From 0db23ddd14b02c90f37c9161b0ca76aee57c6b35 Mon Sep 17 00:00:00 2001 From: "Thomas E. Enebo" Date: Tue, 20 Feb 2024 09:11:17 -0500 Subject: [PATCH 01/33] Version 9.3.14.0 updated for release --- VERSION | 2 +- core/pom.xml | 2 +- lib/pom.xml | 4 ++-- pom.xml | 5 ++++- shaded/pom.xml | 2 +- 5 files changed, 9 insertions(+), 6 deletions(-) diff --git a/VERSION b/VERSION index 0418f8425d2..7fa97546c71 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -9.3.14.0-SNAPSHOT +9.3.14.0 diff --git a/core/pom.xml b/core/pom.xml index b718f7031b0..2efb13bfebc 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -12,7 +12,7 @@ DO NOT MODIFY - GENERATED CODE org.jruby jruby-parent - 9.3.14.0-SNAPSHOT + 9.3.14.0 jruby-base JRuby Base diff --git a/lib/pom.xml b/lib/pom.xml index dc0fde4a255..187c9d09286 100644 --- a/lib/pom.xml +++ b/lib/pom.xml @@ -12,7 +12,7 @@ DO NOT MODIFY - GENERATED CODE org.jruby jruby-parent - 9.3.14.0-SNAPSHOT + 9.3.14.0 jruby-stdlib JRuby Lib Setup @@ -28,7 +28,7 @@ DO NOT MODIFY - GENERATED CODE org.jruby jruby-core - 9.3.14.0-SNAPSHOT + 9.3.14.0 test diff --git a/pom.xml b/pom.xml index 9c79b5fed73..25267e9addd 100644 --- a/pom.xml +++ b/pom.xml @@ -16,7 +16,7 @@ DO NOT MODIFY - GENERATED CODE org.jruby jruby-parent - 9.3.14.0-SNAPSHOT + 9.3.14.0 pom JRuby JRuby is the effort to recreate the Ruby (https://www.ruby-lang.org) interpreter in Java. @@ -274,6 +274,9 @@ DO NOT MODIFY - GENERATED CODE [3.3.0,) + + No Snapshots Allowed! + diff --git a/shaded/pom.xml b/shaded/pom.xml index 260548fc44b..6020ee90bb7 100644 --- a/shaded/pom.xml +++ b/shaded/pom.xml @@ -12,7 +12,7 @@ DO NOT MODIFY - GENERATED CODE org.jruby jruby-parent - 9.3.14.0-SNAPSHOT + 9.3.14.0 jruby-core JRuby Core From 3639d9f5b0645c4c8c2a6651a6962101d3d8648d Mon Sep 17 00:00:00 2001 From: "Thomas E. Enebo" Date: Tue, 20 Feb 2024 10:47:25 -0500 Subject: [PATCH 02/33] Update for next development cycle --- VERSION | 2 +- core/pom.xml | 2 +- lib/pom.xml | 4 ++-- pom.xml | 5 +---- shaded/pom.xml | 2 +- 5 files changed, 6 insertions(+), 9 deletions(-) diff --git a/VERSION b/VERSION index 7fa97546c71..44f728f7e70 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -9.3.14.0 +9.3.15.0-SNAPSHOT diff --git a/core/pom.xml b/core/pom.xml index 2efb13bfebc..4c157863c29 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -12,7 +12,7 @@ DO NOT MODIFY - GENERATED CODE org.jruby jruby-parent - 9.3.14.0 + 9.3.15.0-SNAPSHOT jruby-base JRuby Base diff --git a/lib/pom.xml b/lib/pom.xml index 187c9d09286..147515211cd 100644 --- a/lib/pom.xml +++ b/lib/pom.xml @@ -12,7 +12,7 @@ DO NOT MODIFY - GENERATED CODE org.jruby jruby-parent - 9.3.14.0 + 9.3.15.0-SNAPSHOT jruby-stdlib JRuby Lib Setup @@ -28,7 +28,7 @@ DO NOT MODIFY - GENERATED CODE org.jruby jruby-core - 9.3.14.0 + 9.3.15.0-SNAPSHOT test diff --git a/pom.xml b/pom.xml index 25267e9addd..64ee82e54f6 100644 --- a/pom.xml +++ b/pom.xml @@ -16,7 +16,7 @@ DO NOT MODIFY - GENERATED CODE org.jruby jruby-parent - 9.3.14.0 + 9.3.15.0-SNAPSHOT pom JRuby JRuby is the effort to recreate the Ruby (https://www.ruby-lang.org) interpreter in Java. @@ -274,9 +274,6 @@ DO NOT MODIFY - GENERATED CODE [3.3.0,) - - No Snapshots Allowed! - diff --git a/shaded/pom.xml b/shaded/pom.xml index 6020ee90bb7..113492885f0 100644 --- a/shaded/pom.xml +++ b/shaded/pom.xml @@ -12,7 +12,7 @@ DO NOT MODIFY - GENERATED CODE org.jruby jruby-parent - 9.3.14.0 + 9.3.15.0-SNAPSHOT jruby-core JRuby Core From c5c7164f2de984e51700e8b8dfde1078e359d2f4 Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Mon, 26 Feb 2024 14:51:50 +0100 Subject: [PATCH 03/33] Update to ruby/mspec@36e8ed8 --- spec/mspec/lib/mspec/runner/formatters/base.rb | 8 +++++++- spec/mspec/spec/integration/run_spec.rb | 9 +++++---- spec/mspec/spec/integration/tag_spec.rb | 9 +++++---- spec/mspec/spec/spec_helper.rb | 2 ++ 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/spec/mspec/lib/mspec/runner/formatters/base.rb b/spec/mspec/lib/mspec/runner/formatters/base.rb index 54a83c9c321..e3b5bb23e0b 100644 --- a/spec/mspec/lib/mspec/runner/formatters/base.rb +++ b/spec/mspec/lib/mspec/runner/formatters/base.rb @@ -5,6 +5,9 @@ if ENV['CHECK_LEAKS'] require 'mspec/runner/actions/leakchecker' +end + +if ENV['CHECK_LEAKS'] || ENV['CHECK_CONSTANT_LEAKS'] require 'mspec/runner/actions/constants_leak_checker' end @@ -40,8 +43,11 @@ def register @counter = @tally.counter if ENV['CHECK_LEAKS'] - save = ENV['CHECK_LEAKS'] == 'save' LeakCheckerAction.new.register + end + + if ENV['CHECK_LEAKS'] || ENV['CHECK_CONSTANT_LEAKS'] + save = ENV['CHECK_LEAKS'] == 'save' || ENV['CHECK_CONSTANT_LEAKS'] == 'save' ConstantsLeakCheckerAction.new(save).register end diff --git a/spec/mspec/spec/integration/run_spec.rb b/spec/mspec/spec/integration/run_spec.rb index 90dc0515438..ea0735e9b28 100644 --- a/spec/mspec/spec/integration/run_spec.rb +++ b/spec/mspec/spec/integration/run_spec.rb @@ -1,20 +1,21 @@ require 'spec_helper' RSpec.describe "Running mspec" do + q = BACKTRACE_QUOTE a_spec_output = <' -CWD/spec/fixtures/a_spec.rb:2:in `' +CWD/spec/fixtures/a_spec.rb:8:in #{q}block (2 levels) in ' +CWD/spec/fixtures/a_spec.rb:2:in #{q}' 2) Foo#bar fails ERROR RuntimeError: failure -CWD/spec/fixtures/a_spec.rb:12:in `block (2 levels) in ' -CWD/spec/fixtures/a_spec.rb:2:in `' +CWD/spec/fixtures/a_spec.rb:12:in #{q}block (2 levels) in ' +CWD/spec/fixtures/a_spec.rb:2:in #{q}' Finished in D.DDDDDD seconds EOS diff --git a/spec/mspec/spec/integration/tag_spec.rb b/spec/mspec/spec/integration/tag_spec.rb index 33df1cfd406..ae08e9d45f8 100644 --- a/spec/mspec/spec/integration/tag_spec.rb +++ b/spec/mspec/spec/integration/tag_spec.rb @@ -13,6 +13,7 @@ it "tags the failing specs" do fixtures = "spec/fixtures" out, ret = run_mspec("tag", "--add fails --fail #{fixtures}/tagging_spec.rb") + q = BACKTRACE_QUOTE expect(out).to eq <' -CWD/spec/fixtures/tagging_spec.rb:3:in `' +CWD/spec/fixtures/tagging_spec.rb:9:in #{q}block (2 levels) in ' +CWD/spec/fixtures/tagging_spec.rb:3:in #{q}' 2) Tag#me érròrs in unicode FAILED Expected 1 == 2 to be truthy but was false -CWD/spec/fixtures/tagging_spec.rb:13:in `block (2 levels) in ' -CWD/spec/fixtures/tagging_spec.rb:3:in `' +CWD/spec/fixtures/tagging_spec.rb:13:in #{q}block (2 levels) in ' +CWD/spec/fixtures/tagging_spec.rb:3:in #{q}' Finished in D.DDDDDD seconds diff --git a/spec/mspec/spec/spec_helper.rb b/spec/mspec/spec/spec_helper.rb index 3a749581eee..5cabfe56264 100644 --- a/spec/mspec/spec/spec_helper.rb +++ b/spec/mspec/spec/spec_helper.rb @@ -66,3 +66,5 @@ def ensure_mspec_method(method) include MSpecMatchers public :raise_error }.new + +BACKTRACE_QUOTE = RUBY_VERSION >= "3.4" ? "'" : "`" From b0b0b67ff8656d1eef5bc4eea3cc113d8581417e Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Mon, 26 Feb 2024 14:51:52 +0100 Subject: [PATCH 04/33] Update to ruby/spec@3a510bb --- spec/ruby/.rubocop_todo.yml | 1 - .../ruby/command_line/backtrace_limit_spec.rb | 87 +++- .../singleton_method_added_spec.rb | 8 +- spec/ruby/core/binding/clone_spec.rb | 6 + spec/ruby/core/binding/dup_spec.rb | 6 + spec/ruby/core/binding/shared/clone.rb | 22 + spec/ruby/core/class/attached_object_spec.rb | 6 +- spec/ruby/core/encoding/replicate_spec.rb | 5 + spec/ruby/core/enumerable/fixtures/classes.rb | 6 + spec/ruby/core/enumerable/to_set_spec.rb | 29 ++ .../ruby/core/enumerator/product/each_spec.rb | 2 +- spec/ruby/core/enumerator/product_spec.rb | 2 +- spec/ruby/core/exception/backtrace_spec.rb | 27 +- spec/ruby/core/exception/full_message_spec.rb | 6 +- spec/ruby/core/exception/interrupt_spec.rb | 2 +- .../core/exception/no_method_error_spec.rb | 6 +- spec/ruby/core/exception/to_s_spec.rb | 2 +- spec/ruby/core/exception/top_level_spec.rb | 13 +- spec/ruby/core/file/lutime_spec.rb | 9 +- spec/ruby/core/file/shared/update_time.rb | 105 +++++ spec/ruby/core/file/utime_spec.rb | 100 +---- spec/ruby/core/filetest/exist_spec.rb | 8 + spec/ruby/core/integer/coerce_spec.rb | 14 - spec/ruby/core/io/pwrite_spec.rb | 2 +- .../ruby/core/kernel/caller_locations_spec.rb | 30 +- spec/ruby/core/kernel/caller_spec.rb | 10 +- spec/ruby/core/kernel/eval_spec.rb | 2 +- spec/ruby/core/kernel/not_match_spec.rb | 14 + spec/ruby/core/kernel/public_send_spec.rb | 4 +- spec/ruby/core/marshal/dump_spec.rb | 2 +- spec/ruby/core/method/clone_spec.rb | 15 +- spec/ruby/core/method/dup_spec.rb | 15 + spec/ruby/core/method/parameters_spec.rb | 16 + spec/ruby/core/method/shared/dup.rb | 32 ++ spec/ruby/core/module/prepend_spec.rb | 33 ++ spec/ruby/core/module/ruby2_keywords_spec.rb | 2 +- spec/ruby/core/module/undef_method_spec.rb | 10 +- .../weakkeymap/element_set_spec.rb | 2 +- spec/ruby/core/proc/clone_spec.rb | 9 + spec/ruby/core/proc/dup_spec.rb | 7 + spec/ruby/core/proc/parameters_spec.rb | 14 + spec/ruby/core/proc/shared/dup.rb | 23 + spec/ruby/core/rational/coerce_spec.rb | 7 - .../core/refinement/import_methods_spec.rb | 4 +- spec/ruby/core/signal/trap_spec.rb | 4 +- spec/ruby/core/symbol/to_proc_spec.rb | 8 +- .../backtrace/location/absolute_path_spec.rb | 2 +- .../thread/backtrace/location/label_spec.rb | 10 +- .../core/thread/backtrace_locations_spec.rb | 2 +- spec/ruby/core/thread/backtrace_spec.rb | 2 +- .../core/thread/report_on_exception_spec.rb | 10 +- spec/ruby/core/time/at_spec.rb | 9 - spec/ruby/core/time/new_spec.rb | 16 +- spec/ruby/core/tracepoint/inspect_spec.rb | 6 +- spec/ruby/core/unboundmethod/clone_spec.rb | 13 +- spec/ruby/core/unboundmethod/dup_spec.rb | 15 + spec/ruby/core/unboundmethod/shared/dup.rb | 32 ++ spec/ruby/language/hash_spec.rb | 28 +- .../ruby/language/numbered_parameters_spec.rb | 2 +- spec/ruby/language/predefined_spec.rb | 4 +- spec/ruby/language/rescue_spec.rb | 2 +- spec/ruby/language/symbol_spec.rb | 14 +- spec/ruby/language/variables_spec.rb | 2 +- spec/ruby/library/abbrev/abbrev_spec.rb | 47 +- spec/ruby/library/base64/decode64_spec.rb | 41 +- spec/ruby/library/base64/encode64_spec.rb | 33 +- .../library/base64/strict_decode64_spec.rb | 77 ++-- .../library/base64/strict_encode64_spec.rb | 27 +- .../library/base64/urlsafe_decode64_spec.rb | 27 +- .../library/base64/urlsafe_encode64_spec.rb | 29 +- .../library/bigdecimal/BigDecimal_spec.rb | 415 +++++++++-------- spec/ruby/library/bigdecimal/abs_spec.rb | 89 ++-- spec/ruby/library/bigdecimal/add_spec.rb | 339 +++++++------- .../library/bigdecimal/case_compare_spec.rb | 9 +- spec/ruby/library/bigdecimal/ceil_spec.rb | 187 ++++---- spec/ruby/library/bigdecimal/clone_spec.rb | 9 +- spec/ruby/library/bigdecimal/coerce_spec.rb | 43 +- .../library/bigdecimal/comparison_spec.rb | 137 +++--- .../ruby/library/bigdecimal/constants_spec.rb | 111 +++-- spec/ruby/library/bigdecimal/core_spec.rb | 59 +++ spec/ruby/library/bigdecimal/div_spec.rb | 185 ++++---- spec/ruby/library/bigdecimal/divide_spec.rb | 23 +- spec/ruby/library/bigdecimal/divmod_spec.rb | 293 ++++++------ .../library/bigdecimal/double_fig_spec.rb | 13 +- spec/ruby/library/bigdecimal/dup_spec.rb | 9 +- spec/ruby/library/bigdecimal/eql_spec.rb | 9 +- .../library/bigdecimal/equal_value_spec.rb | 9 +- spec/ruby/library/bigdecimal/exponent_spec.rb | 41 +- spec/ruby/library/bigdecimal/finite_spec.rb | 57 ++- spec/ruby/library/bigdecimal/fix_spec.rb | 99 ++-- spec/ruby/library/bigdecimal/floor_spec.rb | 169 ++++--- spec/ruby/library/bigdecimal/frac_spec.rb | 89 ++-- spec/ruby/library/bigdecimal/gt_spec.rb | 161 ++++--- spec/ruby/library/bigdecimal/gte_spec.rb | 169 ++++--- spec/ruby/library/bigdecimal/hash_spec.rb | 43 +- spec/ruby/library/bigdecimal/infinite_spec.rb | 51 +-- spec/ruby/library/bigdecimal/inspect_spec.rb | 45 +- spec/ruby/library/bigdecimal/limit_spec.rb | 89 ++-- spec/ruby/library/bigdecimal/lt_spec.rb | 161 ++++--- spec/ruby/library/bigdecimal/lte_spec.rb | 169 ++++--- spec/ruby/library/bigdecimal/minus_spec.rb | 109 +++-- spec/ruby/library/bigdecimal/mode_spec.rb | 61 ++- spec/ruby/library/bigdecimal/modulo_spec.rb | 19 +- spec/ruby/library/bigdecimal/mult_spec.rb | 49 +- spec/ruby/library/bigdecimal/multiply_spec.rb | 63 ++- spec/ruby/library/bigdecimal/nan_spec.rb | 37 +- spec/ruby/library/bigdecimal/nonzero_spec.rb | 49 +- spec/ruby/library/bigdecimal/plus_spec.rb | 93 ++-- spec/ruby/library/bigdecimal/power_spec.rb | 9 +- spec/ruby/library/bigdecimal/precs_spec.rb | 79 ++-- spec/ruby/library/bigdecimal/quo_spec.rb | 17 +- .../ruby/library/bigdecimal/remainder_spec.rb | 161 ++++--- spec/ruby/library/bigdecimal/round_spec.rb | 423 +++++++++--------- spec/ruby/library/bigdecimal/sign_spec.rb | 85 ++-- spec/ruby/library/bigdecimal/split_spec.rb | 149 +++--- spec/ruby/library/bigdecimal/sqrt_spec.rb | 185 ++++---- spec/ruby/library/bigdecimal/sub_spec.rb | 115 +++-- spec/ruby/library/bigdecimal/to_d_spec.rb | 15 +- spec/ruby/library/bigdecimal/to_f_spec.rb | 103 +++-- spec/ruby/library/bigdecimal/to_i_spec.rb | 11 +- spec/ruby/library/bigdecimal/to_int_spec.rb | 11 +- spec/ruby/library/bigdecimal/to_r_spec.rb | 43 +- spec/ruby/library/bigdecimal/to_s_spec.rb | 159 ++++--- spec/ruby/library/bigdecimal/truncate_spec.rb | 135 +++--- spec/ruby/library/bigdecimal/uminus_spec.rb | 101 ++--- spec/ruby/library/bigdecimal/uplus_spec.rb | 29 +- spec/ruby/library/bigdecimal/util_spec.rb | 59 ++- spec/ruby/library/bigdecimal/zero_spec.rb | 45 +- spec/ruby/library/bigmath/log_spec.rb | 13 - .../basicwriter/close_on_terminate_spec.rb | 9 +- .../csv/basicwriter/initialize_spec.rb | 9 +- .../library/csv/basicwriter/terminate_spec.rb | 9 +- spec/ruby/library/csv/cell/data_spec.rb | 9 +- spec/ruby/library/csv/cell/initialize_spec.rb | 9 +- spec/ruby/library/csv/foreach_spec.rb | 9 +- spec/ruby/library/csv/generate_line_spec.rb | 45 +- spec/ruby/library/csv/generate_row_spec.rb | 9 +- spec/ruby/library/csv/generate_spec.rb | 47 +- spec/ruby/library/csv/iobuf/close_spec.rb | 9 +- .../ruby/library/csv/iobuf/initialize_spec.rb | 9 +- spec/ruby/library/csv/iobuf/read_spec.rb | 9 +- spec/ruby/library/csv/iobuf/terminate_spec.rb | 9 +- .../csv/ioreader/close_on_terminate_spec.rb | 9 +- .../ruby/library/csv/ioreader/get_row_spec.rb | 9 +- .../library/csv/ioreader/initialize_spec.rb | 9 +- .../library/csv/ioreader/terminate_spec.rb | 9 +- spec/ruby/library/csv/liberal_parsing_spec.rb | 29 +- spec/ruby/library/csv/open_spec.rb | 9 +- spec/ruby/library/csv/parse_spec.rb | 181 ++++---- spec/ruby/library/csv/read_spec.rb | 9 +- spec/ruby/library/csv/readlines_spec.rb | 53 ++- .../library/csv/streambuf/add_buf_spec.rb | 9 +- .../library/csv/streambuf/buf_size_spec.rb | 9 +- spec/ruby/library/csv/streambuf/drop_spec.rb | 9 +- .../csv/streambuf/element_reference_spec.rb | 9 +- spec/ruby/library/csv/streambuf/get_spec.rb | 9 +- .../library/csv/streambuf/idx_is_eos_spec.rb | 9 +- .../library/csv/streambuf/initialize_spec.rb | 9 +- .../ruby/library/csv/streambuf/is_eos_spec.rb | 9 +- spec/ruby/library/csv/streambuf/read_spec.rb | 9 +- .../library/csv/streambuf/rel_buf_spec.rb | 9 +- .../library/csv/streambuf/terminate_spec.rb | 9 +- .../library/csv/stringreader/get_row_spec.rb | 9 +- .../csv/stringreader/initialize_spec.rb | 9 +- spec/ruby/library/csv/writer/add_row_spec.rb | 9 +- spec/ruby/library/csv/writer/append_spec.rb | 9 +- spec/ruby/library/csv/writer/close_spec.rb | 9 +- spec/ruby/library/csv/writer/create_spec.rb | 9 +- spec/ruby/library/csv/writer/generate_spec.rb | 9 +- .../library/csv/writer/initialize_spec.rb | 9 +- .../ruby/library/csv/writer/terminate_spec.rb | 9 +- spec/ruby/library/drb/start_service_spec.rb | 4 +- .../library/getoptlong/each_option_spec.rb | 11 +- spec/ruby/library/getoptlong/each_spec.rb | 11 +- .../library/getoptlong/error_message_spec.rb | 35 +- .../library/getoptlong/get_option_spec.rb | 11 +- spec/ruby/library/getoptlong/get_spec.rb | 11 +- .../library/getoptlong/initialize_spec.rb | 41 +- spec/ruby/library/getoptlong/ordering_spec.rb | 57 ++- .../library/getoptlong/set_options_spec.rb | 151 +++---- .../ruby/library/getoptlong/terminate_spec.rb | 47 +- .../library/getoptlong/terminated_spec.rb | 23 +- spec/ruby/library/matrix/I_spec.rb | 9 +- .../ruby/library/matrix/antisymmetric_spec.rb | 54 ++- spec/ruby/library/matrix/build_spec.rb | 117 +++-- spec/ruby/library/matrix/clone_spec.rb | 37 +- spec/ruby/library/matrix/coerce_spec.rb | 11 +- spec/ruby/library/matrix/collect_spec.rb | 9 +- spec/ruby/library/matrix/column_size_spec.rb | 19 +- spec/ruby/library/matrix/column_spec.rb | 53 ++- .../ruby/library/matrix/column_vector_spec.rb | 37 +- .../library/matrix/column_vectors_spec.rb | 37 +- spec/ruby/library/matrix/columns_spec.rb | 67 ++- spec/ruby/library/matrix/conj_spec.rb | 9 +- spec/ruby/library/matrix/conjugate_spec.rb | 9 +- spec/ruby/library/matrix/constructor_spec.rb | 103 +++-- spec/ruby/library/matrix/det_spec.rb | 11 +- spec/ruby/library/matrix/determinant_spec.rb | 11 +- spec/ruby/library/matrix/diagonal_spec.rb | 105 +++-- spec/ruby/library/matrix/divide_spec.rb | 83 ++-- spec/ruby/library/matrix/each_spec.rb | 119 +++-- .../library/matrix/each_with_index_spec.rb | 133 +++--- .../eigenvalue_matrix_spec.rb | 13 +- .../eigenvalues_spec.rb | 35 +- .../eigenvector_matrix_spec.rb | 33 +- .../eigenvectors_spec.rb | 37 +- .../initialize_spec.rb | 39 +- .../eigenvalue_decomposition/to_a_spec.rb | 27 +- .../library/matrix/element_reference_spec.rb | 31 +- spec/ruby/library/matrix/empty_spec.rb | 107 +++-- spec/ruby/library/matrix/eql_spec.rb | 15 +- spec/ruby/library/matrix/equal_value_spec.rb | 15 +- spec/ruby/library/matrix/exponent_spec.rb | 93 ++-- spec/ruby/library/matrix/find_index_spec.rb | 221 +++++---- spec/ruby/library/matrix/hash_spec.rb | 21 +- spec/ruby/library/matrix/hermitian_spec.rb | 53 ++- spec/ruby/library/matrix/identity_spec.rb | 9 +- spec/ruby/library/matrix/imag_spec.rb | 9 +- spec/ruby/library/matrix/imaginary_spec.rb | 9 +- spec/ruby/library/matrix/inspect_spec.rb | 39 +- spec/ruby/library/matrix/inv_spec.rb | 11 +- spec/ruby/library/matrix/inverse_from_spec.rb | 9 +- spec/ruby/library/matrix/inverse_spec.rb | 11 +- .../library/matrix/lower_triangular_spec.rb | 39 +- .../lup_decomposition/determinant_spec.rb | 33 +- .../lup_decomposition/initialize_spec.rb | 21 +- .../matrix/lup_decomposition/l_spec.rb | 27 +- .../matrix/lup_decomposition/p_spec.rb | 27 +- .../matrix/lup_decomposition/solve_spec.rb | 85 ++-- .../matrix/lup_decomposition/to_a_spec.rb | 53 ++- .../matrix/lup_decomposition/u_spec.rb | 27 +- spec/ruby/library/matrix/map_spec.rb | 9 +- spec/ruby/library/matrix/minor_spec.rb | 135 +++--- spec/ruby/library/matrix/minus_spec.rb | 65 ++- spec/ruby/library/matrix/multiply_spec.rb | 104 +++-- spec/ruby/library/matrix/new_spec.rb | 11 +- spec/ruby/library/matrix/normal_spec.rb | 41 +- spec/ruby/library/matrix/orthogonal_spec.rb | 41 +- spec/ruby/library/matrix/permutation_spec.rb | 51 +-- spec/ruby/library/matrix/plus_spec.rb | 65 ++- spec/ruby/library/matrix/rank_spec.rb | 29 +- spec/ruby/library/matrix/real_spec.rb | 63 ++- spec/ruby/library/matrix/rect_spec.rb | 9 +- spec/ruby/library/matrix/rectangular_spec.rb | 9 +- spec/ruby/library/matrix/regular_spec.rb | 45 +- spec/ruby/library/matrix/round_spec.rb | 31 +- spec/ruby/library/matrix/row_size_spec.rb | 19 +- spec/ruby/library/matrix/row_spec.rb | 55 ++- spec/ruby/library/matrix/row_vector_spec.rb | 33 +- spec/ruby/library/matrix/row_vectors_spec.rb | 37 +- spec/ruby/library/matrix/rows_spec.rb | 65 ++- spec/ruby/library/matrix/scalar/Fail_spec.rb | 9 +- spec/ruby/library/matrix/scalar/Raise_spec.rb | 9 +- .../ruby/library/matrix/scalar/divide_spec.rb | 9 +- .../library/matrix/scalar/exponent_spec.rb | 9 +- .../library/matrix/scalar/included_spec.rb | 9 +- .../library/matrix/scalar/initialize_spec.rb | 9 +- spec/ruby/library/matrix/scalar/minus_spec.rb | 9 +- .../library/matrix/scalar/multiply_spec.rb | 9 +- spec/ruby/library/matrix/scalar/plus_spec.rb | 9 +- spec/ruby/library/matrix/scalar_spec.rb | 93 ++-- spec/ruby/library/matrix/singular_spec.rb | 47 +- spec/ruby/library/matrix/square_spec.rb | 41 +- spec/ruby/library/matrix/symmetric_spec.rb | 45 +- spec/ruby/library/matrix/t_spec.rb | 9 +- spec/ruby/library/matrix/to_a_spec.rb | 17 +- spec/ruby/library/matrix/to_s_spec.rb | 9 +- spec/ruby/library/matrix/tr_spec.rb | 11 +- spec/ruby/library/matrix/trace_spec.rb | 11 +- spec/ruby/library/matrix/transpose_spec.rb | 9 +- spec/ruby/library/matrix/unit_spec.rb | 9 +- spec/ruby/library/matrix/unitary_spec.rb | 48 +- .../library/matrix/upper_triangular_spec.rb | 39 +- .../matrix/vector/cross_product_spec.rb | 21 +- spec/ruby/library/matrix/vector/each2_spec.rb | 81 ++-- spec/ruby/library/matrix/vector/eql_spec.rb | 23 +- .../matrix/vector/inner_product_spec.rb | 33 +- .../library/matrix/vector/normalize_spec.rb | 29 +- spec/ruby/library/matrix/zero_spec.rb | 75 ++-- spec/ruby/library/net-ftp/FTPError_spec.rb | 8 + .../ruby/library/net-ftp/FTPPermError_spec.rb | 12 + .../library/net-ftp/FTPProtoError_spec.rb | 12 + .../library/net-ftp/FTPReplyError_spec.rb | 12 + .../ruby/library/net-ftp/FTPTempError_spec.rb | 12 + spec/ruby/library/net-ftp/abort_spec.rb | 62 +++ spec/ruby/library/net-ftp/acct_spec.rb | 58 +++ spec/ruby/library/net-ftp/binary_spec.rb | 24 + spec/ruby/library/net-ftp/chdir_spec.rb | 99 ++++ spec/ruby/library/net-ftp/close_spec.rb | 30 ++ spec/ruby/library/net-ftp/closed_spec.rb | 21 + spec/ruby/library/net-ftp/connect_spec.rb | 51 +++ spec/ruby/library/net-ftp/debug_mode_spec.rb | 23 + .../library/net-ftp/default_passive_spec.rb | 8 + spec/ruby/library/net-ftp/delete_spec.rb | 59 +++ spec/ruby/library/net-ftp/dir_spec.rb | 8 + .../fixtures/default_passive.rb | 0 .../{net/ftp => net-ftp}/fixtures/passive.rb | 0 .../ftp => net-ftp}/fixtures/putbinaryfile | 0 .../{net/ftp => net-ftp}/fixtures/puttextfile | 0 .../{net/ftp => net-ftp}/fixtures/server.rb | 0 spec/ruby/library/net-ftp/get_spec.rb | 21 + .../library/net-ftp/getbinaryfile_spec.rb | 8 + spec/ruby/library/net-ftp/getdir_spec.rb | 7 + spec/ruby/library/net-ftp/gettextfile_spec.rb | 8 + spec/ruby/library/net-ftp/help_spec.rb | 66 +++ spec/ruby/library/net-ftp/initialize_spec.rb | 405 +++++++++++++++++ .../net-ftp/last_response_code_spec.rb | 8 + .../library/net-ftp/last_response_spec.rb | 25 ++ spec/ruby/library/net-ftp/lastresp_spec.rb | 8 + spec/ruby/library/net-ftp/list_spec.rb | 8 + spec/ruby/library/net-ftp/login_spec.rb | 195 ++++++++ spec/ruby/library/net-ftp/ls_spec.rb | 8 + spec/ruby/library/net-ftp/mdtm_spec.rb | 38 ++ spec/ruby/library/net-ftp/mkdir_spec.rb | 61 +++ spec/ruby/library/net-ftp/mtime_spec.rb | 50 +++ spec/ruby/library/net-ftp/nlst_spec.rb | 92 ++++ spec/ruby/library/net-ftp/noop_spec.rb | 38 ++ spec/ruby/library/net-ftp/open_spec.rb | 55 +++ spec/ruby/library/net-ftp/passive_spec.rb | 28 ++ spec/ruby/library/net-ftp/put_spec.rb | 21 + .../library/net-ftp/putbinaryfile_spec.rb | 8 + spec/ruby/library/net-ftp/puttextfile_spec.rb | 8 + spec/ruby/library/net-ftp/pwd_spec.rb | 53 +++ spec/ruby/library/net-ftp/quit_spec.rb | 33 ++ spec/ruby/library/net-ftp/rename_spec.rb | 94 ++++ spec/ruby/library/net-ftp/resume_spec.rb | 23 + spec/ruby/library/net-ftp/retrbinary_spec.rb | 30 ++ spec/ruby/library/net-ftp/retrlines_spec.rb | 34 ++ spec/ruby/library/net-ftp/return_code_spec.rb | 24 + spec/ruby/library/net-ftp/rmdir_spec.rb | 58 +++ spec/ruby/library/net-ftp/sendcmd_spec.rb | 54 +++ spec/ruby/library/net-ftp/set_socket_spec.rb | 8 + .../ftp => net-ftp}/shared/getbinaryfile.rb | 0 .../ftp => net-ftp}/shared/gettextfile.rb | 0 .../shared/last_response_code.rb | 0 .../{net/ftp => net-ftp}/shared/list.rb | 0 .../ftp => net-ftp}/shared/putbinaryfile.rb | 0 .../ftp => net-ftp}/shared/puttextfile.rb | 0 .../{net/ftp => net-ftp}/shared/pwd.rb | 0 spec/ruby/library/net-ftp/site_spec.rb | 53 +++ spec/ruby/library/net-ftp/size_spec.rb | 48 ++ .../{net/ftp => net-ftp}/spec_helper.rb | 0 spec/ruby/library/net-ftp/status_spec.rb | 67 +++ spec/ruby/library/net-ftp/storbinary_spec.rb | 49 ++ spec/ruby/library/net-ftp/storlines_spec.rb | 44 ++ spec/ruby/library/net-ftp/system_spec.rb | 48 ++ spec/ruby/library/net-ftp/voidcmd_spec.rb | 54 +++ spec/ruby/library/net-ftp/welcome_spec.rb | 25 ++ .../http => net-http}/HTTPBadResponse_spec.rb | 2 +- .../HTTPClientExcepton_spec.rb | 2 +- .../{net/http => net-http}/HTTPError_spec.rb | 2 +- .../http => net-http}/HTTPFatalError_spec.rb | 2 +- .../HTTPHeaderSyntaxError_spec.rb | 2 +- .../HTTPRetriableError_spec.rb | 2 +- .../HTTPServerException_spec.rb | 2 +- .../{net/http => net-http}/http/Proxy_spec.rb | 2 +- .../http => net-http}/http/active_spec.rb | 2 +- .../http => net-http}/http/address_spec.rb | 2 +- .../http/close_on_empty_response_spec.rb | 2 +- .../{net/http => net-http}/http/copy_spec.rb | 2 +- .../http/default_port_spec.rb | 2 +- .../http => net-http}/http/delete_spec.rb | 2 +- .../http => net-http}/http/finish_spec.rb | 2 +- .../http/fixtures/http_server.rb | 0 .../{net/http => net-http}/http/get2_spec.rb | 2 +- .../http => net-http}/http/get_print_spec.rb | 2 +- .../http/get_response_spec.rb | 2 +- .../{net/http => net-http}/http/get_spec.rb | 2 +- .../{net/http => net-http}/http/head2_spec.rb | 2 +- .../{net/http => net-http}/http/head_spec.rb | 2 +- .../http/http_default_port_spec.rb | 2 +- .../http/https_default_port_spec.rb | 2 +- .../http => net-http}/http/initialize_spec.rb | 2 +- .../http => net-http}/http/inspect_spec.rb | 2 +- .../http/is_version_1_1_spec.rb | 2 +- .../http/is_version_1_2_spec.rb | 2 +- .../{net/http => net-http}/http/lock_spec.rb | 2 +- .../{net/http => net-http}/http/mkcol_spec.rb | 2 +- .../{net/http => net-http}/http/move_spec.rb | 2 +- .../{net/http => net-http}/http/new_spec.rb | 2 +- .../http => net-http}/http/newobj_spec.rb | 2 +- .../http/open_timeout_spec.rb | 2 +- .../http => net-http}/http/options_spec.rb | 2 +- .../{net/http => net-http}/http/port_spec.rb | 2 +- .../{net/http => net-http}/http/post2_spec.rb | 2 +- .../http => net-http}/http/post_form_spec.rb | 2 +- .../{net/http => net-http}/http/post_spec.rb | 2 +- .../http => net-http}/http/propfind_spec.rb | 2 +- .../http => net-http}/http/proppatch_spec.rb | 2 +- .../http/proxy_address_spec.rb | 2 +- .../http/proxy_class_spec.rb | 2 +- .../http => net-http}/http/proxy_pass_spec.rb | 2 +- .../http => net-http}/http/proxy_port_spec.rb | 2 +- .../http => net-http}/http/proxy_user_spec.rb | 2 +- .../{net/http => net-http}/http/put2_spec.rb | 2 +- .../{net/http => net-http}/http/put_spec.rb | 2 +- .../http/read_timeout_spec.rb | 2 +- .../http/request_get_spec.rb | 2 +- .../http/request_head_spec.rb | 2 +- .../http/request_post_spec.rb | 2 +- .../http/request_put_spec.rb | 2 +- .../http => net-http}/http/request_spec.rb | 2 +- .../http/request_types_spec.rb | 2 +- .../http/send_request_spec.rb | 2 +- .../http/set_debug_output_spec.rb | 2 +- .../http/shared/request_get.rb | 0 .../http/shared/request_head.rb | 0 .../http/shared/request_post.rb | 0 .../http/shared/request_put.rb | 0 .../http => net-http}/http/shared/started.rb | 0 .../http/shared/version_1_1.rb | 0 .../http/shared/version_1_2.rb | 0 .../http/socket_type_spec.rb | 2 +- .../{net/http => net-http}/http/start_spec.rb | 2 +- .../http => net-http}/http/started_spec.rb | 2 +- .../{net/http => net-http}/http/trace_spec.rb | 2 +- .../http => net-http}/http/unlock_spec.rb | 2 +- .../http => net-http}/http/use_ssl_spec.rb | 2 +- .../http/version_1_1_spec.rb | 2 +- .../http/version_1_2_spec.rb | 2 +- .../httpexceptions/fixtures/classes.rb | 0 .../httpexceptions/initialize_spec.rb | 2 +- .../httpexceptions/response_spec.rb | 2 +- .../httpgenericrequest/body_exist_spec.rb | 2 +- .../httpgenericrequest/body_spec.rb | 2 +- .../httpgenericrequest/body_stream_spec.rb | 2 +- .../httpgenericrequest/exec_spec.rb | 2 +- .../httpgenericrequest/inspect_spec.rb | 2 +- .../httpgenericrequest/method_spec.rb | 2 +- .../httpgenericrequest/path_spec.rb | 2 +- .../request_body_permitted_spec.rb | 2 +- .../response_body_permitted_spec.rb | 2 +- .../set_body_internal_spec.rb | 2 +- .../httpheader/add_field_spec.rb | 2 +- .../httpheader/basic_auth_spec.rb | 2 +- .../httpheader/canonical_each_spec.rb | 2 +- .../httpheader/chunked_spec.rb | 2 +- .../httpheader/content_length_spec.rb | 2 +- .../httpheader/content_range_spec.rb | 2 +- .../httpheader/content_type_spec.rb | 2 +- .../httpheader/delete_spec.rb | 2 +- .../httpheader/each_capitalized_name_spec.rb | 2 +- .../httpheader/each_capitalized_spec.rb | 2 +- .../httpheader/each_header_spec.rb | 2 +- .../httpheader/each_key_spec.rb | 2 +- .../httpheader/each_name_spec.rb | 2 +- .../http => net-http}/httpheader/each_spec.rb | 2 +- .../httpheader/each_value_spec.rb | 2 +- .../httpheader/element_reference_spec.rb | 2 +- .../httpheader/element_set_spec.rb | 2 +- .../httpheader/fetch_spec.rb | 2 +- .../httpheader/fixtures/classes.rb | 0 .../httpheader/form_data_spec.rb | 2 +- .../httpheader/get_fields_spec.rb | 2 +- .../httpheader/initialize_http_header_spec.rb | 2 +- .../http => net-http}/httpheader/key_spec.rb | 2 +- .../httpheader/length_spec.rb | 2 +- .../httpheader/main_type_spec.rb | 2 +- .../httpheader/proxy_basic_auth_spec.rb | 2 +- .../httpheader/range_length_spec.rb | 2 +- .../httpheader/range_spec.rb | 2 +- .../httpheader/set_content_type_spec.rb | 2 +- .../httpheader/set_form_data_spec.rb | 2 +- .../httpheader/set_range_spec.rb | 2 +- .../httpheader/shared/each_capitalized.rb | 0 .../httpheader/shared/each_header.rb | 0 .../httpheader/shared/each_name.rb | 0 .../httpheader/shared/set_content_type.rb | 0 .../httpheader/shared/set_form_data.rb | 0 .../httpheader/shared/set_range.rb | 0 .../httpheader/shared/size.rb | 0 .../http => net-http}/httpheader/size_spec.rb | 2 +- .../httpheader/sub_type_spec.rb | 2 +- .../httpheader/to_hash_spec.rb | 2 +- .../httpheader/type_params_spec.rb | 2 +- .../httprequest/initialize_spec.rb | 2 +- .../httpresponse/body_permitted_spec.rb | 2 +- .../httpresponse/body_spec.rb | 2 +- .../httpresponse/code_spec.rb | 2 +- .../httpresponse/code_type_spec.rb | 2 +- .../httpresponse/entity_spec.rb | 2 +- .../httpresponse/error_spec.rb | 2 +- .../httpresponse/error_type_spec.rb | 2 +- .../httpresponse/exception_type_spec.rb | 2 +- .../httpresponse/header_spec.rb | 2 +- .../httpresponse/http_version_spec.rb | 2 +- .../httpresponse/initialize_spec.rb | 2 +- .../httpresponse/inspect_spec.rb | 2 +- .../httpresponse/message_spec.rb | 2 +- .../httpresponse/msg_spec.rb | 2 +- .../httpresponse/read_body_spec.rb | 2 +- .../httpresponse/read_header_spec.rb | 2 +- .../httpresponse/read_new_spec.rb | 2 +- .../httpresponse/reading_body_spec.rb | 2 +- .../httpresponse/response_spec.rb | 2 +- .../httpresponse/shared/body.rb | 0 .../httpresponse/value_spec.rb | 2 +- spec/ruby/library/net/FTPError_spec.rb | 11 - spec/ruby/library/net/FTPPermError_spec.rb | 15 - spec/ruby/library/net/FTPProtoError_spec.rb | 15 - spec/ruby/library/net/FTPReplyError_spec.rb | 15 - spec/ruby/library/net/FTPTempError_spec.rb | 15 - spec/ruby/library/net/ftp/abort_spec.rb | 65 --- spec/ruby/library/net/ftp/acct_spec.rb | 61 --- spec/ruby/library/net/ftp/binary_spec.rb | 27 -- spec/ruby/library/net/ftp/chdir_spec.rb | 102 ----- spec/ruby/library/net/ftp/close_spec.rb | 33 -- spec/ruby/library/net/ftp/closed_spec.rb | 24 - spec/ruby/library/net/ftp/connect_spec.rb | 52 --- spec/ruby/library/net/ftp/debug_mode_spec.rb | 26 -- .../library/net/ftp/default_passive_spec.rb | 11 - spec/ruby/library/net/ftp/delete_spec.rb | 62 --- spec/ruby/library/net/ftp/dir_spec.rb | 11 - spec/ruby/library/net/ftp/get_spec.rb | 24 - .../library/net/ftp/getbinaryfile_spec.rb | 11 - spec/ruby/library/net/ftp/getdir_spec.rb | 10 - spec/ruby/library/net/ftp/gettextfile_spec.rb | 11 - spec/ruby/library/net/ftp/help_spec.rb | 69 --- spec/ruby/library/net/ftp/initialize_spec.rb | 408 ----------------- .../net/ftp/last_response_code_spec.rb | 11 - .../library/net/ftp/last_response_spec.rb | 28 -- spec/ruby/library/net/ftp/lastresp_spec.rb | 11 - spec/ruby/library/net/ftp/list_spec.rb | 11 - spec/ruby/library/net/ftp/login_spec.rb | 198 -------- spec/ruby/library/net/ftp/ls_spec.rb | 11 - spec/ruby/library/net/ftp/mdtm_spec.rb | 41 -- spec/ruby/library/net/ftp/mkdir_spec.rb | 64 --- spec/ruby/library/net/ftp/mtime_spec.rb | 53 --- spec/ruby/library/net/ftp/nlst_spec.rb | 95 ---- spec/ruby/library/net/ftp/noop_spec.rb | 41 -- spec/ruby/library/net/ftp/open_spec.rb | 58 --- spec/ruby/library/net/ftp/passive_spec.rb | 31 -- spec/ruby/library/net/ftp/put_spec.rb | 24 - .../library/net/ftp/putbinaryfile_spec.rb | 11 - spec/ruby/library/net/ftp/puttextfile_spec.rb | 11 - spec/ruby/library/net/ftp/pwd_spec.rb | 56 --- spec/ruby/library/net/ftp/quit_spec.rb | 36 -- spec/ruby/library/net/ftp/rename_spec.rb | 97 ---- spec/ruby/library/net/ftp/resume_spec.rb | 26 -- spec/ruby/library/net/ftp/retrbinary_spec.rb | 33 -- spec/ruby/library/net/ftp/retrlines_spec.rb | 37 -- spec/ruby/library/net/ftp/return_code_spec.rb | 27 -- spec/ruby/library/net/ftp/rmdir_spec.rb | 61 --- spec/ruby/library/net/ftp/sendcmd_spec.rb | 57 --- spec/ruby/library/net/ftp/set_socket_spec.rb | 11 - spec/ruby/library/net/ftp/site_spec.rb | 56 --- spec/ruby/library/net/ftp/size_spec.rb | 51 --- spec/ruby/library/net/ftp/status_spec.rb | 70 --- spec/ruby/library/net/ftp/storbinary_spec.rb | 51 --- spec/ruby/library/net/ftp/storlines_spec.rb | 46 -- spec/ruby/library/net/ftp/system_spec.rb | 51 --- spec/ruby/library/net/ftp/voidcmd_spec.rb | 57 --- spec/ruby/library/net/ftp/welcome_spec.rb | 28 -- .../library/observer/add_observer_spec.rb | 35 +- .../library/observer/count_observers_spec.rb | 37 +- .../library/observer/delete_observer_spec.rb | 29 +- .../library/observer/delete_observers_spec.rb | 29 +- .../ruby/library/observer/fixtures/classes.rb | 24 +- .../library/observer/notify_observers_spec.rb | 49 +- spec/ruby/library/prime/each_spec.rb | 247 +++++----- spec/ruby/library/prime/instance_spec.rb | 31 +- .../prime/int_from_prime_division_spec.rb | 19 +- .../library/prime/integer/each_prime_spec.rb | 19 +- .../prime/integer/from_prime_division_spec.rb | 19 +- .../prime/integer/prime_division_spec.rb | 31 +- spec/ruby/library/prime/integer/prime_spec.rb | 27 +- spec/ruby/library/prime/next_spec.rb | 11 +- .../ruby/library/prime/prime_division_spec.rb | 37 +- spec/ruby/library/prime/prime_spec.rb | 27 +- spec/ruby/library/prime/succ_spec.rb | 11 +- spec/ruby/library/set/set_spec.rb | 12 + .../library/socket/tcpserver/accept_spec.rb | 2 +- spec/ruby/library/syslog/alert_spec.rb | 13 +- spec/ruby/library/syslog/close_spec.rb | 107 +++-- spec/ruby/library/syslog/constants_spec.rb | 57 ++- spec/ruby/library/syslog/crit_spec.rb | 13 +- spec/ruby/library/syslog/debug_spec.rb | 13 +- spec/ruby/library/syslog/emerg_spec.rb | 23 +- spec/ruby/library/syslog/err_spec.rb | 13 +- spec/ruby/library/syslog/facility_spec.rb | 87 ++-- spec/ruby/library/syslog/ident_spec.rb | 49 +- spec/ruby/library/syslog/info_spec.rb | 13 +- spec/ruby/library/syslog/inspect_spec.rb | 57 ++- spec/ruby/library/syslog/instance_spec.rb | 15 +- spec/ruby/library/syslog/log_spec.rb | 85 ++-- spec/ruby/library/syslog/mask_spec.rb | 151 +++---- spec/ruby/library/syslog/notice_spec.rb | 13 +- spec/ruby/library/syslog/open_spec.rb | 141 +++--- spec/ruby/library/syslog/opened_spec.rb | 55 ++- spec/ruby/library/syslog/options_spec.rb | 87 ++-- spec/ruby/library/syslog/reopen_spec.rb | 13 +- spec/ruby/library/syslog/shared/log.rb | 66 ++- spec/ruby/library/syslog/shared/reopen.rb | 64 ++- spec/ruby/library/syslog/warning_spec.rb | 13 +- spec/ruby/optional/capi/encoding_spec.rb | 31 +- spec/ruby/optional/capi/ext/encoding_spec.c | 5 + spec/ruby/optional/capi/ext/string_spec.c | 18 +- spec/ruby/optional/capi/ext/util_spec.c | 17 +- spec/ruby/optional/capi/string_spec.rb | 74 ++- spec/ruby/shared/rational/coerce.rb | 35 -- 600 files changed, 9361 insertions(+), 9833 deletions(-) create mode 100644 spec/ruby/core/enumerable/to_set_spec.rb create mode 100644 spec/ruby/core/file/shared/update_time.rb create mode 100644 spec/ruby/core/method/dup_spec.rb create mode 100644 spec/ruby/core/method/shared/dup.rb delete mode 100644 spec/ruby/core/rational/coerce_spec.rb create mode 100644 spec/ruby/core/unboundmethod/dup_spec.rb create mode 100644 spec/ruby/core/unboundmethod/shared/dup.rb create mode 100644 spec/ruby/library/bigdecimal/core_spec.rb delete mode 100644 spec/ruby/library/bigmath/log_spec.rb create mode 100644 spec/ruby/library/net-ftp/FTPError_spec.rb create mode 100644 spec/ruby/library/net-ftp/FTPPermError_spec.rb create mode 100644 spec/ruby/library/net-ftp/FTPProtoError_spec.rb create mode 100644 spec/ruby/library/net-ftp/FTPReplyError_spec.rb create mode 100644 spec/ruby/library/net-ftp/FTPTempError_spec.rb create mode 100644 spec/ruby/library/net-ftp/abort_spec.rb create mode 100644 spec/ruby/library/net-ftp/acct_spec.rb create mode 100644 spec/ruby/library/net-ftp/binary_spec.rb create mode 100644 spec/ruby/library/net-ftp/chdir_spec.rb create mode 100644 spec/ruby/library/net-ftp/close_spec.rb create mode 100644 spec/ruby/library/net-ftp/closed_spec.rb create mode 100644 spec/ruby/library/net-ftp/connect_spec.rb create mode 100644 spec/ruby/library/net-ftp/debug_mode_spec.rb create mode 100644 spec/ruby/library/net-ftp/default_passive_spec.rb create mode 100644 spec/ruby/library/net-ftp/delete_spec.rb create mode 100644 spec/ruby/library/net-ftp/dir_spec.rb rename spec/ruby/library/{net/ftp => net-ftp}/fixtures/default_passive.rb (100%) rename spec/ruby/library/{net/ftp => net-ftp}/fixtures/passive.rb (100%) rename spec/ruby/library/{net/ftp => net-ftp}/fixtures/putbinaryfile (100%) rename spec/ruby/library/{net/ftp => net-ftp}/fixtures/puttextfile (100%) rename spec/ruby/library/{net/ftp => net-ftp}/fixtures/server.rb (100%) create mode 100644 spec/ruby/library/net-ftp/get_spec.rb create mode 100644 spec/ruby/library/net-ftp/getbinaryfile_spec.rb create mode 100644 spec/ruby/library/net-ftp/getdir_spec.rb create mode 100644 spec/ruby/library/net-ftp/gettextfile_spec.rb create mode 100644 spec/ruby/library/net-ftp/help_spec.rb create mode 100644 spec/ruby/library/net-ftp/initialize_spec.rb create mode 100644 spec/ruby/library/net-ftp/last_response_code_spec.rb create mode 100644 spec/ruby/library/net-ftp/last_response_spec.rb create mode 100644 spec/ruby/library/net-ftp/lastresp_spec.rb create mode 100644 spec/ruby/library/net-ftp/list_spec.rb create mode 100644 spec/ruby/library/net-ftp/login_spec.rb create mode 100644 spec/ruby/library/net-ftp/ls_spec.rb create mode 100644 spec/ruby/library/net-ftp/mdtm_spec.rb create mode 100644 spec/ruby/library/net-ftp/mkdir_spec.rb create mode 100644 spec/ruby/library/net-ftp/mtime_spec.rb create mode 100644 spec/ruby/library/net-ftp/nlst_spec.rb create mode 100644 spec/ruby/library/net-ftp/noop_spec.rb create mode 100644 spec/ruby/library/net-ftp/open_spec.rb create mode 100644 spec/ruby/library/net-ftp/passive_spec.rb create mode 100644 spec/ruby/library/net-ftp/put_spec.rb create mode 100644 spec/ruby/library/net-ftp/putbinaryfile_spec.rb create mode 100644 spec/ruby/library/net-ftp/puttextfile_spec.rb create mode 100644 spec/ruby/library/net-ftp/pwd_spec.rb create mode 100644 spec/ruby/library/net-ftp/quit_spec.rb create mode 100644 spec/ruby/library/net-ftp/rename_spec.rb create mode 100644 spec/ruby/library/net-ftp/resume_spec.rb create mode 100644 spec/ruby/library/net-ftp/retrbinary_spec.rb create mode 100644 spec/ruby/library/net-ftp/retrlines_spec.rb create mode 100644 spec/ruby/library/net-ftp/return_code_spec.rb create mode 100644 spec/ruby/library/net-ftp/rmdir_spec.rb create mode 100644 spec/ruby/library/net-ftp/sendcmd_spec.rb create mode 100644 spec/ruby/library/net-ftp/set_socket_spec.rb rename spec/ruby/library/{net/ftp => net-ftp}/shared/getbinaryfile.rb (100%) rename spec/ruby/library/{net/ftp => net-ftp}/shared/gettextfile.rb (100%) rename spec/ruby/library/{net/ftp => net-ftp}/shared/last_response_code.rb (100%) rename spec/ruby/library/{net/ftp => net-ftp}/shared/list.rb (100%) rename spec/ruby/library/{net/ftp => net-ftp}/shared/putbinaryfile.rb (100%) rename spec/ruby/library/{net/ftp => net-ftp}/shared/puttextfile.rb (100%) rename spec/ruby/library/{net/ftp => net-ftp}/shared/pwd.rb (100%) create mode 100644 spec/ruby/library/net-ftp/site_spec.rb create mode 100644 spec/ruby/library/net-ftp/size_spec.rb rename spec/ruby/library/{net/ftp => net-ftp}/spec_helper.rb (100%) create mode 100644 spec/ruby/library/net-ftp/status_spec.rb create mode 100644 spec/ruby/library/net-ftp/storbinary_spec.rb create mode 100644 spec/ruby/library/net-ftp/storlines_spec.rb create mode 100644 spec/ruby/library/net-ftp/system_spec.rb create mode 100644 spec/ruby/library/net-ftp/voidcmd_spec.rb create mode 100644 spec/ruby/library/net-ftp/welcome_spec.rb rename spec/ruby/library/{net/http => net-http}/HTTPBadResponse_spec.rb (79%) rename spec/ruby/library/{net/http => net-http}/HTTPClientExcepton_spec.rb (87%) rename spec/ruby/library/{net/http => net-http}/HTTPError_spec.rb (86%) rename spec/ruby/library/{net/http => net-http}/HTTPFatalError_spec.rb (87%) rename spec/ruby/library/{net/http => net-http}/HTTPHeaderSyntaxError_spec.rb (80%) rename spec/ruby/library/{net/http => net-http}/HTTPRetriableError_spec.rb (88%) rename spec/ruby/library/{net/http => net-http}/HTTPServerException_spec.rb (92%) rename spec/ruby/library/{net/http => net-http}/http/Proxy_spec.rb (96%) rename spec/ruby/library/{net/http => net-http}/http/active_spec.rb (80%) rename spec/ruby/library/{net/http => net-http}/http/address_spec.rb (80%) rename spec/ruby/library/{net/http => net-http}/http/close_on_empty_response_spec.rb (84%) rename spec/ruby/library/{net/http => net-http}/http/copy_spec.rb (92%) rename spec/ruby/library/{net/http => net-http}/http/default_port_spec.rb (75%) rename spec/ruby/library/{net/http => net-http}/http/delete_spec.rb (92%) rename spec/ruby/library/{net/http => net-http}/http/finish_spec.rb (93%) rename spec/ruby/library/{net/http => net-http}/http/fixtures/http_server.rb (100%) rename spec/ruby/library/{net/http => net-http}/http/get2_spec.rb (80%) rename spec/ruby/library/{net/http => net-http}/http/get_print_spec.rb (94%) rename spec/ruby/library/{net/http => net-http}/http/get_response_spec.rb (94%) rename spec/ruby/library/{net/http => net-http}/http/get_spec.rb (98%) rename spec/ruby/library/{net/http => net-http}/http/head2_spec.rb (80%) rename spec/ruby/library/{net/http => net-http}/http/head_spec.rb (93%) rename spec/ruby/library/{net/http => net-http}/http/http_default_port_spec.rb (76%) rename spec/ruby/library/{net/http => net-http}/http/https_default_port_spec.rb (77%) rename spec/ruby/library/{net/http => net-http}/http/initialize_spec.rb (96%) rename spec/ruby/library/{net/http => net-http}/http/inspect_spec.rb (93%) rename spec/ruby/library/{net/http => net-http}/http/is_version_1_1_spec.rb (79%) rename spec/ruby/library/{net/http => net-http}/http/is_version_1_2_spec.rb (79%) rename spec/ruby/library/{net/http => net-http}/http/lock_spec.rb (92%) rename spec/ruby/library/{net/http => net-http}/http/mkcol_spec.rb (92%) rename spec/ruby/library/{net/http => net-http}/http/move_spec.rb (93%) rename spec/ruby/library/{net/http => net-http}/http/new_spec.rb (98%) rename spec/ruby/library/{net/http => net-http}/http/newobj_spec.rb (96%) rename spec/ruby/library/{net/http => net-http}/http/open_timeout_spec.rb (93%) rename spec/ruby/library/{net/http => net-http}/http/options_spec.rb (93%) rename spec/ruby/library/{net/http => net-http}/http/port_spec.rb (80%) rename spec/ruby/library/{net/http => net-http}/http/post2_spec.rb (80%) rename spec/ruby/library/{net/http => net-http}/http/post_form_spec.rb (91%) rename spec/ruby/library/{net/http => net-http}/http/post_spec.rb (98%) rename spec/ruby/library/{net/http => net-http}/http/propfind_spec.rb (93%) rename spec/ruby/library/{net/http => net-http}/http/proppatch_spec.rb (93%) rename spec/ruby/library/{net/http => net-http}/http/proxy_address_spec.rb (95%) rename spec/ruby/library/{net/http => net-http}/http/proxy_class_spec.rb (84%) rename spec/ruby/library/{net/http => net-http}/http/proxy_pass_spec.rb (96%) rename spec/ruby/library/{net/http => net-http}/http/proxy_port_spec.rb (96%) rename spec/ruby/library/{net/http => net-http}/http/proxy_user_spec.rb (96%) rename spec/ruby/library/{net/http => net-http}/http/put2_spec.rb (80%) rename spec/ruby/library/{net/http => net-http}/http/put_spec.rb (93%) rename spec/ruby/library/{net/http => net-http}/http/read_timeout_spec.rb (93%) rename spec/ruby/library/{net/http => net-http}/http/request_get_spec.rb (81%) rename spec/ruby/library/{net/http => net-http}/http/request_head_spec.rb (82%) rename spec/ruby/library/{net/http => net-http}/http/request_post_spec.rb (82%) rename spec/ruby/library/{net/http => net-http}/http/request_put_spec.rb (81%) rename spec/ruby/library/{net/http => net-http}/http/request_spec.rb (98%) rename spec/ruby/library/{net/http => net-http}/http/request_types_spec.rb (99%) rename spec/ruby/library/{net/http => net-http}/http/send_request_spec.rb (97%) rename spec/ruby/library/{net/http => net-http}/http/set_debug_output_spec.rb (94%) rename spec/ruby/library/{net/http => net-http}/http/shared/request_get.rb (100%) rename spec/ruby/library/{net/http => net-http}/http/shared/request_head.rb (100%) rename spec/ruby/library/{net/http => net-http}/http/shared/request_post.rb (100%) rename spec/ruby/library/{net/http => net-http}/http/shared/request_put.rb (100%) rename spec/ruby/library/{net/http => net-http}/http/shared/started.rb (100%) rename spec/ruby/library/{net/http => net-http}/http/shared/version_1_1.rb (100%) rename spec/ruby/library/{net/http => net-http}/http/shared/version_1_2.rb (100%) rename spec/ruby/library/{net/http => net-http}/http/socket_type_spec.rb (77%) rename spec/ruby/library/{net/http => net-http}/http/start_spec.rb (98%) rename spec/ruby/library/{net/http => net-http}/http/started_spec.rb (80%) rename spec/ruby/library/{net/http => net-http}/http/trace_spec.rb (93%) rename spec/ruby/library/{net/http => net-http}/http/unlock_spec.rb (93%) rename spec/ruby/library/{net/http => net-http}/http/use_ssl_spec.rb (78%) rename spec/ruby/library/{net/http => net-http}/http/version_1_1_spec.rb (78%) rename spec/ruby/library/{net/http => net-http}/http/version_1_2_spec.rb (90%) rename spec/ruby/library/{net/http => net-http}/httpexceptions/fixtures/classes.rb (100%) rename spec/ruby/library/{net/http => net-http}/httpexceptions/initialize_spec.rb (91%) rename spec/ruby/library/{net/http => net-http}/httpexceptions/response_spec.rb (86%) rename spec/ruby/library/{net/http => net-http}/httpgenericrequest/body_exist_spec.rb (93%) rename spec/ruby/library/{net/http => net-http}/httpgenericrequest/body_spec.rb (94%) rename spec/ruby/library/{net/http => net-http}/httpgenericrequest/body_stream_spec.rb (95%) rename spec/ruby/library/{net/http => net-http}/httpgenericrequest/exec_spec.rb (99%) rename spec/ruby/library/{net/http => net-http}/httpgenericrequest/inspect_spec.rb (95%) rename spec/ruby/library/{net/http => net-http}/httpgenericrequest/method_spec.rb (91%) rename spec/ruby/library/{net/http => net-http}/httpgenericrequest/path_spec.rb (89%) rename spec/ruby/library/{net/http => net-http}/httpgenericrequest/request_body_permitted_spec.rb (90%) rename spec/ruby/library/{net/http => net-http}/httpgenericrequest/response_body_permitted_spec.rb (90%) rename spec/ruby/library/{net/http => net-http}/httpgenericrequest/set_body_internal_spec.rb (94%) rename spec/ruby/library/{net/http => net-http}/httpheader/add_field_spec.rb (95%) rename spec/ruby/library/{net/http => net-http}/httpheader/basic_auth_spec.rb (90%) rename spec/ruby/library/{net/http => net-http}/httpheader/canonical_each_spec.rb (83%) rename spec/ruby/library/{net/http => net-http}/httpheader/chunked_spec.rb (92%) rename spec/ruby/library/{net/http => net-http}/httpheader/content_length_spec.rb (97%) rename spec/ruby/library/{net/http => net-http}/httpheader/content_range_spec.rb (96%) rename spec/ruby/library/{net/http => net-http}/httpheader/content_type_spec.rb (94%) rename spec/ruby/library/{net/http => net-http}/httpheader/delete_spec.rb (94%) rename spec/ruby/library/{net/http => net-http}/httpheader/each_capitalized_name_spec.rb (95%) rename spec/ruby/library/{net/http => net-http}/httpheader/each_capitalized_spec.rb (83%) rename spec/ruby/library/{net/http => net-http}/httpheader/each_header_spec.rb (82%) rename spec/ruby/library/{net/http => net-http}/httpheader/each_key_spec.rb (81%) rename spec/ruby/library/{net/http => net-http}/httpheader/each_name_spec.rb (81%) rename spec/ruby/library/{net/http => net-http}/httpheader/each_spec.rb (81%) rename spec/ruby/library/{net/http => net-http}/httpheader/each_value_spec.rb (95%) rename spec/ruby/library/{net/http => net-http}/httpheader/element_reference_spec.rb (96%) rename spec/ruby/library/{net/http => net-http}/httpheader/element_set_spec.rb (96%) rename spec/ruby/library/{net/http => net-http}/httpheader/fetch_spec.rb (98%) rename spec/ruby/library/{net/http => net-http}/httpheader/fixtures/classes.rb (100%) rename spec/ruby/library/{net/http => net-http}/httpheader/form_data_spec.rb (82%) rename spec/ruby/library/{net/http => net-http}/httpheader/get_fields_spec.rb (96%) rename spec/ruby/library/{net/http => net-http}/httpheader/initialize_http_header_spec.rb (94%) rename spec/ruby/library/{net/http => net-http}/httpheader/key_spec.rb (92%) rename spec/ruby/library/{net/http => net-http}/httpheader/length_spec.rb (80%) rename spec/ruby/library/{net/http => net-http}/httpheader/main_type_spec.rb (93%) rename spec/ruby/library/{net/http => net-http}/httpheader/proxy_basic_auth_spec.rb (90%) rename spec/ruby/library/{net/http => net-http}/httpheader/range_length_spec.rb (96%) rename spec/ruby/library/{net/http => net-http}/httpheader/range_spec.rb (97%) rename spec/ruby/library/{net/http => net-http}/httpheader/set_content_type_spec.rb (83%) rename spec/ruby/library/{net/http => net-http}/httpheader/set_form_data_spec.rb (82%) rename spec/ruby/library/{net/http => net-http}/httpheader/set_range_spec.rb (81%) rename spec/ruby/library/{net/http => net-http}/httpheader/shared/each_capitalized.rb (100%) rename spec/ruby/library/{net/http => net-http}/httpheader/shared/each_header.rb (100%) rename spec/ruby/library/{net/http => net-http}/httpheader/shared/each_name.rb (100%) rename spec/ruby/library/{net/http => net-http}/httpheader/shared/set_content_type.rb (100%) rename spec/ruby/library/{net/http => net-http}/httpheader/shared/set_form_data.rb (100%) rename spec/ruby/library/{net/http => net-http}/httpheader/shared/set_range.rb (100%) rename spec/ruby/library/{net/http => net-http}/httpheader/shared/size.rb (100%) rename spec/ruby/library/{net/http => net-http}/httpheader/size_spec.rb (80%) rename spec/ruby/library/{net/http => net-http}/httpheader/sub_type_spec.rb (95%) rename spec/ruby/library/{net/http => net-http}/httpheader/to_hash_spec.rb (94%) rename spec/ruby/library/{net/http => net-http}/httpheader/type_params_spec.rb (94%) rename spec/ruby/library/{net/http => net-http}/httprequest/initialize_spec.rb (96%) rename spec/ruby/library/{net/http => net-http}/httpresponse/body_permitted_spec.rb (91%) rename spec/ruby/library/{net/http => net-http}/httpresponse/body_spec.rb (76%) rename spec/ruby/library/{net/http => net-http}/httpresponse/code_spec.rb (94%) rename spec/ruby/library/{net/http => net-http}/httpresponse/code_type_spec.rb (94%) rename spec/ruby/library/{net/http => net-http}/httpresponse/entity_spec.rb (77%) rename spec/ruby/library/{net/http => net-http}/httpresponse/error_spec.rb (95%) rename spec/ruby/library/{net/http => net-http}/httpresponse/error_type_spec.rb (95%) rename spec/ruby/library/{net/http => net-http}/httpresponse/exception_type_spec.rb (92%) rename spec/ruby/library/{net/http => net-http}/httpresponse/header_spec.rb (82%) rename spec/ruby/library/{net/http => net-http}/httpresponse/http_version_spec.rb (88%) rename spec/ruby/library/{net/http => net-http}/httpresponse/initialize_spec.rb (90%) rename spec/ruby/library/{net/http => net-http}/httpresponse/inspect_spec.rb (92%) rename spec/ruby/library/{net/http => net-http}/httpresponse/message_spec.rb (83%) rename spec/ruby/library/{net/http => net-http}/httpresponse/msg_spec.rb (83%) rename spec/ruby/library/{net/http => net-http}/httpresponse/read_body_spec.rb (98%) rename spec/ruby/library/{net/http => net-http}/httpresponse/read_header_spec.rb (82%) rename spec/ruby/library/{net/http => net-http}/httpresponse/read_new_spec.rb (93%) rename spec/ruby/library/{net/http => net-http}/httpresponse/reading_body_spec.rb (97%) rename spec/ruby/library/{net/http => net-http}/httpresponse/response_spec.rb (82%) rename spec/ruby/library/{net/http => net-http}/httpresponse/shared/body.rb (100%) rename spec/ruby/library/{net/http => net-http}/httpresponse/value_spec.rb (95%) delete mode 100644 spec/ruby/library/net/FTPError_spec.rb delete mode 100644 spec/ruby/library/net/FTPPermError_spec.rb delete mode 100644 spec/ruby/library/net/FTPProtoError_spec.rb delete mode 100644 spec/ruby/library/net/FTPReplyError_spec.rb delete mode 100644 spec/ruby/library/net/FTPTempError_spec.rb delete mode 100644 spec/ruby/library/net/ftp/abort_spec.rb delete mode 100644 spec/ruby/library/net/ftp/acct_spec.rb delete mode 100644 spec/ruby/library/net/ftp/binary_spec.rb delete mode 100644 spec/ruby/library/net/ftp/chdir_spec.rb delete mode 100644 spec/ruby/library/net/ftp/close_spec.rb delete mode 100644 spec/ruby/library/net/ftp/closed_spec.rb delete mode 100644 spec/ruby/library/net/ftp/connect_spec.rb delete mode 100644 spec/ruby/library/net/ftp/debug_mode_spec.rb delete mode 100644 spec/ruby/library/net/ftp/default_passive_spec.rb delete mode 100644 spec/ruby/library/net/ftp/delete_spec.rb delete mode 100644 spec/ruby/library/net/ftp/dir_spec.rb delete mode 100644 spec/ruby/library/net/ftp/get_spec.rb delete mode 100644 spec/ruby/library/net/ftp/getbinaryfile_spec.rb delete mode 100644 spec/ruby/library/net/ftp/getdir_spec.rb delete mode 100644 spec/ruby/library/net/ftp/gettextfile_spec.rb delete mode 100644 spec/ruby/library/net/ftp/help_spec.rb delete mode 100644 spec/ruby/library/net/ftp/initialize_spec.rb delete mode 100644 spec/ruby/library/net/ftp/last_response_code_spec.rb delete mode 100644 spec/ruby/library/net/ftp/last_response_spec.rb delete mode 100644 spec/ruby/library/net/ftp/lastresp_spec.rb delete mode 100644 spec/ruby/library/net/ftp/list_spec.rb delete mode 100644 spec/ruby/library/net/ftp/login_spec.rb delete mode 100644 spec/ruby/library/net/ftp/ls_spec.rb delete mode 100644 spec/ruby/library/net/ftp/mdtm_spec.rb delete mode 100644 spec/ruby/library/net/ftp/mkdir_spec.rb delete mode 100644 spec/ruby/library/net/ftp/mtime_spec.rb delete mode 100644 spec/ruby/library/net/ftp/nlst_spec.rb delete mode 100644 spec/ruby/library/net/ftp/noop_spec.rb delete mode 100644 spec/ruby/library/net/ftp/open_spec.rb delete mode 100644 spec/ruby/library/net/ftp/passive_spec.rb delete mode 100644 spec/ruby/library/net/ftp/put_spec.rb delete mode 100644 spec/ruby/library/net/ftp/putbinaryfile_spec.rb delete mode 100644 spec/ruby/library/net/ftp/puttextfile_spec.rb delete mode 100644 spec/ruby/library/net/ftp/pwd_spec.rb delete mode 100644 spec/ruby/library/net/ftp/quit_spec.rb delete mode 100644 spec/ruby/library/net/ftp/rename_spec.rb delete mode 100644 spec/ruby/library/net/ftp/resume_spec.rb delete mode 100644 spec/ruby/library/net/ftp/retrbinary_spec.rb delete mode 100644 spec/ruby/library/net/ftp/retrlines_spec.rb delete mode 100644 spec/ruby/library/net/ftp/return_code_spec.rb delete mode 100644 spec/ruby/library/net/ftp/rmdir_spec.rb delete mode 100644 spec/ruby/library/net/ftp/sendcmd_spec.rb delete mode 100644 spec/ruby/library/net/ftp/set_socket_spec.rb delete mode 100644 spec/ruby/library/net/ftp/site_spec.rb delete mode 100644 spec/ruby/library/net/ftp/size_spec.rb delete mode 100644 spec/ruby/library/net/ftp/status_spec.rb delete mode 100644 spec/ruby/library/net/ftp/storbinary_spec.rb delete mode 100644 spec/ruby/library/net/ftp/storlines_spec.rb delete mode 100644 spec/ruby/library/net/ftp/system_spec.rb delete mode 100644 spec/ruby/library/net/ftp/voidcmd_spec.rb delete mode 100644 spec/ruby/library/net/ftp/welcome_spec.rb create mode 100644 spec/ruby/library/set/set_spec.rb delete mode 100644 spec/ruby/shared/rational/coerce.rb diff --git a/spec/ruby/.rubocop_todo.yml b/spec/ruby/.rubocop_todo.yml index a59e64bd58b..3ebb23a8bb7 100644 --- a/spec/ruby/.rubocop_todo.yml +++ b/spec/ruby/.rubocop_todo.yml @@ -63,7 +63,6 @@ Lint/LiteralInInterpolation: - 'language/string_spec.rb' - 'language/symbol_spec.rb' - 'language/undef_spec.rb' - - 'library/net/ftp/connect_spec.rb' # Offense count: 8 # Cop supports --auto-correct. diff --git a/spec/ruby/command_line/backtrace_limit_spec.rb b/spec/ruby/command_line/backtrace_limit_spec.rb index bc40a542a07..4d57bc268b5 100644 --- a/spec/ruby/command_line/backtrace_limit_spec.rb +++ b/spec/ruby/command_line/backtrace_limit_spec.rb @@ -1,46 +1,93 @@ require_relative '../spec_helper' describe "The --backtrace-limit command line option" 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__, '') + 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 + 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 + 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__, '') + 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 + 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 + 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__, '') + 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 + 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 `
' - MSG + 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 '
' + MSG + end 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 ab6b2a2d10c..fc65a091aaa 100644 --- a/spec/ruby/core/basicobject/singleton_method_added_spec.rb +++ b/spec/ruby/core/basicobject/singleton_method_added_spec.rb @@ -94,7 +94,7 @@ class << self -> { def self.foo end - }.should raise_error(NoMethodError, /undefined method `singleton_method_added' for/) + }.should raise_error(NoMethodError, /undefined method [`']singleton_method_added' for/) end end @@ -106,16 +106,16 @@ class << object -> { def foo end - }.should raise_error(NoMethodError, /undefined method `singleton_method_added' for # { define_method(:bar) {} - }.should raise_error(NoMethodError, /undefined method `singleton_method_added' for # { object.define_singleton_method(:baz) {} - }.should raise_error(NoMethodError, /undefined method `singleton_method_added' for # { nil.singleton_class.attached_object }.should raise_error(TypeError, /`NilClass' is not a singleton class/) - -> { true.singleton_class.attached_object }.should raise_error(TypeError, /`TrueClass' is not a singleton class/) - -> { false.singleton_class.attached_object }.should raise_error(TypeError, /`FalseClass' is not a singleton class/) + -> { nil.singleton_class.attached_object }.should raise_error(TypeError, /[`']NilClass' is not a singleton class/) + -> { true.singleton_class.attached_object }.should raise_error(TypeError, /[`']TrueClass' is not a singleton class/) + -> { false.singleton_class.attached_object }.should raise_error(TypeError, /[`']FalseClass' is not a singleton class/) end end end diff --git a/spec/ruby/core/encoding/replicate_spec.rb b/spec/ruby/core/encoding/replicate_spec.rb index 498d03581ac..68c285158d3 100644 --- a/spec/ruby/core/encoding/replicate_spec.rb +++ b/spec/ruby/core/encoding/replicate_spec.rb @@ -73,6 +73,11 @@ Encoding::US_ASCII.replicate('MY-US-ASCII') }.should complain(/warning: Encoding#replicate is deprecated and will be removed in Ruby 3.3; use the original encoding instead/) end + + it "raises EncodingError if too many encodings" do + code = '1_000.times {|i| Encoding::US_ASCII.replicate("R_#{i}") }' + ruby_exe(code, args: "2>&1", exit_status: 1).should.include?('too many encoding (> 256) (EncodingError)') + end end ruby_version_is "3.3" do diff --git a/spec/ruby/core/enumerable/fixtures/classes.rb b/spec/ruby/core/enumerable/fixtures/classes.rb index fb4951c6e62..2701c6999c4 100644 --- a/spec/ruby/core/enumerable/fixtures/classes.rb +++ b/spec/ruby/core/enumerable/fixtures/classes.rb @@ -342,4 +342,10 @@ def ===(*args) @block.call(*args) end end + + # Set is a core class since Ruby 3.2 + ruby_version_is '3.2' do + class SetSubclass < Set + end + end end # EnumerableSpecs utility classes 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 00000000000..c21a2772c47 --- /dev/null +++ b/spec/ruby/core/enumerable/to_set_spec.rb @@ -0,0 +1,29 @@ +require_relative '../../spec_helper' +require_relative 'fixtures/classes' + +ruby_version_is "3.2" do + describe "Enumerable#to_set" do + it "returns a new Set created from self" do + [1, 2, 3].to_set.should == Set[1, 2, 3] + {a: 1, b: 2}.to_set.should == Set[[:b, 2], [:a, 1]] + end + + it "passes down passed blocks" do + [1, 2, 3].to_set { |x| x * x }.should == Set[1, 4, 9] + end + + it "instantiates an object of provided as the first argument set class" do + set = [1, 2, 3].to_set(EnumerableSpecs::SetSubclass) + set.should be_kind_of(EnumerableSpecs::SetSubclass) + set.to_a.sort.should == [1, 2, 3] + end + + it "does not need explicit `require 'set'`" do + output = ruby_exe(<<~RUBY, options: '--disable-gems', args: '2>&1') + puts [1, 2, 3].to_set + RUBY + + output.chomp.should == "#" + end + end +end diff --git a/spec/ruby/core/enumerator/product/each_spec.rb b/spec/ruby/core/enumerator/product/each_spec.rb index 868a1ea6bf4..cabeb9d93a2 100644 --- a/spec/ruby/core/enumerator/product/each_spec.rb +++ b/spec/ruby/core/enumerator/product/each_spec.rb @@ -34,7 +34,7 @@ def object2.each_entry it "raises a NoMethodError if the object doesn't respond to #each_entry" do -> { Enumerator::Product.new(Object.new).each {} - }.should raise_error(NoMethodError, /undefined method `each_entry' for/) + }.should raise_error(NoMethodError, /undefined method [`']each_entry' for/) end it "returns enumerator if not given a block" do diff --git a/spec/ruby/core/enumerator/product_spec.rb b/spec/ruby/core/enumerator/product_spec.rb index 0fb00fc7ee8..0acca6690eb 100644 --- a/spec/ruby/core/enumerator/product_spec.rb +++ b/spec/ruby/core/enumerator/product_spec.rb @@ -69,7 +69,7 @@ def object.each_entry it "raises NoMethodError when argument doesn't respond to #each_entry" do -> { Enumerator.product(Object.new).to_a - }.should raise_error(NoMethodError, /undefined method `each_entry' for/) + }.should raise_error(NoMethodError, /undefined method [`']each_entry' for/) end it "calls #each_entry lazily" do diff --git a/spec/ruby/core/exception/backtrace_spec.rb b/spec/ruby/core/exception/backtrace_spec.rb index 3f74c4cefe0..9a65ea3820e 100644 --- a/spec/ruby/core/exception/backtrace_spec.rb +++ b/spec/ruby/core/exception/backtrace_spec.rb @@ -27,7 +27,7 @@ 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,12 +38,25 @@ @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 + + 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 diff --git a/spec/ruby/core/exception/full_message_spec.rb b/spec/ruby/core/exception/full_message_spec.rb index 4fad369936b..51543545551 100644 --- a/spec/ruby/core/exception/full_message_spec.rb +++ b/spec/ruby/core/exception/full_message_spec.rb @@ -42,7 +42,7 @@ 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.start_with?("#{__FILE__}:#{__LINE__-1}:in ") full_message[0].should.end_with?("': Some runtime error (RuntimeError)\n") end @@ -94,7 +94,7 @@ 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.start_with?("#{__FILE__}:#{line}:in ") full_message[0].should.end_with?(": first line (RuntimeError)\n") full_message[1].should == "second line\n" end @@ -105,7 +105,7 @@ 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.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" diff --git a/spec/ruby/core/exception/interrupt_spec.rb b/spec/ruby/core/exception/interrupt_spec.rb index 299b5b81f33..90d261e4703 100644 --- a/spec/ruby/core/exception/interrupt_spec.rb +++ b/spec/ruby/core/exception/interrupt_spec.rb @@ -54,7 +54,7 @@ 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.include? "from -e:1:in `
'" + err.should =~ /from -e:1:in [`']
'/ end end end diff --git a/spec/ruby/core/exception/no_method_error_spec.rb b/spec/ruby/core/exception/no_method_error_spec.rb index 4621e36f448..26df3338e9d 100644 --- a/spec/ruby/core/exception/no_method_error_spec.rb +++ b/spec/ruby/core/exception/no_method_error_spec.rb @@ -62,7 +62,7 @@ NoMethodErrorSpecs::NoMethodErrorC.new.a_private_method rescue Exception => e e.should be_kind_of(NoMethodError) - e.message.lines[0].should =~ /private method `a_private_method' called for / + e.message.lines[0].should =~ /private method [`']a_private_method' called for / end end @@ -130,14 +130,14 @@ def inspect begin klass.foo rescue NoMethodError => error - error.message.lines.first.chomp.should =~ /^undefined method `foo' for / + error.message.lines.first.chomp.should =~ /^undefined method [`']foo' for / end mod = Module.new { def self.name; "MyModule"; end } begin mod.foo rescue NoMethodError => error - error.message.lines.first.chomp.should =~ /^undefined method `foo' for / + error.message.lines.first.chomp.should =~ /^undefined method [`']foo' for / end end end diff --git a/spec/ruby/core/exception/to_s_spec.rb b/spec/ruby/core/exception/to_s_spec.rb index 4c4c7ab432f..65c0d73a988 100644 --- a/spec/ruby/core/exception/to_s_spec.rb +++ b/spec/ruby/core/exception/to_s_spec.rb @@ -23,7 +23,7 @@ begin puts not_defined rescue => exception - exception.message.should =~ /undefined local variable or method `not_defined'/ + exception.message.should =~ /undefined local variable or method [`']not_defined'/ end end diff --git a/spec/ruby/core/exception/top_level_spec.rb b/spec/ruby/core/exception/top_level_spec.rb index bcd09205b69..6ef75395984 100644 --- a/spec/ruby/core/exception/top_level_spec.rb +++ b/spec/ruby/core/exception/top_level_spec.rb @@ -2,7 +2,7 @@ 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.include?("in `
': foo (RuntimeError)") + ruby_exe('raise "foo"', args: "2>&1", exit_status: 1).should =~ /in [`']
': foo \(RuntimeError\)/ end it "the Exception#cause is printed to STDERR with backtraces" do @@ -20,12 +20,13 @@ def raise_wrapped end RUBY lines = ruby_exe(code, args: "2>&1", exit_status: 1).lines - lines.reject! { |l| l.include?('rescue in') } lines.map! { |l| l.chomp[/:(in.+)/, 1] } - lines.should == ["in `raise_wrapped': wrapped (RuntimeError)", - "in `
'", - "in `raise_cause': the cause (RuntimeError)", - "in `
'"] + lines.size.should == 5 + lines[0].should =~ /\Ain [`'](?:Object#)?raise_wrapped': wrapped \(RuntimeError\)\z/ + lines[1].should =~ /\Ain [`'](?:rescue in )?
'\z/ + lines[2].should =~ /\Ain [`']
'\z/ + lines[3].should =~ /\Ain [`'](?:Object#)?raise_cause': the cause \(RuntimeError\)\z/ + lines[4].should =~ /\Ain [`']
'\z/ end describe "with a custom backtrace" do diff --git a/spec/ruby/core/file/lutime_spec.rb b/spec/ruby/core/file/lutime_spec.rb index 1f0625f61eb..0f6df42ea37 100644 --- a/spec/ruby/core/file/lutime_spec.rb +++ b/spec/ruby/core/file/lutime_spec.rb @@ -1,7 +1,12 @@ require_relative '../../spec_helper' +require_relative 'shared/update_time' -describe "File.lutime" do - platform_is_not :windows do +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) 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 00000000000..9c063a8e935 --- /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 wordsize: 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/utime_spec.rb b/spec/ruby/core/file/utime_spec.rb index 0b0e4f979c9..d87626be509 100644 --- a/spec/ruby/core/file/utime_spec.rb +++ b/spec/ruby/core/file/utime_spec.rb @@ -1,102 +1,6 @@ require_relative '../../spec_helper' +require_relative 'shared/update_time' describe "File.utime" 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.utime(@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.utime(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.utime(@atime, @mtime, mock_to_path(@file1), mock_to_path(@file2)) - end - - it "accepts numeric atime and mtime arguments" do - if @time_is_float - File.utime(@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.utime(@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.utime(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.utime(@atime.to_f, @mtime.to_f, @file1, @file2).should == 2 - end - - platform_is :linux do - platform_is wordsize: 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.utime(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 + it_behaves_like :update_time, :utime end diff --git a/spec/ruby/core/filetest/exist_spec.rb b/spec/ruby/core/filetest/exist_spec.rb index 4d14bea2311..a95d3f91a18 100644 --- a/spec/ruby/core/filetest/exist_spec.rb +++ b/spec/ruby/core/filetest/exist_spec.rb @@ -4,3 +4,11 @@ describe "FileTest.exist?" do it_behaves_like :file_exist, :exist?, FileTest end + +ruby_version_is "3.2" do + describe "FileTest.exists?" do + it "has been removed" do + FileTest.should_not.respond_to?(:exists?) + end + end +end diff --git a/spec/ruby/core/integer/coerce_spec.rb b/spec/ruby/core/integer/coerce_spec.rb index 13fe7b33217..1d6dc9713f5 100644 --- a/spec/ruby/core/integer/coerce_spec.rb +++ b/spec/ruby/core/integer/coerce_spec.rb @@ -88,18 +88,4 @@ ary.should == [1.2, a.to_f] end end - - ruby_version_is ""..."3.4" do - require 'bigdecimal' - context "bigdecimal" 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 - end - end diff --git a/spec/ruby/core/io/pwrite_spec.rb b/spec/ruby/core/io/pwrite_spec.rb index 00d40db28d7..2bc508b37d1 100644 --- a/spec/ruby/core/io/pwrite_spec.rb +++ b/spec/ruby/core/io/pwrite_spec.rb @@ -57,7 +57,7 @@ it "raises a NoMethodError if object does not respond to #to_s" do -> { @file.pwrite(BasicObject.new, 0) - }.should raise_error(NoMethodError, /undefined method `to_s'/) + }.should raise_error(NoMethodError, /undefined method [`']to_s'/) end it "raises a TypeError if the offset cannot be converted to an Integer" do diff --git a/spec/ruby/core/kernel/caller_locations_spec.rb b/spec/ruby/core/kernel/caller_locations_spec.rb index 5994b28fa31..aaacd9a9105 100644 --- a/spec/ruby/core/kernel/caller_locations_spec.rb +++ b/spec/ruby/core/kernel/caller_locations_spec.rb @@ -71,14 +71,28 @@ end guard -> { Kernel.instance_method(:tap).source_location } do - it "includes core library methods defined in Ruby" do - file, line = Kernel.instance_method(:tap).source_location - file.should.start_with?(''\n" - ] + lines.size.should == 2 + lines[0].should =~ /\A#{path}:6:in [`'](?:Object#)?foo'\n\z/ + lines[1].should =~ /\A#{path}:2:in [`']block in
'\n\z/ end it "works with endless ranges" do @@ -63,8 +62,7 @@ loc = nil tap { loc = caller(1, 1)[0] } - loc.should.end_with? "in `tap'" - loc.should.start_with? " { eval(code) }.should complain(/warning: `frozen_string_literal' is ignored after any tokens/, verbose: true) + -> { eval(code) }.should complain(/warning: [`']frozen_string_literal' is ignored after any tokens/, verbose: true) EvalSpecs::Vπstring_not_frozen.frozen?.should be_false EvalSpecs.send :remove_const, :Vπstring_not_frozen diff --git a/spec/ruby/core/kernel/not_match_spec.rb b/spec/ruby/core/kernel/not_match_spec.rb index 906f18df2c6..f8dd82fad86 100644 --- a/spec/ruby/core/kernel/not_match_spec.rb +++ b/spec/ruby/core/kernel/not_match_spec.rb @@ -14,6 +14,20 @@ def !~(obj) (obj !~ :foo).should == false end + ruby_version_is ""..."3.2" do + it "returns true if self does not respond to #=~" do + suppress_warning do + (Object.new !~ :foo).should == true + end + end + end + + ruby_version_is "3.2" do + it "raises NoMethodError if self does not respond to #=~" do + -> { Object.new !~ :foo }.should raise_error(NoMethodError) + end + end + it 'can be overridden in subclasses' do obj = KernelSpecs::NotMatch.new (obj !~ :bar).should == :foo diff --git a/spec/ruby/core/kernel/public_send_spec.rb b/spec/ruby/core/kernel/public_send_spec.rb index 4dae419ff9d..b684b1729c7 100644 --- a/spec/ruby/core/kernel/public_send_spec.rb +++ b/spec/ruby/core/kernel/public_send_spec.rb @@ -105,11 +105,11 @@ def bar end it "includes `public_send` in the backtrace when passed not enough arguments" do - -> { public_send() }.should raise_error(ArgumentError) { |e| e.backtrace[0].should.include?("`public_send'") } + -> { public_send() }.should raise_error(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_error(TypeError) { |e| e.backtrace[0].should.include?("`public_send'") } + -> { public_send(Object.new) }.should raise_error(TypeError) { |e| e.backtrace[0].should =~ /[`'](?:Kernel#)?public_send'/ } end it_behaves_like :basicobject_send, :public_send diff --git a/spec/ruby/core/marshal/dump_spec.rb b/spec/ruby/core/marshal/dump_spec.rb index eaf238bbd93..34db6fef831 100644 --- a/spec/ruby/core/marshal/dump_spec.rb +++ b/spec/ruby/core/marshal/dump_spec.rb @@ -740,7 +740,7 @@ def finalizer.noop(_) rescue => e end - Marshal.dump(e).should =~ /undefined method `foo' for ("":String|an instance of String)/ + Marshal.dump(e).should =~ /undefined method [`']foo' for ("":String|an instance of String)/ end it "raises TypeError if an Object is an instance of an anonymous class" do diff --git a/spec/ruby/core/method/clone_spec.rb b/spec/ruby/core/method/clone_spec.rb index 3fe4000fb79..b0eb5751a99 100644 --- a/spec/ruby/core/method/clone_spec.rb +++ b/spec/ruby/core/method/clone_spec.rb @@ -1,14 +1,13 @@ require_relative '../../spec_helper' -require_relative 'fixtures/classes' +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/dup_spec.rb b/spec/ruby/core/method/dup_spec.rb new file mode 100644 index 00000000000..e3e29d8a68b --- /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/parameters_spec.rb b/spec/ruby/core/method/parameters_spec.rb index 7d2b37fac75..8495aef4d2d 100644 --- a/spec/ruby/core/method/parameters_spec.rb +++ b/spec/ruby/core/method/parameters_spec.rb @@ -22,6 +22,8 @@ def one_splat_one_block(*args, &block) local_is_not_parameter = {} end + def forward_parameters(...) end + def underscore_parameters(_, _, _ = 1, *_, _:, _: 2, **_, &_); end define_method(:one_optional_defined_method) {|x = 1|} @@ -267,6 +269,20 @@ def object.foo(&) end end + ruby_version_is ""..."3.1" do + it "returns [:rest, :*], [:block, :&] for forward parameters operator" do + m = MethodSpecs::Methods.new + m.method(:forward_parameters).parameters.should == [[:rest, :*], [:block, :&]] + end + end + + ruby_version_is "3.1" do + it "returns [:rest, :*], [:keyrest, :**], [:block, :&] for forward parameters operator" do + m = MethodSpecs::Methods.new + m.method(:forward_parameters).parameters.should == [[:rest, :*], [:keyrest, :**], [:block, :&]] + end + end + it "returns the args and block for a splat and block argument" do m = MethodSpecs::Methods.new m.method(:one_splat_one_block).parameters.should == [[:rest, :args], [:block, :block]] diff --git a/spec/ruby/core/method/shared/dup.rb b/spec/ruby/core/method/shared/dup.rb new file mode 100644 index 00000000000..1a10b90689f --- /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/module/prepend_spec.rb b/spec/ruby/core/module/prepend_spec.rb index f80cfbcca18..c90fa9700ec 100644 --- a/spec/ruby/core/module/prepend_spec.rb +++ b/spec/ruby/core/module/prepend_spec.rb @@ -737,6 +737,39 @@ def foo(ary) 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 + ruby_version_is ""..."3.1" do + it "does not modify 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(4).should == [b, m, a, Object] + end + end + + ruby_version_is "3.1" 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 + end + describe "called on a module" do describe "included into a class" it "does not obscure the module's methods from reflective access" do diff --git a/spec/ruby/core/module/ruby2_keywords_spec.rb b/spec/ruby/core/module/ruby2_keywords_spec.rb index a72612a670c..aca419f522b 100644 --- a/spec/ruby/core/module/ruby2_keywords_spec.rb +++ b/spec/ruby/core/module/ruby2_keywords_spec.rb @@ -237,7 +237,7 @@ def foo(*a) end obj.singleton_class.class_exec do ruby2_keywords :not_existing end - }.should raise_error(NameError, /undefined method `not_existing'/) + }.should raise_error(NameError, /undefined method [`']not_existing'/) end it "accepts String as well" do diff --git a/spec/ruby/core/module/undef_method_spec.rb b/spec/ruby/core/module/undef_method_spec.rb index c2ad2005361..d4efcd51cbe 100644 --- a/spec/ruby/core/module/undef_method_spec.rb +++ b/spec/ruby/core/module/undef_method_spec.rb @@ -50,7 +50,7 @@ def another_method_to_undef() 1 end end it "raises a NameError when passed a missing name for a module" do - -> { @module.send :undef_method, :not_exist }.should raise_error(NameError, /undefined method `not_exist' for module `#{@module}'/) { |e| + -> { @module.send :undef_method, :not_exist }.should raise_error(NameError, /undefined method [`']not_exist' for module [`']#{@module}'/) { |e| # a NameError and not a NoMethodError e.class.should == NameError } @@ -58,7 +58,7 @@ def another_method_to_undef() 1 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_error(NameError, /undefined method `not_exist' for class `#{klass}'/) { |e| + -> { klass.send :undef_method, :not_exist }.should raise_error(NameError, /undefined method [`']not_exist' for class [`']#{klass}'/) { |e| # a NameError and not a NoMethodError e.class.should == NameError } @@ -69,8 +69,8 @@ def another_method_to_undef() 1 end obj = klass.new sclass = obj.singleton_class - -> { sclass.send :undef_method, :not_exist }.should raise_error(NameError, /undefined method `not_exist' for class `#{sclass}'/) { |e| - e.message.should include('`# { sclass.send :undef_method, :not_exist }.should raise_error(NameError, /undefined method [`']not_exist' for class [`']#{sclass}'/) { |e| + e.message.should =~ /[`']# { klass.send :undef_method, :not_exist }.should raise_error(NameError, /undefined method `not_exist' for class `String'/) { |e| + -> { klass.send :undef_method, :not_exist }.should raise_error(NameError, /undefined method [`']not_exist' for class [`']String'/) { |e| # a NameError and not a NoMethodError e.class.should == NameError } diff --git a/spec/ruby/core/objectspace/weakkeymap/element_set_spec.rb b/spec/ruby/core/objectspace/weakkeymap/element_set_spec.rb index 689509d8203..c427e01ca5a 100644 --- a/spec/ruby/core/objectspace/weakkeymap/element_set_spec.rb +++ b/spec/ruby/core/objectspace/weakkeymap/element_set_spec.rb @@ -24,7 +24,7 @@ def should_not_accept(map, key, value) it "requires the keys to implement #hash" do map = ObjectSpace::WeakKeyMap.new - -> { map[BasicObject.new] = 1 }.should raise_error(NoMethodError, "undefined method `hash' for an instance of BasicObject") + -> { map[BasicObject.new] = 1 }.should raise_error(NoMethodError, /undefined method [`']hash' for an instance of BasicObject/) end it "accepts frozen keys or values" do diff --git a/spec/ruby/core/proc/clone_spec.rb b/spec/ruby/core/proc/clone_spec.rb index a1a12926547..7eca9c561e2 100644 --- a/spec/ruby/core/proc/clone_spec.rb +++ b/spec/ruby/core/proc/clone_spec.rb @@ -3,4 +3,13 @@ describe "Proc#clone" do it_behaves_like :proc_dup, :clone + + ruby_bug "cloning a frozen proc is broken on Ruby 3.3", "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 end diff --git a/spec/ruby/core/proc/dup_spec.rb b/spec/ruby/core/proc/dup_spec.rb index 6da2f3080c8..dd19b3c1e97 100644 --- a/spec/ruby/core/proc/dup_spec.rb +++ b/spec/ruby/core/proc/dup_spec.rb @@ -3,4 +3,11 @@ describe "Proc#dup" do 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 end diff --git a/spec/ruby/core/proc/parameters_spec.rb b/spec/ruby/core/proc/parameters_spec.rb index 6c21784ab65..972596d2ea8 100644 --- a/spec/ruby/core/proc/parameters_spec.rb +++ b/spec/ruby/core/proc/parameters_spec.rb @@ -33,6 +33,16 @@ 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 end it "regards optional keyword parameters in procs as optional" do @@ -160,4 +170,8 @@ [:block, :_] ] end + + it "returns :nokey for **nil parameter" do + proc { |**nil| }.parameters.should == [[:nokey]] + end end diff --git a/spec/ruby/core/proc/shared/dup.rb b/spec/ruby/core/proc/shared/dup.rb index 4480f3d0c98..c419a4078af 100644 --- a/spec/ruby/core/proc/shared/dup.rb +++ b/spec/ruby/core/proc/shared/dup.rb @@ -15,4 +15,27 @@ cl.new{}.send(@method).class.should == cl end 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/rational/coerce_spec.rb b/spec/ruby/core/rational/coerce_spec.rb deleted file mode 100644 index 7aea31aea9e..00000000000 --- a/spec/ruby/core/rational/coerce_spec.rb +++ /dev/null @@ -1,7 +0,0 @@ -require_relative "../../spec_helper" - -require_relative '../../shared/rational/coerce' - -describe "Rational#coerce" do - it_behaves_like :rational_coerce, :coerce -end diff --git a/spec/ruby/core/refinement/import_methods_spec.rb b/spec/ruby/core/refinement/import_methods_spec.rb index 05973b2380b..614c54dff8c 100644 --- a/spec/ruby/core/refinement/import_methods_spec.rb +++ b/spec/ruby/core/refinement/import_methods_spec.rb @@ -128,7 +128,7 @@ def indent(level) using self -> { "foo".indent(3) - }.should raise_error(NoMethodError, /undefined method `indent' for ("foo":String|an instance of String)/) + }.should raise_error(NoMethodError, /undefined method [`']indent' for ("foo":String|an instance of String)/) end end @@ -214,7 +214,7 @@ def self.indent(level) using self -> { String.indent(3) - }.should raise_error(NoMethodError, /undefined method `indent' for (String:Class|class String)/) + }.should raise_error(NoMethodError, /undefined method [`']indent' for (String:Class|class String)/) end end diff --git a/spec/ruby/core/signal/trap_spec.rb b/spec/ruby/core/signal/trap_spec.rb index e238da3ca29..6d654a99be6 100644 --- a/spec/ruby/core/signal/trap_spec.rb +++ b/spec/ruby/core/signal/trap_spec.rb @@ -242,8 +242,8 @@ it "raises ArgumentError when passed unknown signal" do -> { Signal.trap(300) { } }.should raise_error(ArgumentError, "invalid signal number (300)") - -> { Signal.trap("USR10") { } }.should raise_error(ArgumentError, "unsupported signal `SIGUSR10'") - -> { Signal.trap("SIGUSR10") { } }.should raise_error(ArgumentError, "unsupported signal `SIGUSR10'") + -> { Signal.trap("USR10") { } }.should raise_error(ArgumentError, /\Aunsupported signal [`']SIGUSR10'\z/) + -> { Signal.trap("SIGUSR10") { } }.should raise_error(ArgumentError, /\Aunsupported signal [`']SIGUSR10'\z/) end it "raises ArgumentError when passed signal is not Integer, String or Symbol" do diff --git a/spec/ruby/core/symbol/to_proc_spec.rb b/spec/ruby/core/symbol/to_proc_spec.rb index 2cd013696ad..54eccdba11e 100644 --- a/spec/ruby/core/symbol/to_proc_spec.rb +++ b/spec/ruby/core/symbol/to_proc_spec.rb @@ -39,8 +39,8 @@ @a = [] singleton_class.class_eval(&body) tap(&:pub) - proc{tap(&:pro)}.should raise_error(NoMethodError, /protected method `pro' called/) - proc{tap(&:pri)}.should raise_error(NoMethodError, /private method `pri' called/) + proc{tap(&:pro)}.should raise_error(NoMethodError, /protected method [`']pro' called/) + proc{tap(&:pri)}.should raise_error(NoMethodError, /private method [`']pri' called/) @a.should == [:pub] @a = [] @@ -48,8 +48,8 @@ o = c.new o.instance_variable_set(:@a, []) o.tap(&:pub) - proc{tap(&:pro)}.should raise_error(NoMethodError, /protected method `pro' called/) - proc{o.tap(&:pri)}.should raise_error(NoMethodError, /private method `pri' called/) + proc{tap(&:pro)}.should raise_error(NoMethodError, /protected method [`']pro' called/) + proc{o.tap(&:pri)}.should raise_error(NoMethodError, /private method [`']pri' called/) o.a.should == [:pub] end 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 e35e1fc0b4d..6e381e48689 100644 --- a/spec/ruby/core/thread/backtrace/location/absolute_path_spec.rb +++ b/spec/ruby/core/thread/backtrace/location/absolute_path_spec.rb @@ -59,7 +59,7 @@ it "returns nil" do location = nil tap { location = caller_locations(1, 1)[0] } - location.label.should == "tap" + location.label.should =~ /\A(?:Kernel#)?tap\z/ if location.path.start_with?(" { go = true Thread.pass while t.alive? - }.should output("", <' -ERR + }.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'\n +\z/x) -> { t.join diff --git a/spec/ruby/core/time/at_spec.rb b/spec/ruby/core/time/at_spec.rb index 25056f20115..7fec8ad548b 100644 --- a/spec/ruby/core/time/at_spec.rb +++ b/spec/ruby/core/time/at_spec.rb @@ -32,15 +32,6 @@ t2.nsec.should == t.nsec end - ruby_version_is ""..."3.4" do - describe "passed BigDecimal" do - it "doesn't round input value" do - require 'bigdecimal' - Time.at(BigDecimal('1.1')).to_f.should == 1.1 - end - end - end - describe "passed Rational" do it "returns Time with correct microseconds" do t = Time.at(Rational(1_486_570_508_539_759, 1_000_000)) diff --git a/spec/ruby/core/time/new_spec.rb b/spec/ruby/core/time/new_spec.rb index 18d73962692..d686355270c 100644 --- a/spec/ruby/core/time/new_spec.rb +++ b/spec/ruby/core/time/new_spec.rb @@ -358,7 +358,7 @@ def zone.local_to_utc(t) -> { Marshal.dump(time) - }.should raise_error(NoMethodError, /undefined method `name' for/) + }.should raise_error(NoMethodError, /undefined method [`']name' for/) end end @@ -559,15 +559,15 @@ def obj.to_int; 3; end -> { Time.new("2020-012-25 00:56:17 +0900") - }.should raise_error(ArgumentError, "two digits mon is expected after `-': -012-25 00:") + }.should raise_error(ArgumentError, /\Atwo digits mon is expected after [`']-': -012-25 00:\z/) -> { Time.new("2020-2-25 00:56:17 +0900") - }.should raise_error(ArgumentError, "two digits mon is expected after `-': -2-25 00:56") + }.should raise_error(ArgumentError, /\Atwo digits mon is expected after [`']-': -2-25 00:56\z/) -> { Time.new("2020-12-215 00:56:17 +0900") - }.should raise_error(ArgumentError, "two digits mday is expected after `-': -215 00:56:") + }.should raise_error(ArgumentError, /\Atwo digits mday is expected after [`']-': -215 00:56:\z/) -> { Time.new("2020-12-25 000:56:17 +0900") @@ -579,19 +579,19 @@ def obj.to_int; 3; end -> { Time.new("2020-12-25 00:516:17 +0900") - }.should raise_error(ArgumentError, "two digits min is expected after `:': :516:17 +09") + }.should raise_error(ArgumentError, /\Atwo digits min is expected after [`']:': :516:17 \+09\z/) -> { Time.new("2020-12-25 00:6:17 +0900") - }.should raise_error(ArgumentError, "two digits min is expected after `:': :6:17 +0900") + }.should raise_error(ArgumentError, /\Atwo digits min is expected after [`']:': :6:17 \+0900\z/) -> { Time.new("2020-12-25 00:56:137 +0900") - }.should raise_error(ArgumentError, "two digits sec is expected after `:': :137 +0900") + }.should raise_error(ArgumentError, /\Atwo digits sec is expected after [`']:': :137 \+0900\z/) -> { Time.new("2020-12-25 00:56:7 +0900") - }.should raise_error(ArgumentError, "two digits sec is expected after `:': :7 +0900") + }.should raise_error(ArgumentError, /\Atwo digits sec is expected after [`']:': :7 \+0900\z/) -> { Time.new("2020-12-25 00:56. +0900") diff --git a/spec/ruby/core/tracepoint/inspect_spec.rb b/spec/ruby/core/tracepoint/inspect_spec.rb index 21d62e9e267..cc6bf0f8423 100644 --- a/spec/ruby/core/tracepoint/inspect_spec.rb +++ b/spec/ruby/core/tracepoint/inspect_spec.rb @@ -44,7 +44,7 @@ def trace_point_spec_test_call; end trace_point_spec_test_call end - inspect.should == "#" + inspect.should =~ /\A#\z/ end it 'returns a String showing the event, method, path and line for a :return event' do @@ -62,7 +62,7 @@ def trace_point_spec_test_return trace_point_spec_test_return end - inspect.should == "#" + inspect.should =~ /\A#\z/ end it 'returns a String showing the event, method, path and line for a :c_call event' do @@ -76,7 +76,7 @@ def trace_point_spec_test_return [0, 1].max end - inspect.should == "#" + inspect.should =~ /\A#\z/ end it 'returns a String showing the event, path and line for a :class event' do diff --git a/spec/ruby/core/unboundmethod/clone_spec.rb b/spec/ruby/core/unboundmethod/clone_spec.rb index 098ee61476b..1e7fb18744e 100644 --- a/spec/ruby/core/unboundmethod/clone_spec.rb +++ b/spec/ruby/core/unboundmethod/clone_spec.rb @@ -1,12 +1,13 @@ require_relative '../../spec_helper' -require_relative 'fixtures/classes' +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 00000000000..5a78dd8e369 --- /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/shared/dup.rb b/spec/ruby/core/unboundmethod/shared/dup.rb new file mode 100644 index 00000000000..943a7faaa39 --- /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/language/hash_spec.rb b/spec/ruby/language/hash_spec.rb index 6ac382c42cd..60e357fe616 100644 --- a/spec/ruby/language/hash_spec.rb +++ b/spec/ruby/language/hash_spec.rb @@ -191,20 +191,22 @@ def h.to_hash; {:b => 2, :c => 3}; end usascii_hash.keys.first.encoding.should == Encoding::US_ASCII end - it "raises an EncodingError at parse time when Symbol key with invalid bytes" do - ScratchPad.record [] - -> { - eval 'ScratchPad << 1; {:"\xC3" => 1}' - }.should raise_error(EncodingError, 'invalid symbol in encoding UTF-8 :"\xC3"') - ScratchPad.recorded.should == [] - 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_error(SyntaxError, /invalid symbol/) + ScratchPad.recorded.should == [] + end - it "raises an EncodingError at parse time when Symbol key with invalid bytes and 'key: value' syntax used" do - ScratchPad.record [] - -> { - eval 'ScratchPad << 1; {"\xC3": 1}' - }.should raise_error(EncodingError, 'invalid symbol in encoding UTF-8 :"\xC3"') - ScratchPad.recorded.should == [] + 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_error(SyntaxError, /invalid symbol/) + ScratchPad.recorded.should == [] + end end end diff --git a/spec/ruby/language/numbered_parameters_spec.rb b/spec/ruby/language/numbered_parameters_spec.rb index 3a35cf14656..06f9948c58b 100644 --- a/spec/ruby/language/numbered_parameters_spec.rb +++ b/spec/ruby/language/numbered_parameters_spec.rb @@ -22,7 +22,7 @@ it "does not support more than 9 parameters" do -> { proc { [_10] }.call(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) - }.should raise_error(NameError, /undefined local variable or method `_10'/) + }.should raise_error(NameError, /undefined local variable or method [`']_10'/) end it "can not be used in both outer and nested blocks at the same time" do diff --git a/spec/ruby/language/predefined_spec.rb b/spec/ruby/language/predefined_spec.rb index fe865cc3252..ed823f185af 100644 --- a/spec/ruby/language/predefined_spec.rb +++ b/spec/ruby/language/predefined_spec.rb @@ -687,7 +687,7 @@ def foo end it "warns if assigned non-nil" do - -> { $, = "_" }.should complain(/warning: `\$,' is deprecated/) + -> { $, = "_" }.should complain(/warning: [`']\$,' is deprecated/) end end @@ -724,7 +724,7 @@ def foo end it "warns if assigned non-nil" do - -> { $; = "_" }.should complain(/warning: `\$;' is deprecated/) + -> { $; = "_" }.should complain(/warning: [`']\$;' is deprecated/) end end diff --git a/spec/ruby/language/rescue_spec.rb b/spec/ruby/language/rescue_spec.rb index 69ed038fda9..d6e7b6c8024 100644 --- a/spec/ruby/language/rescue_spec.rb +++ b/spec/ruby/language/rescue_spec.rb @@ -263,7 +263,7 @@ class << Object.new rescue ArgumentError end rescue StandardError => e - e.backtrace.first.should include ":in `raise_standard_error'" + e.backtrace.first.should =~ /:in [`'](?:RescueSpecs\.)?raise_standard_error'/ else fail("exception wasn't handled by the correct rescue block") end diff --git a/spec/ruby/language/symbol_spec.rb b/spec/ruby/language/symbol_spec.rb index 7c1898efc25..0801d3223ec 100644 --- a/spec/ruby/language/symbol_spec.rb +++ b/spec/ruby/language/symbol_spec.rb @@ -96,11 +96,13 @@ %I{a b #{"c"}}.should == [:a, :b, :c] end - it "raises an EncodingError at parse time when Symbol with invalid bytes" do - ScratchPad.record [] - -> { - eval 'ScratchPad << 1; :"\xC3"' - }.should raise_error(EncodingError, 'invalid symbol in encoding UTF-8 :"\xC3"') - 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_error(SyntaxError, /invalid symbol/) + ScratchPad.recorded.should == [] + end end end diff --git a/spec/ruby/language/variables_spec.rb b/spec/ruby/language/variables_spec.rb index 53d191b4566..01be61a9dcd 100644 --- a/spec/ruby/language/variables_spec.rb +++ b/spec/ruby/language/variables_spec.rb @@ -930,7 +930,7 @@ def obj.foobar; @a ||= 42; end 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) + -> { obj.foobar }.should complain(/warning: global variable [`']\$specs_uninitialized_global_variable' not initialized/, verbose: true) end it "doesn't warn at lazy initialization" do diff --git a/spec/ruby/library/abbrev/abbrev_spec.rb b/spec/ruby/library/abbrev/abbrev_spec.rb index 79045a08045..61b09265977 100644 --- a/spec/ruby/library/abbrev/abbrev_spec.rb +++ b/spec/ruby/library/abbrev/abbrev_spec.rb @@ -1,34 +1,31 @@ require_relative '../../spec_helper' +require 'abbrev' -ruby_version_is ""..."3.4" do - require 'abbrev' +#test both Abbrev.abbrev and Array#abbrev in +#the same manner, as they're more or less aliases +#of one another - #test both Abbrev.abbrev and Array#abbrev in - #the same manner, as they're more or less aliases - #of one another +[["Abbrev.abbrev", -> a { Abbrev.abbrev(a)}], + ["Array#abbrev", -> a { a.abbrev}] +].each do |(name, func)| - [["Abbrev.abbrev", -> a { Abbrev.abbrev(a)}], - ["Array#abbrev", -> a { a.abbrev}] - ].each do |(name, func)| + describe name do + it "returns a hash of all unambiguous abbreviations of the array of strings passed in" do + func.call(['ruby', 'rules']).should == {"rub" => "ruby", + "ruby" => "ruby", + "rul" => "rules", + "rule" => "rules", + "rules" => "rules"} - describe name do - it "returns a hash of all unambiguous abbreviations of the array of strings passed in" do - func.call(['ruby', 'rules']).should == {"rub" => "ruby", - "ruby" => "ruby", - "rul" => "rules", - "rule" => "rules", - "rules" => "rules"} - - func.call(["car", "cone"]).should == {"ca" => "car", - "car" => "car", - "co" => "cone", - "con" => "cone", - "cone" => "cone"} - end + func.call(["car", "cone"]).should == {"ca" => "car", + "car" => "car", + "co" => "cone", + "con" => "cone", + "cone" => "cone"} + end - it "returns an empty hash when called on an empty array" do - func.call([]).should == {} - end + it "returns an empty hash when called on an empty array" do + func.call([]).should == {} end end end diff --git a/spec/ruby/library/base64/decode64_spec.rb b/spec/ruby/library/base64/decode64_spec.rb index c587c82d28f..6dd33dddfe2 100644 --- a/spec/ruby/library/base64/decode64_spec.rb +++ b/spec/ruby/library/base64/decode64_spec.rb @@ -1,32 +1,29 @@ require_relative '../../spec_helper' -ruby_version_is ""..."3.4" do +require 'base64' - require 'base64' - - describe "Base64#decode64" do - it "returns the Base64-decoded version of the given string" do - Base64.decode64("U2VuZCByZWluZm9yY2VtZW50cw==\n").should == "Send reinforcements" - end +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 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 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 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 "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 + 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 e31c6604f0a..64de6257bc8 100644 --- a/spec/ruby/library/base64/encode64_spec.rb +++ b/spec/ruby/library/base64/encode64_spec.rb @@ -1,26 +1,23 @@ require_relative '../../spec_helper' -ruby_version_is ""..."3.4" do +require 'base64' - require 'base64' - - describe "Base64#encode64" do - it "returns the Base64-encoded version of the given string" do - Base64.encode64("Now is the time for all good coders\nto learn Ruby").should == - "Tm93IGlzIHRoZSB0aW1lIGZvciBhbGwgZ29vZCBjb2RlcnMKdG8gbGVhcm4g\nUnVieQ==\n" - end +describe "Base64#encode64" do + it "returns the Base64-encoded version of the given string" do + Base64.encode64("Now is the time for all good coders\nto learn Ruby").should == + "Tm93IGlzIHRoZSB0aW1lIGZvciBhbGwgZ29vZCBjb2RlcnMKdG8gbGVhcm4g\nUnVieQ==\n" + end - 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 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 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 + 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 index f4dd3a60fe9..d258223c827 100644 --- a/spec/ruby/library/base64/strict_decode64_spec.rb +++ b/spec/ruby/library/base64/strict_decode64_spec.rb @@ -1,44 +1,41 @@ require_relative '../../spec_helper' -ruby_version_is ""..."3.4" do - - 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_error(ArgumentError) - end - - it "raises ArgumentError when the given string contains LF" do - -> do - Base64.strict_decode64("U2VuZCByZWluZm9yY2VtZW50cw==\n") - end.should raise_error(ArgumentError) - end - - it "raises ArgumentError when the given string has wrong padding" do - -> do - Base64.strict_decode64("=U2VuZCByZWluZm9yY2VtZW50cw==") - end.should raise_error(ArgumentError) - end - - it "raises ArgumentError when the given string contains an invalid character" do - -> do - Base64.strict_decode64("%3D") - end.should raise_error(ArgumentError) - end - - it "returns a binary encoded string" do - Base64.strict_decode64("SEk=").encoding.should == Encoding::BINARY - end +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_error(ArgumentError) + end + + it "raises ArgumentError when the given string contains LF" do + -> do + Base64.strict_decode64("U2VuZCByZWluZm9yY2VtZW50cw==\n") + end.should raise_error(ArgumentError) + end + + it "raises ArgumentError when the given string has wrong padding" do + -> do + Base64.strict_decode64("=U2VuZCByZWluZm9yY2VtZW50cw==") + end.should raise_error(ArgumentError) + end + + it "raises ArgumentError when the given string contains an invalid character" do + -> do + Base64.strict_decode64("%3D") + end.should raise_error(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 index c7f9f12a969..7cabcf190cc 100644 --- a/spec/ruby/library/base64/strict_encode64_spec.rb +++ b/spec/ruby/library/base64/strict_encode64_spec.rb @@ -1,22 +1,19 @@ require_relative '../../spec_helper' -ruby_version_is ""..."3.4" do +require 'base64' - 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 +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 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 + 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 f9a46787f71..1b813ee1b94 100644 --- a/spec/ruby/library/base64/urlsafe_decode64_spec.rb +++ b/spec/ruby/library/base64/urlsafe_decode64_spec.rb @@ -1,22 +1,19 @@ require_relative '../../spec_helper' -ruby_version_is ""..."3.4" do +require 'base64' - require 'base64' - - describe "Base64#urlsafe_decode64" do - it "uses '_' instead of '/'" do - decoded = Base64.urlsafe_decode64("V2hlcmUgYW0gST8gV2hvIGFtIEk_IEFtIEk_IEk_") - decoded.should == 'Where am I? Who am I? Am I? I?' - end +describe "Base64#urlsafe_decode64" do + it "uses '_' instead of '/'" do + decoded = Base64.urlsafe_decode64("V2hlcmUgYW0gST8gV2hvIGFtIEk_IEFtIEk_IEk_") + decoded.should == 'Where am I? Who am I? Am I? I?' + end - it "uses '-' instead of '+'" do - decoded = Base64.urlsafe_decode64('IkJlaW5nIGRpc2ludGVncmF0ZWQgbWFrZXMgbWUgdmUtcnkgYW4tZ3J5ISIgPGh1ZmYsIGh1ZmY-') - decoded.should == '"Being disintegrated makes me ve-ry an-gry!" ' - end + it "uses '-' instead of '+'" do + decoded = Base64.urlsafe_decode64('IkJlaW5nIGRpc2ludGVncmF0ZWQgbWFrZXMgbWUgdmUtcnkgYW4tZ3J5ISIgPGh1ZmYsIGh1ZmY-') + decoded.should == '"Being disintegrated makes me ve-ry an-gry!" ' + end - 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 0c7b08757ee..de1f235ceab 100644 --- a/spec/ruby/library/base64/urlsafe_encode64_spec.rb +++ b/spec/ruby/library/base64/urlsafe_encode64_spec.rb @@ -1,23 +1,20 @@ require_relative '../../spec_helper' -ruby_version_is ""..."3.4" do +require 'base64' - require 'base64' - - describe "Base64#urlsafe_encode64" do - it "uses '_' instead of '/'" do - encoded = Base64.urlsafe_encode64('Where am I? Who am I? Am I? I?') - encoded.should == "V2hlcmUgYW0gST8gV2hvIGFtIEk_IEFtIEk_IEk_" - end +describe "Base64#urlsafe_encode64" do + it "uses '_' instead of '/'" do + encoded = Base64.urlsafe_encode64('Where am I? Who am I? Am I? I?') + encoded.should == "V2hlcmUgYW0gST8gV2hvIGFtIEk_IEFtIEk_IEk_" + end - it "uses '-' instead of '+'" do - encoded = Base64.urlsafe_encode64('"Being disintegrated makes me ve-ry an-gry!" ') - encoded.should == 'IkJlaW5nIGRpc2ludGVncmF0ZWQgbWFrZXMgbWUgdmUtcnkgYW4tZ3J5ISIgPGh1ZmYsIGh1ZmY-' - end + it "uses '-' instead of '+'" do + encoded = Base64.urlsafe_encode64('"Being disintegrated makes me ve-ry an-gry!" ') + encoded.should == 'IkJlaW5nIGRpc2ludGVncmF0ZWQgbWFrZXMgbWUgdmUtcnkgYW4tZ3J5ISIgPGh1ZmYsIGh1ZmY-' + end - 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 index d6e119b36ea..43a779b420e 100644 --- a/spec/ruby/library/bigdecimal/BigDecimal_spec.rb +++ b/spec/ruby/library/bigdecimal/BigDecimal_spec.rb @@ -1,272 +1,269 @@ require_relative '../../spec_helper' +require 'bigdecimal' -ruby_version_is ""..."3.4" do - 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 "BigDecimal" do - it "is not defined unless it is required" do - ruby_exe('puts Object.const_defined?(:BigDecimal)').should == "false\n" - end +describe "Kernel#BigDecimal" do + + it "creates a new object of class BigDecimal" do + BigDecimal("3.14159").should be_kind_of(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 - describe "Kernel#BigDecimal" do - - it "creates a new object of class BigDecimal" do - BigDecimal("3.14159").should be_kind_of(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 "BigDecimal(Rational) with bigger-than-double numerator" do - rational = 99999999999999999999/100r - rational.numerator.should > 2**64 - BigDecimal(rational, 100).to_s.should == "0.99999999999999999999e18" + it "accepts significant digits >= given precision" do + suppress_warning do + BigDecimal("3.1415923", 10).precs[1].should >= 10 end + end - it "accepts significant digits >= given precision" do - suppress_warning do - BigDecimal("3.1415923", 10).precs[1].should >= 10 - end - end + it "determines precision from initial value" do + pi_string = "3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593014782083152134043" + suppress_warning { + BigDecimal(pi_string).precs[1] + }.should >= pi_string.size-1 + end - it "determines precision from initial value" do - pi_string = "3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593014782083152134043" - suppress_warning { - BigDecimal(pi_string).precs[1] - }.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 "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 "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_error(ArgumentError) + -> { BigDecimal("123x45") }.should raise_error(ArgumentError) + -> { BigDecimal("123.4%E5") }.should raise_error(ArgumentError) + -> { BigDecimal("1E2E3E4E5E") }.should raise_error(ArgumentError) + end - it "does not ignores trailing garbage" do - -> { BigDecimal("123E45ruby") }.should raise_error(ArgumentError) - -> { BigDecimal("123x45") }.should raise_error(ArgumentError) - -> { BigDecimal("123.4%E5") }.should raise_error(ArgumentError) - -> { BigDecimal("1E2E3E4E5E") }.should raise_error(ArgumentError) - end + it "raises ArgumentError for invalid strings" do + -> { BigDecimal("ruby") }.should raise_error(ArgumentError) + -> { BigDecimal(" \t\n \r-\t\t\tInfinity \n") }.should raise_error(ArgumentError) + end - it "raises ArgumentError for invalid strings" do - -> { BigDecimal("ruby") }.should raise_error(ArgumentError) - -> { BigDecimal(" \t\n \r-\t\t\tInfinity \n") }.should raise_error(ArgumentError) - end + it "allows omitting the integer part" do + BigDecimal(".123").should == BigDecimal("0.123") + 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_error(ArgumentError) + -> { BigDecimal("12345_.67E_8__9_") }.should raise_error(ArgumentError) + end + + it "accepts NaN and [+-]Infinity" do + BigDecimal("NaN").should.nan? - it "process underscores as Float()" do - reference = BigDecimal("12345.67E89") + pos_inf = BigDecimal("Infinity") + pos_inf.should_not.finite? + pos_inf.should > 0 + pos_inf.should == BigDecimal("+Infinity") - BigDecimal("12_345.67E89").should == reference - -> { BigDecimal("1_2_3_4_5_._6____7_E89") }.should raise_error(ArgumentError) - -> { BigDecimal("12345_.67E_8__9_") }.should raise_error(ArgumentError) + 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 be_nil + BigDecimal("0invalid", exception: false).should be_nil + BigDecimal("invalid0", exception: false).should be_nil + BigDecimal("0.", exception: false).should be_nil end + end - it "accepts NaN and [+-]Infinity" do - BigDecimal("NaN").should.nan? + describe "accepts NaN and [+-]Infinity as Float values" do + it "works without an explicit precision" do + BigDecimal(Float::NAN).should.nan? - pos_inf = BigDecimal("Infinity") + pos_inf = BigDecimal(Float::INFINITY) pos_inf.should_not.finite? pos_inf.should > 0 pos_inf.should == BigDecimal("+Infinity") - neg_inf = BigDecimal("-Infinity") + neg_inf = BigDecimal(-Float::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 be_nil - BigDecimal("0invalid", exception: false).should be_nil - BigDecimal("invalid0", exception: false).should be_nil - BigDecimal("0.", exception: false).should be_nil - 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") - describe "accepts NaN and [+-]Infinity as Float values" do - it "works without an explicit precision" do - BigDecimal(Float::NAN).should.nan? + BigDecimal("12345.67e89").should == reference + BigDecimal("12345.67E89").should == reference + BigDecimal("12345.67d89").should == reference + BigDecimal("12345.67D89").should == reference + end - pos_inf = BigDecimal(Float::INFINITY) - pos_inf.should_not.finite? - pos_inf.should > 0 - pos_inf.should == BigDecimal("+Infinity") + 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 - neg_inf = BigDecimal(-Float::INFINITY) - neg_inf.should_not.finite? - neg_inf.should < 0 - end + it "raises ArgumentError when Float is used without precision" do + -> { BigDecimal(1.0) }.should raise_error(ArgumentError) + end - it "works with an explicit precision" do - BigDecimal(Float::NAN, Float::DIG).should.nan? + 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 - pos_inf = BigDecimal(Float::INFINITY, Float::DIG) - pos_inf.should_not.finite? - pos_inf.should > 0 - pos_inf.should == BigDecimal("+Infinity") + 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' - neg_inf = BigDecimal(-Float::INFINITY, Float::DIG) - neg_inf.should_not.finite? - neg_inf.should < 0 + 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 - it "allows for [eEdD] as exponent separator" do - reference = BigDecimal("12345.67E89") + # Check the input is as we understand it - BigDecimal("12345.67e89").should == reference - BigDecimal("12345.67E89").should == reference - BigDecimal("12345.67d89").should == reference - BigDecimal("12345.67D89").should == reference + 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 "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 + 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 "raises ArgumentError when Float is used without precision" do - -> { BigDecimal(1.0) }.should raise_error(ArgumentError) + it "has the expected precision on the LHS" do + suppress_warning { @a.precs[0] }.should == 18 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 + it "has the expected maximum precision on the LHS" do + suppress_warning { @a.precs[1] }.should == 27 end - it "pre-coerces long integers" do - BigDecimal(3).add(1 << 50, 3).should == BigDecimal('0.113e16') + it "produces the expected result when done via Float" do + (Float(@a) - Float(@b)).to_s.should == "-6.666596163995564e-10" 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 + it "produces the expected result when done via to_f" do + (@a.to_f - @b.to_f).to_s.should == "-6.666596163995564e-10" 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 "has the expected precision on the LHS" do - suppress_warning { @a.precs[0] }.should == 18 - end - - it "has the expected maximum precision on the LHS" do - suppress_warning { @a.precs[1] }.should == 27 - end - - it "produces the expected result when done via Float" do - (Float(@a) - Float(@b)).to_s.should == "-6.666596163995564e-10" - end + # Check underlying methods work as we understand - 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 precision is the number of digits rounded up to a multiple of nine" do - 1.upto(100) do |n| - b = BigDecimal('4' * n) - precs, _ = suppress_warning { b.precs } - (precs >= 9).should be_true - (precs >= n).should be_true - (precs % 9).should == 0 - end - suppress_warning { BigDecimal('NaN').precs[0] }.should == 9 + it "BigDecimal precision is the number of digits rounded up to a multiple of nine" do + 1.upto(100) do |n| + b = BigDecimal('4' * n) + precs, _ = suppress_warning { b.precs } + (precs >= 9).should be_true + (precs >= n).should be_true + (precs % 9).should == 0 end + suppress_warning { BigDecimal('NaN').precs[0] }.should == 9 + end - it "BigDecimal maximum precision is nine more than precision except for abnormals" do - 1.upto(100) do |n| - b = BigDecimal('4' * n) - precs, max = suppress_warning { b.precs } - max.should == precs + 9 - end - suppress_warning { BigDecimal('NaN').precs[1] }.should == 9 + it "BigDecimal maximum precision is nine more than precision except for abnormals" do + 1.upto(100) do |n| + b = BigDecimal('4' * n) + precs, max = suppress_warning { b.precs } + max.should == precs + 9 end + suppress_warning { BigDecimal('NaN').precs[1] }.should == 9 + end - it "BigDecimal(Rational, 18) produces the result we expect" do - BigDecimal(@b, 18).to_s.should == "0.166666666666666667e3" - end + it "BigDecimal(Rational, 18) produces the result we expect" do + BigDecimal(@b, 18).to_s.should == "0.166666666666666667e3" + end - it "BigDecimal(Rational, BigDecimal.precs[0]) produces the result we expect" do - BigDecimal(@b, suppress_warning { @a.precs[0] }).to_s.should == "0.166666666666666667e3" - end + it "BigDecimal(Rational, BigDecimal.precs[0]) produces the result we expect" do + BigDecimal(@b, suppress_warning { @a.precs[0] }).to_s.should == "0.166666666666666667e3" + end - # Check the top-level expression works as we expect + # Check the top-level expression works as we expect - it "produces a BigDecimal" do - @c.class.should == BigDecimal - end + it "produces a BigDecimal" do + @c.class.should == BigDecimal + end - it "produces the expected result" do - @c.should == BigDecimal("-0.666667e-9") - @c.to_s.should == "-0.666667e-9" - end + it "produces the expected result" do + @c.should == BigDecimal("-0.666667e-9") + @c.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 + 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 44ac0db77b9..95dc45a9058 100644 --- a/spec/ruby/library/bigdecimal/abs_spec.rb +++ b/spec/ruby/library/bigdecimal/abs_spec.rb @@ -1,53 +1,50 @@ require_relative '../../spec_helper' +require 'bigdecimal' -ruby_version_is ""..."3.4" do - require 'bigdecimal' - - describe "BigDecimal#abs" do - before :each do - @one = BigDecimal("1") - @zero = BigDecimal("0") - @zero_pos = BigDecimal("+0") - @zero_neg = BigDecimal("-0") - @two = BigDecimal("2") - @three = BigDecimal("3") - @mixed = BigDecimal("1.23456789") - @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") - end - - it "returns the absolute value" do - pos_int = BigDecimal("2E5555") - neg_int = BigDecimal("-2E5555") - pos_frac = BigDecimal("2E-9999") - neg_frac = BigDecimal("-2E-9999") +describe "BigDecimal#abs" do + before :each do + @one = BigDecimal("1") + @zero = BigDecimal("0") + @zero_pos = BigDecimal("+0") + @zero_neg = BigDecimal("-0") + @two = BigDecimal("2") + @three = BigDecimal("3") + @mixed = BigDecimal("1.23456789") + @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") + end - pos_int.abs.should == pos_int - neg_int.abs.should == pos_int - pos_frac.abs.should == pos_frac - neg_frac.abs.should == pos_frac - @one.abs.should == 1 - @two.abs.should == 2 - @three.abs.should == 3 - @mixed.abs.should == @mixed - @one_minus.abs.should == @one - end + it "returns the absolute value" do + pos_int = BigDecimal("2E5555") + neg_int = BigDecimal("-2E5555") + pos_frac = BigDecimal("2E-9999") + neg_frac = BigDecimal("-2E-9999") - it "properly handles special values" do - @infinity.abs.should == @infinity - @infinity_minus.abs.should == @infinity - @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 - @zero_pos.abs.sign.should == BigDecimal::SIGN_POSITIVE_ZERO - @zero_neg.abs.should == 0 - @zero_neg.abs.sign.should == BigDecimal::SIGN_POSITIVE_ZERO - end + pos_int.abs.should == pos_int + neg_int.abs.should == pos_int + pos_frac.abs.should == pos_frac + neg_frac.abs.should == pos_frac + @one.abs.should == 1 + @two.abs.should == 2 + @three.abs.should == 3 + @mixed.abs.should == @mixed + @one_minus.abs.should == @one + end + it "properly handles special values" do + @infinity.abs.should == @infinity + @infinity_minus.abs.should == @infinity + @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 + @zero_pos.abs.sign.should == BigDecimal::SIGN_POSITIVE_ZERO + @zero_neg.abs.should == 0 + @zero_neg.abs.sign.should == BigDecimal::SIGN_POSITIVE_ZERO end + end diff --git a/spec/ruby/library/bigdecimal/add_spec.rb b/spec/ruby/library/bigdecimal/add_spec.rb index 9fea1a02124..542713011d6 100644 --- a/spec/ruby/library/bigdecimal/add_spec.rb +++ b/spec/ruby/library/bigdecimal/add_spec.rb @@ -1,196 +1,193 @@ require_relative '../../spec_helper' +require_relative 'fixtures/classes' + +require 'bigdecimal' + +describe "BigDecimal#add" do + + before :each do + @one = BigDecimal("1") + @zero = BigDecimal("0") + @two = BigDecimal("2") + @three = BigDecimal("3") + @ten = BigDecimal("10") + @eleven = BigDecimal("11") + @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") + @dot_ones = BigDecimal("0.1111111111") + end -ruby_version_is ""..."3.4" do - require_relative 'fixtures/classes' - - require 'bigdecimal' - - describe "BigDecimal#add" do - - before :each do - @one = BigDecimal("1") - @zero = BigDecimal("0") - @two = BigDecimal("2") - @three = BigDecimal("3") - @ten = BigDecimal("10") - @eleven = BigDecimal("11") - @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") - @dot_ones = BigDecimal("0.1111111111") - end + it "returns a + b with given precision" do + # 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 + @ten.add(@one, 2).should == @eleven + @zero.add(@one, 1).should == @one + @frac_2.add(@frac_1, 10000).should == BigDecimal("1.9E-99999") + @frac_1.add(@frac_1, 10000).should == BigDecimal("2E-99999") + @frac_3.add(@frac_4, 0).should == BigDecimal("0.11111E16") + @frac_3.add(@frac_4, 1).should == BigDecimal("0.1E16") + @frac_3.add(@frac_4, 2).should == BigDecimal("0.11E16") + @frac_3.add(@frac_4, 3).should == BigDecimal("0.111E16") + @frac_3.add(@frac_4, 4).should == BigDecimal("0.1111E16") + @frac_3.add(@frac_4, 5).should == BigDecimal("0.11111E16") + @frac_3.add(@frac_4, 6).should == BigDecimal("0.11111E16") + end - it "returns a + b with given precision" do - # 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 - @ten.add(@one, 2).should == @eleven - @zero.add(@one, 1).should == @one - @frac_2.add(@frac_1, 10000).should == BigDecimal("1.9E-99999") - @frac_1.add(@frac_1, 10000).should == BigDecimal("2E-99999") - @frac_3.add(@frac_4, 0).should == BigDecimal("0.11111E16") - @frac_3.add(@frac_4, 1).should == BigDecimal("0.1E16") - @frac_3.add(@frac_4, 2).should == BigDecimal("0.11E16") - @frac_3.add(@frac_4, 3).should == BigDecimal("0.111E16") - @frac_3.add(@frac_4, 4).should == BigDecimal("0.1111E16") - @frac_3.add(@frac_4, 5).should == BigDecimal("0.11111E16") - @frac_3.add(@frac_4, 6).should == BigDecimal("0.11111E16") - end + it "returns a + [Fixnum value] with given precision" do + (1..10).each {|precision| + @dot_ones.add(0, precision).should == BigDecimal("0." + "1" * precision) + } + BigDecimal("0.88").add(0, 1).should == BigDecimal("0.9") + end - it "returns a + [Fixnum value] with given precision" do - (1..10).each {|precision| - @dot_ones.add(0, precision).should == BigDecimal("0." + "1" * precision) - } - BigDecimal("0.88").add(0, 1).should == BigDecimal("0.9") - end + it "returns a + [Bignum value] with given precision" do + bignum = 10000000000000000000 + (1..20).each {|precision| + @dot_ones.add(bignum, precision).should == BigDecimal("0.1E20") + } + (21..30).each {|precision| + @dot_ones.add(bignum, precision).should == BigDecimal( + "0.10000000000000000000" + "1" * (precision - 20) + "E20") + } + end - it "returns a + [Bignum value] with given precision" do - bignum = 10000000000000000000 - (1..20).each {|precision| - @dot_ones.add(bignum, precision).should == BigDecimal("0.1E20") - } - (21..30).each {|precision| - @dot_ones.add(bignum, precision).should == BigDecimal( - "0.10000000000000000000" + "1" * (precision - 20) + "E20") - } +# TODO: +# 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) +# +# it "returns a + [Float value] with given precision" do +# (1..10).each {|precision| +# @dot_ones.add(0.0, precision).should == BigDecimal("0." + "1" * precision) +# } +# +# BigDecimal("0.88").add(0.0, 1).should == BigDecimal("0.9") +# end + + describe "with Object" do + it "tries to coerce the other operand to self" do + object = mock("Object") + object.should_receive(:coerce).with(@frac_3).and_return([@frac_3, @frac_4]) + @frac_3.add(object, 1).should == BigDecimal("0.1E16") end + end - # TODO: - # 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) - # - # it "returns a + [Float value] with given precision" do - # (1..10).each {|precision| - # @dot_ones.add(0.0, precision).should == BigDecimal("0." + "1" * precision) - # } - # - # BigDecimal("0.88").add(0.0, 1).should == BigDecimal("0.9") - # end - - describe "with Object" do - it "tries to coerce the other operand to self" do - object = mock("Object") - object.should_receive(:coerce).with(@frac_3).and_return([@frac_3, @frac_4]) - @frac_3.add(object, 1).should == BigDecimal("0.1E16") - end + describe "with Rational" do + it "produces a BigDecimal" do + (@three + Rational(500, 2)).should == BigDecimal("0.253e3") end + end - describe "with Rational" do - it "produces a BigDecimal" do - (@three + Rational(500, 2)).should == BigDecimal("0.253e3") - 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') 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') - end - - BigDecimalSpecs.with_limit(2) do - BigDecimal('0.888').add(@zero, 1).should == BigDecimal('0.9') - end + BigDecimalSpecs.with_limit(2) do + BigDecimal('0.888').add(@zero, 1).should == BigDecimal('0.9') end + end - it "uses the current rounding mode if rounding is needed" do - BigDecimalSpecs.with_rounding(BigDecimal::ROUND_UP) do - BigDecimal('0.111').add(@zero, 1).should == BigDecimal('0.2') - BigDecimal('-0.111').add(@zero, 1).should == BigDecimal('-0.2') - end - BigDecimalSpecs.with_rounding(BigDecimal::ROUND_DOWN) do - BigDecimal('0.999').add(@zero, 1).should == BigDecimal('0.9') - BigDecimal('-0.999').add(@zero, 1).should == BigDecimal('-0.9') - end - BigDecimalSpecs.with_rounding(BigDecimal::ROUND_HALF_UP) do - BigDecimal('0.85').add(@zero, 1).should == BigDecimal('0.9') - BigDecimal('-0.85').add(@zero, 1).should == BigDecimal('-0.9') - end - BigDecimalSpecs.with_rounding(BigDecimal::ROUND_HALF_DOWN) do - BigDecimal('0.85').add(@zero, 1).should == BigDecimal('0.8') - BigDecimal('-0.85').add(@zero, 1).should == BigDecimal('-0.8') - end - BigDecimalSpecs.with_rounding(BigDecimal::ROUND_HALF_EVEN) do - BigDecimal('0.75').add(@zero, 1).should == BigDecimal('0.8') - BigDecimal('0.85').add(@zero, 1).should == BigDecimal('0.8') - BigDecimal('-0.75').add(@zero, 1).should == BigDecimal('-0.8') - BigDecimal('-0.85').add(@zero, 1).should == BigDecimal('-0.8') - end - BigDecimalSpecs.with_rounding(BigDecimal::ROUND_CEILING) do - BigDecimal('0.85').add(@zero, 1).should == BigDecimal('0.9') - BigDecimal('-0.85').add(@zero, 1).should == BigDecimal('-0.8') - end - BigDecimalSpecs.with_rounding(BigDecimal::ROUND_FLOOR) do - BigDecimal('0.85').add(@zero, 1).should == BigDecimal('0.8') - BigDecimal('-0.85').add(@zero, 1).should == BigDecimal('-0.9') - end + it "uses the current rounding mode if rounding is needed" do + BigDecimalSpecs.with_rounding(BigDecimal::ROUND_UP) do + BigDecimal('0.111').add(@zero, 1).should == BigDecimal('0.2') + BigDecimal('-0.111').add(@zero, 1).should == BigDecimal('-0.2') end - - it "uses the default ROUND_HALF_UP rounding if it wasn't explicitly changed" do + BigDecimalSpecs.with_rounding(BigDecimal::ROUND_DOWN) do + BigDecimal('0.999').add(@zero, 1).should == BigDecimal('0.9') + BigDecimal('-0.999').add(@zero, 1).should == BigDecimal('-0.9') + end + BigDecimalSpecs.with_rounding(BigDecimal::ROUND_HALF_UP) do BigDecimal('0.85').add(@zero, 1).should == BigDecimal('0.9') BigDecimal('-0.85').add(@zero, 1).should == BigDecimal('-0.9') end - - it "returns NaN if NaN is involved" do - @one.add(@nan, 10000).should.nan? - @nan.add(@one, 1).should.nan? + BigDecimalSpecs.with_rounding(BigDecimal::ROUND_HALF_DOWN) do + BigDecimal('0.85').add(@zero, 1).should == BigDecimal('0.8') + BigDecimal('-0.85').add(@zero, 1).should == BigDecimal('-0.8') end - - it "returns Infinity or -Infinity if these are involved" do - @zero.add(@infinity, 1).should == @infinity - @frac_2.add(@infinity, 1).should == @infinity - @one_minus.add(@infinity, 1).should == @infinity - @two.add(@infinity, 1).should == @infinity - - @zero.add(@infinity_minus, 1).should == @infinity_minus - @frac_2.add(@infinity_minus, 1).should == @infinity_minus - @one_minus.add(@infinity_minus, 1).should == @infinity_minus - @two.add(@infinity_minus, 1).should == @infinity_minus - - @infinity.add(@zero, 1).should == @infinity - @infinity.add(@frac_2, 1).should == @infinity - @infinity.add(@one_minus, 1).should == @infinity - @infinity.add(@two, 1).should == @infinity - - @infinity_minus.add(@zero, 1).should == @infinity_minus - @infinity_minus.add(@frac_2, 1).should == @infinity_minus - @infinity_minus.add(@one_minus, 1).should == @infinity_minus - @infinity_minus.add(@two, 1).should == @infinity_minus - - @infinity.add(@infinity, 10000).should == @infinity - @infinity_minus.add(@infinity_minus, 10000).should == @infinity_minus + BigDecimalSpecs.with_rounding(BigDecimal::ROUND_HALF_EVEN) do + BigDecimal('0.75').add(@zero, 1).should == BigDecimal('0.8') + BigDecimal('0.85').add(@zero, 1).should == BigDecimal('0.8') + BigDecimal('-0.75').add(@zero, 1).should == BigDecimal('-0.8') + BigDecimal('-0.85').add(@zero, 1).should == BigDecimal('-0.8') end - - it "returns NaN if Infinity + (- Infinity)" do - @infinity.add(@infinity_minus, 10000).should.nan? - @infinity_minus.add(@infinity, 10000).should.nan? + BigDecimalSpecs.with_rounding(BigDecimal::ROUND_CEILING) do + BigDecimal('0.85').add(@zero, 1).should == BigDecimal('0.9') + BigDecimal('-0.85').add(@zero, 1).should == BigDecimal('-0.8') end - - it "raises TypeError when adds nil" do - -> { - @one.add(nil, 10) - }.should raise_error(TypeError) - -> { - @one.add(nil, 0) - }.should raise_error(TypeError) + BigDecimalSpecs.with_rounding(BigDecimal::ROUND_FLOOR) do + BigDecimal('0.85').add(@zero, 1).should == BigDecimal('0.8') + BigDecimal('-0.85').add(@zero, 1).should == BigDecimal('-0.9') end + end - it "raises TypeError when precision parameter is nil" do - -> { - @one.add(@one, nil) - }.should raise_error(TypeError) - end + it "uses the default ROUND_HALF_UP rounding if it wasn't explicitly changed" do + BigDecimal('0.85').add(@zero, 1).should == BigDecimal('0.9') + BigDecimal('-0.85').add(@zero, 1).should == BigDecimal('-0.9') + end - it "raises ArgumentError when precision parameter is negative" do - -> { - @one.add(@one, -10) - }.should raise_error(ArgumentError) - end + it "returns NaN if NaN is involved" do + @one.add(@nan, 10000).should.nan? + @nan.add(@one, 1).should.nan? + end + + it "returns Infinity or -Infinity if these are involved" do + @zero.add(@infinity, 1).should == @infinity + @frac_2.add(@infinity, 1).should == @infinity + @one_minus.add(@infinity, 1).should == @infinity + @two.add(@infinity, 1).should == @infinity + + @zero.add(@infinity_minus, 1).should == @infinity_minus + @frac_2.add(@infinity_minus, 1).should == @infinity_minus + @one_minus.add(@infinity_minus, 1).should == @infinity_minus + @two.add(@infinity_minus, 1).should == @infinity_minus + + @infinity.add(@zero, 1).should == @infinity + @infinity.add(@frac_2, 1).should == @infinity + @infinity.add(@one_minus, 1).should == @infinity + @infinity.add(@two, 1).should == @infinity + + @infinity_minus.add(@zero, 1).should == @infinity_minus + @infinity_minus.add(@frac_2, 1).should == @infinity_minus + @infinity_minus.add(@one_minus, 1).should == @infinity_minus + @infinity_minus.add(@two, 1).should == @infinity_minus + + @infinity.add(@infinity, 10000).should == @infinity + @infinity_minus.add(@infinity_minus, 10000).should == @infinity_minus + end + + it "returns NaN if Infinity + (- Infinity)" do + @infinity.add(@infinity_minus, 10000).should.nan? + @infinity_minus.add(@infinity, 10000).should.nan? + end + + it "raises TypeError when adds nil" do + -> { + @one.add(nil, 10) + }.should raise_error(TypeError) + -> { + @one.add(nil, 0) + }.should raise_error(TypeError) + end + + it "raises TypeError when precision parameter is nil" do + -> { + @one.add(@one, nil) + }.should raise_error(TypeError) + end + + it "raises ArgumentError when precision parameter is negative" do + -> { + @one.add(@one, -10) + }.should raise_error(ArgumentError) end end diff --git a/spec/ruby/library/bigdecimal/case_compare_spec.rb b/spec/ruby/library/bigdecimal/case_compare_spec.rb index 7803346c791..fac67143561 100644 --- a/spec/ruby/library/bigdecimal/case_compare_spec.rb +++ b/spec/ruby/library/bigdecimal/case_compare_spec.rb @@ -1,10 +1,7 @@ require_relative '../../spec_helper' +require_relative 'shared/eql' -ruby_version_is ""..."3.4" do - require_relative 'shared/eql' - - describe "BigDecimal#===" do - it_behaves_like :bigdecimal_eql, :=== - end +describe "BigDecimal#===" do + it_behaves_like :bigdecimal_eql, :=== end diff --git a/spec/ruby/library/bigdecimal/ceil_spec.rb b/spec/ruby/library/bigdecimal/ceil_spec.rb index a3b6806be50..60e71b12fb1 100644 --- a/spec/ruby/library/bigdecimal/ceil_spec.rb +++ b/spec/ruby/library/bigdecimal/ceil_spec.rb @@ -1,107 +1,104 @@ require_relative '../../spec_helper' +require 'bigdecimal' + +describe "BigDecimal#ceil" do + before :each do + @zero = BigDecimal("0") + @one = BigDecimal("1") + @three = BigDecimal("3") + @four = BigDecimal("4") + @mixed = BigDecimal("1.23456789") + @mixed_big = BigDecimal("1.23456789E100") + @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 -ruby_version_is ""..."3.4" do - require 'bigdecimal' - - describe "BigDecimal#ceil" do - before :each do - @zero = BigDecimal("0") - @one = BigDecimal("1") - @three = BigDecimal("3") - @four = BigDecimal("4") - @mixed = BigDecimal("1.23456789") - @mixed_big = BigDecimal("1.23456789E100") - @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 an Integer, if n is unspecified" do + @mixed.ceil.kind_of?(Integer).should == true + end - it "returns an Integer, if n is unspecified" do - @mixed.ceil.kind_of?(Integer).should == true - end + it "returns a BigDecimal, if n is specified" do + @pos_int.ceil(2).kind_of?(BigDecimal).should == true + end - it "returns a BigDecimal, if n is specified" do - @pos_int.ceil(2).kind_of?(BigDecimal).should == true - end + it "returns the smallest integer greater or equal to self, if n is unspecified" do + @pos_int.ceil.should == @pos_int + @neg_int.ceil.should == @neg_int + @pos_frac.ceil.should == BigDecimal("1") + @neg_frac.ceil.should == @zero + @zero.ceil.should == 0 + @zero_pos.ceil.should == @zero_pos + @zero_neg.ceil.should == @zero_neg + + + BigDecimal('2.3').ceil.should == 3 + BigDecimal('2.5').ceil.should == 3 + BigDecimal('2.9999').ceil.should == 3 + BigDecimal('-2.3').ceil.should == -2 + BigDecimal('-2.5').ceil.should == -2 + BigDecimal('-2.9999').ceil.should == -2 + end - it "returns the smallest integer greater or equal to self, if n is unspecified" do - @pos_int.ceil.should == @pos_int - @neg_int.ceil.should == @neg_int - @pos_frac.ceil.should == BigDecimal("1") - @neg_frac.ceil.should == @zero - @zero.ceil.should == 0 - @zero_pos.ceil.should == @zero_pos - @zero_neg.ceil.should == @zero_neg - - - BigDecimal('2.3').ceil.should == 3 - BigDecimal('2.5').ceil.should == 3 - BigDecimal('2.9999').ceil.should == 3 - BigDecimal('-2.3').ceil.should == -2 - BigDecimal('-2.5').ceil.should == -2 - BigDecimal('-2.9999').ceil.should == -2 - end + it "raise exception, if self is special value" do + -> { @infinity.ceil }.should raise_error(FloatDomainError) + -> { @infinity_neg.ceil }.should raise_error(FloatDomainError) + -> { @nan.ceil }.should raise_error(FloatDomainError) + end - it "raise exception, if self is special value" do - -> { @infinity.ceil }.should raise_error(FloatDomainError) - -> { @infinity_neg.ceil }.should raise_error(FloatDomainError) - -> { @nan.ceil }.should raise_error(FloatDomainError) - end + it "returns n digits right of the decimal point if given n > 0" do + @mixed.ceil(1).should == BigDecimal("1.3") + @mixed.ceil(5).should == BigDecimal("1.23457") - it "returns n digits right of the decimal point if given n > 0" do - @mixed.ceil(1).should == BigDecimal("1.3") - @mixed.ceil(5).should == BigDecimal("1.23457") - - BigDecimal("-0.03").ceil(1).should == BigDecimal("0") - BigDecimal("0.03").ceil(1).should == BigDecimal("0.1") - - BigDecimal("23.45").ceil(0).should == BigDecimal('24') - BigDecimal("23.45").ceil(1).should == BigDecimal('23.5') - BigDecimal("23.45").ceil(2).should == BigDecimal('23.45') - - BigDecimal("-23.45").ceil(0).should == BigDecimal('-23') - BigDecimal("-23.45").ceil(1).should == BigDecimal('-23.4') - BigDecimal("-23.45").ceil(2).should == BigDecimal('-23.45') - - BigDecimal("2E-10").ceil(0).should == @one - BigDecimal("2E-10").ceil(9).should == BigDecimal('1E-9') - BigDecimal("2E-10").ceil(10).should == BigDecimal('2E-10') - BigDecimal("2E-10").ceil(11).should == BigDecimal('2E-10') - - (1..10).each do |n| - # 0.4, 0.34, 0.334, etc. - (@one.div(@three,20)).ceil(n).should == BigDecimal("0.#{'3'*(n-1)}4") - # 1.4, 1.34, 1.334, etc. - (@four.div(@three,20)).ceil(n).should == BigDecimal("1.#{'3'*(n-1)}4") - (BigDecimal('31').div(@three,20)).ceil(n).should == BigDecimal("10.#{'3'*(n-1)}4") - end - (1..10).each do |n| - # -0.4, -0.34, -0.334, etc. - (-@one.div(@three,20)).ceil(n).should == BigDecimal("-0.#{'3'* n}") - end - (1..10).each do |n| - (@three.div(@one,20)).ceil(n).should == @three - end - (1..10).each do |n| - (-@three.div(@one,20)).ceil(n).should == -@three - end - end + BigDecimal("-0.03").ceil(1).should == BigDecimal("0") + BigDecimal("0.03").ceil(1).should == BigDecimal("0.1") + + BigDecimal("23.45").ceil(0).should == BigDecimal('24') + BigDecimal("23.45").ceil(1).should == BigDecimal('23.5') + BigDecimal("23.45").ceil(2).should == BigDecimal('23.45') + + BigDecimal("-23.45").ceil(0).should == BigDecimal('-23') + BigDecimal("-23.45").ceil(1).should == BigDecimal('-23.4') + BigDecimal("-23.45").ceil(2).should == BigDecimal('-23.45') - it "sets n digits left of the decimal point to 0, if given n < 0" do - BigDecimal("13345.234").ceil(-2).should == BigDecimal("13400.0") - @mixed_big.ceil(-99).should == BigDecimal("0.13E101") - @mixed_big.ceil(-100).should == BigDecimal("0.2E101") - @mixed_big.ceil(-95).should == BigDecimal("0.123457E101") - BigDecimal("1E10").ceil(-30).should == BigDecimal('1E30') - BigDecimal("-1E10").ceil(-30).should == @zero + BigDecimal("2E-10").ceil(0).should == @one + BigDecimal("2E-10").ceil(9).should == BigDecimal('1E-9') + BigDecimal("2E-10").ceil(10).should == BigDecimal('2E-10') + BigDecimal("2E-10").ceil(11).should == BigDecimal('2E-10') + + (1..10).each do |n| + # 0.4, 0.34, 0.334, etc. + (@one.div(@three,20)).ceil(n).should == BigDecimal("0.#{'3'*(n-1)}4") + # 1.4, 1.34, 1.334, etc. + (@four.div(@three,20)).ceil(n).should == BigDecimal("1.#{'3'*(n-1)}4") + (BigDecimal('31').div(@three,20)).ceil(n).should == BigDecimal("10.#{'3'*(n-1)}4") + end + (1..10).each do |n| + # -0.4, -0.34, -0.334, etc. + (-@one.div(@three,20)).ceil(n).should == BigDecimal("-0.#{'3'* n}") end + (1..10).each do |n| + (@three.div(@one,20)).ceil(n).should == @three + end + (1..10).each do |n| + (-@three.div(@one,20)).ceil(n).should == -@three + end + end + it "sets n digits left of the decimal point to 0, if given n < 0" do + BigDecimal("13345.234").ceil(-2).should == BigDecimal("13400.0") + @mixed_big.ceil(-99).should == BigDecimal("0.13E101") + @mixed_big.ceil(-100).should == BigDecimal("0.2E101") + @mixed_big.ceil(-95).should == BigDecimal("0.123457E101") + BigDecimal("1E10").ceil(-30).should == BigDecimal('1E30') + BigDecimal("-1E10").ceil(-30).should == @zero end + end diff --git a/spec/ruby/library/bigdecimal/clone_spec.rb b/spec/ruby/library/bigdecimal/clone_spec.rb index 8bb073b7b2c..b3a1c61d6a6 100644 --- a/spec/ruby/library/bigdecimal/clone_spec.rb +++ b/spec/ruby/library/bigdecimal/clone_spec.rb @@ -1,9 +1,6 @@ require_relative '../../spec_helper' +require_relative 'shared/clone' -ruby_version_is ""..."3.4" do - require_relative 'shared/clone' - - describe "BigDecimal#dup" do - it_behaves_like :bigdecimal_clone, :clone - end +describe "BigDecimal#dup" do + it_behaves_like :bigdecimal_clone, :clone end diff --git a/spec/ruby/library/bigdecimal/coerce_spec.rb b/spec/ruby/library/bigdecimal/coerce_spec.rb index a12997ffcd9..1e5c73f9690 100644 --- a/spec/ruby/library/bigdecimal/coerce_spec.rb +++ b/spec/ruby/library/bigdecimal/coerce_spec.rb @@ -1,29 +1,26 @@ require_relative '../../spec_helper' +require 'bigdecimal' -ruby_version_is ""..."3.4" do - require 'bigdecimal' +describe "BigDecimal#coerce" do - describe "BigDecimal#coerce" do - - it "returns [other, self] both as BigDecimal" do - one = BigDecimal("1.0") - five_point_28 = BigDecimal("5.28") - zero_minus = BigDecimal("-0.0") - some_value = 32434234234234234234 - - BigDecimal("1.2").coerce(1).should == [one, BigDecimal("1.2")] - five_point_28.coerce(1.0).should == [one, BigDecimal("5.28")] - one.coerce(one).should == [one, one] - one.coerce(2.5).should == [2.5, one] - BigDecimal("1").coerce(3.14).should == [3.14, one] - a, b = zero_minus.coerce(some_value) - a.should == BigDecimal(some_value.to_s) - b.should == zero_minus - a, b = one.coerce(some_value) - a.should == BigDecimal(some_value.to_s) - b.to_f.should be_close(1.0, TOLERANCE) # can we take out the to_f once BigDecimal#- is implemented? - b.should == one - end + it "returns [other, self] both as BigDecimal" do + one = BigDecimal("1.0") + five_point_28 = BigDecimal("5.28") + zero_minus = BigDecimal("-0.0") + some_value = 32434234234234234234 + BigDecimal("1.2").coerce(1).should == [one, BigDecimal("1.2")] + five_point_28.coerce(1.0).should == [one, BigDecimal("5.28")] + one.coerce(one).should == [one, one] + one.coerce(2.5).should == [2.5, one] + BigDecimal("1").coerce(3.14).should == [3.14, one] + a, b = zero_minus.coerce(some_value) + a.should == BigDecimal(some_value.to_s) + b.should == zero_minus + a, b = one.coerce(some_value) + a.should == BigDecimal(some_value.to_s) + b.to_f.should be_close(1.0, TOLERANCE) # can we take out the to_f once BigDecimal#- is implemented? + b.should == one end + end diff --git a/spec/ruby/library/bigdecimal/comparison_spec.rb b/spec/ruby/library/bigdecimal/comparison_spec.rb index ae6f00dd9a7..c53187b727d 100644 --- a/spec/ruby/library/bigdecimal/comparison_spec.rb +++ b/spec/ruby/library/bigdecimal/comparison_spec.rb @@ -1,84 +1,81 @@ require_relative '../../spec_helper' +require 'bigdecimal' -ruby_version_is ""..."3.4" do - require 'bigdecimal' +describe "BigDecimal#<=>" do + before :each do + @zero = BigDecimal("0") + @zero_pos = BigDecimal("+0") + @zero_neg = BigDecimal("-0") + @mixed = BigDecimal("1.23456789") + @mixed_big = BigDecimal("1.23456789E100") + @pos_int = BigDecimal("2E5555") + @neg_int = BigDecimal("-2E5555") + @pos_frac = BigDecimal("2E-9999") + @neg_frac = BigDecimal("-2E-9999") - describe "BigDecimal#<=>" do - before :each do - @zero = BigDecimal("0") - @zero_pos = BigDecimal("+0") - @zero_neg = BigDecimal("-0") - @mixed = BigDecimal("1.23456789") - @mixed_big = BigDecimal("1.23456789E100") - @pos_int = BigDecimal("2E5555") - @neg_int = BigDecimal("-2E5555") - @pos_frac = BigDecimal("2E-9999") - @neg_frac = BigDecimal("-2E-9999") - - @int_mock = mock('123') - class << @int_mock - def coerce(other) - return [other, BigDecimal('123')] - end - def >=(other) - BigDecimal('123') >= other - end + @int_mock = mock('123') + class << @int_mock + def coerce(other) + return [other, BigDecimal('123')] + end + def >=(other) + BigDecimal('123') >= other end + end - @values = [@mixed, @pos_int, @neg_int, @pos_frac, @neg_frac, - -2**32, -2**31, -2**30, -2**16, -2**8, -100, -10, -1, - @zero , 1, 2, 10, 2**8, 2**16, 2**32, @int_mock, @zero_pos, @zero_neg] + @values = [@mixed, @pos_int, @neg_int, @pos_frac, @neg_frac, + -2**32, -2**31, -2**30, -2**16, -2**8, -100, -10, -1, + @zero , 1, 2, 10, 2**8, 2**16, 2**32, @int_mock, @zero_pos, @zero_neg] - @infinity = BigDecimal("Infinity") - @infinity_neg = BigDecimal("-Infinity") - @nan = BigDecimal("NaN") - end + @infinity = BigDecimal("Infinity") + @infinity_neg = BigDecimal("-Infinity") + @nan = BigDecimal("NaN") + end - it "returns 0 if a == b" do - (@pos_int <=> @pos_int).should == 0 - (@neg_int <=> @neg_int).should == 0 - (@pos_frac <=> @pos_frac).should == 0 - (@neg_frac <=> @neg_frac).should == 0 - (@zero <=> @zero).should == 0 - (@infinity <=> @infinity).should == 0 - (@infinity_neg <=> @infinity_neg).should == 0 - end + it "returns 0 if a == b" do + (@pos_int <=> @pos_int).should == 0 + (@neg_int <=> @neg_int).should == 0 + (@pos_frac <=> @pos_frac).should == 0 + (@neg_frac <=> @neg_frac).should == 0 + (@zero <=> @zero).should == 0 + (@infinity <=> @infinity).should == 0 + (@infinity_neg <=> @infinity_neg).should == 0 + end - it "returns 1 if a > b" do - (@pos_int <=> @neg_int).should == 1 - (@pos_frac <=> @neg_frac).should == 1 - (@pos_frac <=> @zero).should == 1 - @values.each { |val| - (@infinity <=> val).should == 1 - } - end + it "returns 1 if a > b" do + (@pos_int <=> @neg_int).should == 1 + (@pos_frac <=> @neg_frac).should == 1 + (@pos_frac <=> @zero).should == 1 + @values.each { |val| + (@infinity <=> val).should == 1 + } + end - it "returns -1 if a < b" do - (@zero <=> @pos_frac).should == -1 - (@neg_int <=> @pos_frac).should == -1 - (@pos_frac <=> @pos_int).should == -1 - @values.each { |val| - (@infinity_neg <=> val).should == -1 - } - end + it "returns -1 if a < b" do + (@zero <=> @pos_frac).should == -1 + (@neg_int <=> @pos_frac).should == -1 + (@pos_frac <=> @pos_int).should == -1 + @values.each { |val| + (@infinity_neg <=> val).should == -1 + } + end - it "returns nil if NaN is involved" do - @values += [@infinity, @infinity_neg, @nan] - @values << nil - @values << Object.new - @values.each { |val| - (@nan <=> val).should == nil - } - end + it "returns nil if NaN is involved" do + @values += [@infinity, @infinity_neg, @nan] + @values << nil + @values << Object.new + @values.each { |val| + (@nan <=> val).should == nil + } + end - it "returns nil if the argument is nil" do - (@zero <=> nil).should == nil - (@infinity <=> nil).should == nil - (@infinity_neg <=> nil).should == nil - (@mixed <=> nil).should == nil - (@pos_int <=> nil).should == nil - (@neg_frac <=> nil).should == nil - end + it "returns nil if the argument is nil" do + (@zero <=> nil).should == nil + (@infinity <=> nil).should == nil + (@infinity_neg <=> nil).should == nil + (@mixed <=> nil).should == nil + (@pos_int <=> nil).should == nil + (@neg_frac <=> nil).should == nil end end diff --git a/spec/ruby/library/bigdecimal/constants_spec.rb b/spec/ruby/library/bigdecimal/constants_spec.rb index 6779a727c36..8d879c036ac 100644 --- a/spec/ruby/library/bigdecimal/constants_spec.rb +++ b/spec/ruby/library/bigdecimal/constants_spec.rb @@ -1,72 +1,69 @@ require_relative '../../spec_helper' +require 'bigdecimal' -ruby_version_is ""..."3.4" do - require 'bigdecimal' - - describe "BigDecimal constants" do - it "defines a VERSION value" do - BigDecimal.const_defined?(:VERSION).should be_true - end +describe "BigDecimal constants" do + it "defines a VERSION value" do + BigDecimal.const_defined?(:VERSION).should be_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 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 be_true - end + it "has a NaN value" do + BigDecimal::NAN.nan?.should be_true + end - it "has an INFINITY value" do - BigDecimal::INFINITY.infinite?.should == 1 - 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 + 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 + 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 + 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 diff --git a/spec/ruby/library/bigdecimal/core_spec.rb b/spec/ruby/library/bigdecimal/core_spec.rb new file mode 100644 index 00000000000..acee4dcf564 --- /dev/null +++ b/spec/ruby/library/bigdecimal/core_spec.rb @@ -0,0 +1,59 @@ +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 + result = BigDecimal('0.22314354220170971436137296411949880462556361100856391620766259404746040597133837784E0') + r = Rational(1_234_567_890, 987_654_321) + BigMath.log(r, 50).should == result + 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 be_true + result.last.is_a?(Float).should be_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 be_true + result.last.is_a?(Rational).should be_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_error(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 7e0b8fada75..53ad6d04184 100644 --- a/spec/ruby/library/bigdecimal/div_spec.rb +++ b/spec/ruby/library/bigdecimal/div_spec.rb @@ -1,113 +1,110 @@ require_relative '../../spec_helper' +require_relative 'shared/quo' +require 'bigdecimal' + +describe "BigDecimal#div with precision set to 0" do + # TODO: figure out if there is a better way to do these + # shared specs rather than sending [0]. See other specs + # that share :bigdecimal_quo. + it_behaves_like :bigdecimal_quo, :div, [0] +end -ruby_version_is ""..."3.4" do - require_relative 'shared/quo' - require 'bigdecimal' - - describe "BigDecimal#div with precision set to 0" do - # TODO: figure out if there is a better way to do these - # shared specs rather than sending [0]. See other specs - # that share :bigdecimal_quo. - it_behaves_like :bigdecimal_quo, :div, [0] +describe "BigDecimal#div" do + + before :each do + @one = BigDecimal("1") + @zero = BigDecimal("0") + @zero_plus = BigDecimal("+0") + @zero_minus = 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") end - describe "BigDecimal#div" do - - before :each do - @one = BigDecimal("1") - @zero = BigDecimal("0") - @zero_plus = BigDecimal("+0") - @zero_minus = 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") - end - - it "returns a / b with optional precision" do - @two.div(@one).should == @two - @one.div(@two).should == @zero - # ^^ is this really intended for a class with arbitrary precision? - @one.div(@two, 1).should == BigDecimal("0.5") - @one.div(@one_minus).should == @one_minus - @one_minus.div(@one_minus).should == @one - @frac_2.div(@frac_1, 1).should == BigDecimal("0.9") - @frac_1.div(@frac_1).should == @one - - res = "0." + "3" * 1000 - (1..100).each { |idx| - @one.div(@three, idx).to_s("F").should == "0." + res[2, idx] - } - end + it "returns a / b with optional precision" do + @two.div(@one).should == @two + @one.div(@two).should == @zero + # ^^ is this really intended for a class with arbitrary precision? + @one.div(@two, 1).should == BigDecimal("0.5") + @one.div(@one_minus).should == @one_minus + @one_minus.div(@one_minus).should == @one + @frac_2.div(@frac_1, 1).should == BigDecimal("0.9") + @frac_1.div(@frac_1).should == @one + + res = "0." + "3" * 1000 + (1..100).each { |idx| + @one.div(@three, idx).to_s("F").should == "0." + res[2, idx] + } + 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 + 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 - -> { @one.div(@nan) }.should raise_error(FloatDomainError) - -> { @nan.div(@one) }.should raise_error(FloatDomainError) - -> { @nan.div(@nan) }.should raise_error(FloatDomainError) - end + it "raises FloatDomainError if NaN is involved" do + -> { @one.div(@nan) }.should raise_error(FloatDomainError) + -> { @nan.div(@one) }.should raise_error(FloatDomainError) + -> { @nan.div(@nan) }.should raise_error(FloatDomainError) + end - it "returns 0 if divided by Infinity and no precision given" do - @zero.div(@infinity).should == 0 - @frac_2.div(@infinity).should == 0 - end + it "returns 0 if divided by Infinity and no precision given" do + @zero.div(@infinity).should == 0 + @frac_2.div(@infinity).should == 0 + end - it "returns 0 if divided by Infinity with given precision" do - @zero.div(@infinity, 0).should == 0 - @frac_2.div(@infinity, 1).should == 0 - @zero.div(@infinity, 100000).should == 0 - @frac_2.div(@infinity, 100000).should == 0 - end + it "returns 0 if divided by Infinity with given precision" do + @zero.div(@infinity, 0).should == 0 + @frac_2.div(@infinity, 1).should == 0 + @zero.div(@infinity, 100000).should == 0 + @frac_2.div(@infinity, 100000).should == 0 + end - it "raises ZeroDivisionError if divided by zero and no precision given" do - -> { @one.div(@zero) }.should raise_error(ZeroDivisionError) - -> { @one.div(@zero_plus) }.should raise_error(ZeroDivisionError) - -> { @one.div(@zero_minus) }.should raise_error(ZeroDivisionError) + it "raises ZeroDivisionError if divided by zero and no precision given" do + -> { @one.div(@zero) }.should raise_error(ZeroDivisionError) + -> { @one.div(@zero_plus) }.should raise_error(ZeroDivisionError) + -> { @one.div(@zero_minus) }.should raise_error(ZeroDivisionError) - -> { @zero.div(@zero) }.should raise_error(ZeroDivisionError) - -> { @zero_minus.div(@zero_plus) }.should raise_error(ZeroDivisionError) - -> { @zero_minus.div(@zero_minus) }.should raise_error(ZeroDivisionError) - -> { @zero_plus.div(@zero_minus) }.should raise_error(ZeroDivisionError) - end + -> { @zero.div(@zero) }.should raise_error(ZeroDivisionError) + -> { @zero_minus.div(@zero_plus) }.should raise_error(ZeroDivisionError) + -> { @zero_minus.div(@zero_minus) }.should raise_error(ZeroDivisionError) + -> { @zero_plus.div(@zero_minus) }.should raise_error(ZeroDivisionError) + end - it "returns NaN if zero is divided by zero" do - @zero.div(@zero, 0).should.nan? - @zero_minus.div(@zero_plus, 0).should.nan? - @zero_plus.div(@zero_minus, 0).should.nan? + it "returns NaN if zero is divided by zero" do + @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).should.nan? - @zero_minus.div(@zero_plus, 10).should.nan? - @zero_plus.div(@zero_minus, 10).should.nan? - end + @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 - -> { @infinity_minus.div(@one) }.should raise_error(FloatDomainError) - -> { @infinity.div(@one) }.should raise_error(FloatDomainError) - -> { @infinity_minus.div(@one_minus) }.should raise_error(FloatDomainError) - end + it "raises FloatDomainError if (+|-) Infinity divided by 1 and no precision given" do + -> { @infinity_minus.div(@one) }.should raise_error(FloatDomainError) + -> { @infinity.div(@one) }.should raise_error(FloatDomainError) + -> { @infinity_minus.div(@one_minus) }.should raise_error(FloatDomainError) + end - it "returns (+|-)Infinity if (+|-)Infinity by 1 and precision given" do - @infinity_minus.div(@one, 0).should == @infinity_minus - @infinity.div(@one, 0).should == @infinity - @infinity_minus.div(@one_minus, 0).should == @infinity - end + it "returns (+|-)Infinity if (+|-)Infinity by 1 and precision given" do + @infinity_minus.div(@one, 0).should == @infinity_minus + @infinity.div(@one, 0).should == @infinity + @infinity_minus.div(@one_minus, 0).should == @infinity + end - it "returns NaN if Infinity / ((+|-) Infinity)" do - @infinity.div(@infinity_minus, 100000).should.nan? - @infinity_minus.div(@infinity, 1).should.nan? - end + it "returns NaN if Infinity / ((+|-) Infinity)" do + @infinity.div(@infinity_minus, 100000).should.nan? + @infinity_minus.div(@infinity, 1).should.nan? + end - end end diff --git a/spec/ruby/library/bigdecimal/divide_spec.rb b/spec/ruby/library/bigdecimal/divide_spec.rb index 77ca878402e..c62b23557de 100644 --- a/spec/ruby/library/bigdecimal/divide_spec.rb +++ b/spec/ruby/library/bigdecimal/divide_spec.rb @@ -1,20 +1,17 @@ require_relative '../../spec_helper' +require_relative 'shared/quo' +require 'bigdecimal' -ruby_version_is ""..."3.4" do - require_relative 'shared/quo' - require 'bigdecimal' +describe "BigDecimal#/" do + it_behaves_like :bigdecimal_quo, :/, [] - describe "BigDecimal#/" do - it_behaves_like :bigdecimal_quo, :/, [] - - before :each do - @three = BigDecimal("3") - end + 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 + 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 8b42f2329e4..294f01cba01 100644 --- a/spec/ruby/library/bigdecimal/divmod_spec.rb +++ b/spec/ruby/library/bigdecimal/divmod_spec.rb @@ -1,183 +1,180 @@ require_relative '../../spec_helper' - -ruby_version_is ""..."3.4" do - require_relative 'shared/modulo' - require 'bigdecimal' - - module DivmodSpecs - def self.check_both_nan(array) - array.length.should == 2 - array[0].should.nan? - array[1].should.nan? - end - def self.check_both_bigdecimal(array) - array.length.should == 2 - array[0].kind_of?(BigDecimal).should == true - array[1].kind_of?(BigDecimal).should == true - end +require_relative 'shared/modulo' +require 'bigdecimal' + +module DivmodSpecs + def self.check_both_nan(array) + array.length.should == 2 + array[0].should.nan? + array[1].should.nan? + end + def self.check_both_bigdecimal(array) + array.length.should == 2 + array[0].kind_of?(BigDecimal).should == true + array[1].kind_of?(BigDecimal).should == true end +end - # TODO: figure out a way to do the shared specs with helpers instead - # of spec'ing a method that does not really exist - describe "BigDecimal#mod_part_of_divmod" do - # BigDecimal#divmod[1] behaves exactly like #modulo - before :all do - class BigDecimal - def mod_part_of_divmod(arg) - divmod(arg)[1] - end +# TODO: figure out a way to do the shared specs with helpers instead +# of spec'ing a method that does not really exist +describe "BigDecimal#mod_part_of_divmod" do + # BigDecimal#divmod[1] behaves exactly like #modulo + before :all do + class BigDecimal + def mod_part_of_divmod(arg) + divmod(arg)[1] end end + end - after :all do - class BigDecimal - undef mod_part_of_divmod - end + after :all do + class BigDecimal + undef mod_part_of_divmod end + end - it_behaves_like :bigdecimal_modulo, :mod_part_of_divmod + it_behaves_like :bigdecimal_modulo, :mod_part_of_divmod - it "raises ZeroDivisionError if other is zero" do - bd5667 = BigDecimal("5667.19") + it "raises ZeroDivisionError if other is zero" do + bd5667 = BigDecimal("5667.19") - -> { bd5667.mod_part_of_divmod(0) }.should raise_error(ZeroDivisionError) - -> { bd5667.mod_part_of_divmod(BigDecimal("0")) }.should raise_error(ZeroDivisionError) - -> { @zero.mod_part_of_divmod(@zero) }.should raise_error(ZeroDivisionError) - end + -> { bd5667.mod_part_of_divmod(0) }.should raise_error(ZeroDivisionError) + -> { bd5667.mod_part_of_divmod(BigDecimal("0")) }.should raise_error(ZeroDivisionError) + -> { @zero.mod_part_of_divmod(@zero) }.should raise_error(ZeroDivisionError) end +end - describe "BigDecimal#divmod" do - - before :each do - @a = BigDecimal("42.00000000000000000001") - - @zero = BigDecimal("0") - @zero_pos = BigDecimal("+0") - @zero_neg = BigDecimal("-0") - - @one = BigDecimal("1") - @mixed = BigDecimal("1.23456789") - @pos_int = BigDecimal("2E5555") - @neg_int = BigDecimal("-2E5555") - @pos_frac = BigDecimal("2E-9999") - @neg_frac = BigDecimal("-2E-9999") - @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") - - @special_vals = [@infinity, @infinity_minus, @nan] - @regular_vals = [ - @one, @mixed, @pos_int, @neg_int, @pos_frac, - @neg_frac, @one_minus, @frac_1, @frac_2] - @zeroes = [@zero, @zero_pos, @zero_neg] - end +describe "BigDecimal#divmod" do + + before :each do + @a = BigDecimal("42.00000000000000000001") + + @zero = BigDecimal("0") + @zero_pos = BigDecimal("+0") + @zero_neg = BigDecimal("-0") + + @one = BigDecimal("1") + @mixed = BigDecimal("1.23456789") + @pos_int = BigDecimal("2E5555") + @neg_int = BigDecimal("-2E5555") + @pos_frac = BigDecimal("2E-9999") + @neg_frac = BigDecimal("-2E-9999") + @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") + + @special_vals = [@infinity, @infinity_minus, @nan] + @regular_vals = [ + @one, @mixed, @pos_int, @neg_int, @pos_frac, + @neg_frac, @one_minus, @frac_1, @frac_2] + @zeroes = [@zero, @zero_pos, @zero_neg] + end - it "divides value, returns an array" do - res = @a.divmod(5) - res.kind_of?(Array).should == true - end + it "divides value, returns an array" do + res = @a.divmod(5) + res.kind_of?(Array).should == true + 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') + 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') - BigDecimal('1').divmod(BigDecimal('2')).should == [0, 1] - BigDecimal('2').divmod(BigDecimal('1')).should == [2, 0] + BigDecimal('1').divmod(BigDecimal('2')).should == [0, 1] + BigDecimal('2').divmod(BigDecimal('1')).should == [2, 0] - BigDecimal('1').divmod(BigDecimal('-2')).should == [-1, -1] - BigDecimal('2').divmod(BigDecimal('-1')).should == [-2, 0] + BigDecimal('1').divmod(BigDecimal('-2')).should == [-1, -1] + BigDecimal('2').divmod(BigDecimal('-1')).should == [-2, 0] - BigDecimal('-1').divmod(BigDecimal('2')).should == [-1, 1] - BigDecimal('-2').divmod(BigDecimal('1')).should == [-2, 0] - end + BigDecimal('-1').divmod(BigDecimal('2')).should == [-1, 1] + BigDecimal('-2').divmod(BigDecimal('1')).should == [-2, 0] + end - it "can be reversed with * and +" do - # Example taken from BigDecimal documentation - a = BigDecimal("42") - b = BigDecimal("9") - q, m = a.divmod(b) - c = q * b + m - a.should == c - - values = [@one, @one_minus, BigDecimal('2'), BigDecimal('-2'), - BigDecimal('5'), BigDecimal('-5'), BigDecimal('10'), BigDecimal('-10'), - BigDecimal('20'), BigDecimal('-20'), BigDecimal('100'), BigDecimal('-100'), - BigDecimal('1.23456789E10'), BigDecimal('-1.23456789E10') - ] - - # TODO: file MRI bug: - # BigDecimal('1').divmod(BigDecimal('3E-9'))[0] #=> 0.3E9, - # but really should be 0.333333333E9 - values << BigDecimal('1E-10') - values << BigDecimal('-1E-10') - values << BigDecimal('2E55') - values << BigDecimal('-2E55') - values << BigDecimal('2E-5555') - values << BigDecimal('-2E-5555') - - - values_and_zeroes = values + @zeroes - 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 + it "can be reversed with * and +" do + # Example taken from BigDecimal documentation + a = BigDecimal("42") + b = BigDecimal("9") + q, m = a.divmod(b) + c = q * b + m + a.should == c + + values = [@one, @one_minus, BigDecimal('2'), BigDecimal('-2'), + BigDecimal('5'), BigDecimal('-5'), BigDecimal('10'), BigDecimal('-10'), + BigDecimal('20'), BigDecimal('-20'), BigDecimal('100'), BigDecimal('-100'), + BigDecimal('1.23456789E10'), BigDecimal('-1.23456789E10') + ] + + # TODO: file MRI bug: + # BigDecimal('1').divmod(BigDecimal('3E-9'))[0] #=> 0.3E9, + # but really should be 0.333333333E9 + values << BigDecimal('1E-10') + values << BigDecimal('-1E-10') + values << BigDecimal('2E55') + values << BigDecimal('-2E55') + values << BigDecimal('2E-5555') + values << BigDecimal('-2E-5555') + + + values_and_zeroes = values + @zeroes + 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)) - 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)) end + end - it "raises ZeroDivisionError if the divisor is zero" do - (@special_vals + @regular_vals + @zeroes - [@nan]).each do |val| - @zeroes.each do |zero| - -> { val.divmod(zero) }.should raise_error(ZeroDivisionError) - end + it "raises ZeroDivisionError if the divisor is zero" do + (@special_vals + @regular_vals + @zeroes - [@nan]).each do |val| + @zeroes.each do |zero| + -> { val.divmod(zero) }.should raise_error(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].should.nan? - end + it "returns an array of Infinity and NaN if the dividend is Infinity" do + @regular_vals.each do |val| + array = @infinity.divmod(val) + array.length.should == 2 + array[0].infinite?.should == (val > 0 ? 1 : -1) + array[1].should.nan? 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 - 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 end + end - 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] - end + 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] end end + end - it "raises TypeError if the argument cannot be coerced to BigDecimal" do - -> { - @one.divmod('1') - }.should raise_error(TypeError) - end - + it "raises TypeError if the argument cannot be coerced to BigDecimal" do + -> { + @one.divmod('1') + }.should raise_error(TypeError) end + end diff --git a/spec/ruby/library/bigdecimal/double_fig_spec.rb b/spec/ruby/library/bigdecimal/double_fig_spec.rb index d008dbcefb1..f742d68f876 100644 --- a/spec/ruby/library/bigdecimal/double_fig_spec.rb +++ b/spec/ruby/library/bigdecimal/double_fig_spec.rb @@ -1,12 +1,9 @@ require_relative '../../spec_helper' +require 'bigdecimal' -ruby_version_is ""..."3.4" do - require 'bigdecimal' - - describe "BigDecimal.double_fig" do - # The result depends on the CPU and OS - it "returns the number of digits a Float number is allowed to have" do - BigDecimal.double_fig.should_not == nil - end +describe "BigDecimal.double_fig" do + # The result depends on the CPU and OS + it "returns the number of digits a Float number is allowed to have" do + BigDecimal.double_fig.should_not == nil end end diff --git a/spec/ruby/library/bigdecimal/dup_spec.rb b/spec/ruby/library/bigdecimal/dup_spec.rb index 3fe07c3738f..bfabaf6e8b7 100644 --- a/spec/ruby/library/bigdecimal/dup_spec.rb +++ b/spec/ruby/library/bigdecimal/dup_spec.rb @@ -1,9 +1,6 @@ require_relative '../../spec_helper' +require_relative 'shared/clone' -ruby_version_is ""..."3.4" do - require_relative 'shared/clone' - - describe "BigDecimal#dup" do - it_behaves_like :bigdecimal_clone, :dup - end +describe "BigDecimal#dup" do + it_behaves_like :bigdecimal_clone, :dup end diff --git a/spec/ruby/library/bigdecimal/eql_spec.rb b/spec/ruby/library/bigdecimal/eql_spec.rb index 4a2c0e0b119..1be58627519 100644 --- a/spec/ruby/library/bigdecimal/eql_spec.rb +++ b/spec/ruby/library/bigdecimal/eql_spec.rb @@ -1,9 +1,6 @@ require_relative '../../spec_helper' +require_relative 'shared/eql' -ruby_version_is ""..."3.4" do - require_relative 'shared/eql' - - describe "BigDecimal#eql?" do - it_behaves_like :bigdecimal_eql, :eql? - end +describe "BigDecimal#eql?" do + it_behaves_like :bigdecimal_eql, :eql? end diff --git a/spec/ruby/library/bigdecimal/equal_value_spec.rb b/spec/ruby/library/bigdecimal/equal_value_spec.rb index 7c2230cbc41..933060eada8 100644 --- a/spec/ruby/library/bigdecimal/equal_value_spec.rb +++ b/spec/ruby/library/bigdecimal/equal_value_spec.rb @@ -1,10 +1,7 @@ require_relative '../../spec_helper' +require_relative 'shared/eql' -ruby_version_is ""..."3.4" do - require_relative 'shared/eql' - - describe "BigDecimal#==" do - it_behaves_like :bigdecimal_eql, :== - end +describe "BigDecimal#==" do + it_behaves_like :bigdecimal_eql, :== end diff --git a/spec/ruby/library/bigdecimal/exponent_spec.rb b/spec/ruby/library/bigdecimal/exponent_spec.rb index 7574e8c560c..88771479551 100644 --- a/spec/ruby/library/bigdecimal/exponent_spec.rb +++ b/spec/ruby/library/bigdecimal/exponent_spec.rb @@ -1,30 +1,27 @@ require_relative '../../spec_helper' +require_relative 'shared/power' +require 'bigdecimal' -ruby_version_is ""..."3.4" do - require_relative 'shared/power' - require 'bigdecimal' - - describe "BigDecimal#**" do - it_behaves_like :bigdecimal_power, :** - end - - describe "BigDecimal#exponent" do +describe "BigDecimal#**" do + it_behaves_like :bigdecimal_power, :** +end - it "returns an Integer" do - BigDecimal("2E100000000").exponent.kind_of?(Integer).should == true - BigDecimal("2E-999").exponent.kind_of?(Integer).should == true - end +describe "BigDecimal#exponent" do - it "is n if number can be represented as 0.xxx*10**n" do - BigDecimal("2E1000").exponent.should == 1001 - BigDecimal("1234567E10").exponent.should == 17 - end + it "returns an Integer" do + BigDecimal("2E100000000").exponent.kind_of?(Integer).should == true + BigDecimal("2E-999").exponent.kind_of?(Integer).should == true + end - it "returns 0 if self is 0" do - BigDecimal("0").exponent.should == 0 - BigDecimal("+0").exponent.should == 0 - BigDecimal("-0").exponent.should == 0 - end + it "is n if number can be represented as 0.xxx*10**n" do + BigDecimal("2E1000").exponent.should == 1001 + BigDecimal("1234567E10").exponent.should == 17 + end + it "returns 0 if self is 0" do + BigDecimal("0").exponent.should == 0 + BigDecimal("+0").exponent.should == 0 + BigDecimal("-0").exponent.should == 0 end + end diff --git a/spec/ruby/library/bigdecimal/finite_spec.rb b/spec/ruby/library/bigdecimal/finite_spec.rb index af693ac4963..8fc06029bb3 100644 --- a/spec/ruby/library/bigdecimal/finite_spec.rb +++ b/spec/ruby/library/bigdecimal/finite_spec.rb @@ -1,37 +1,34 @@ require_relative '../../spec_helper' +require 'bigdecimal' -ruby_version_is ""..."3.4" do - require 'bigdecimal' - - describe "BigDecimal#finite?" do - before :each do - @one = BigDecimal("1") - @zero = BigDecimal("0") - @zero_pos = BigDecimal("+0") - @zero_neg = 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") - @big = BigDecimal("2E40001") - @finite_vals = [@one, @zero, @zero_pos, @zero_neg, @two, - @three, @frac_1, @frac_2, @big, @one_minus] - end +describe "BigDecimal#finite?" do + before :each do + @one = BigDecimal("1") + @zero = BigDecimal("0") + @zero_pos = BigDecimal("+0") + @zero_neg = 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") + @big = BigDecimal("2E40001") + @finite_vals = [@one, @zero, @zero_pos, @zero_neg, @two, + @three, @frac_1, @frac_2, @big, @one_minus] + end - it "is false if Infinity or NaN" do - @infinity.should_not.finite? - @infinity_minus.should_not.finite? - @nan.should_not.finite? - end + it "is false if Infinity or NaN" do + @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.should.finite? - end + it "returns true for finite values" do + @finite_vals.each do |val| + 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 49a898b9c5e..231c9a587e3 100644 --- a/spec/ruby/library/bigdecimal/fix_spec.rb +++ b/spec/ruby/library/bigdecimal/fix_spec.rb @@ -1,60 +1,57 @@ require_relative '../../spec_helper' - -ruby_version_is ""..."3.4" do - 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 - - it "returns a BigDecimal" do - BigDecimal("2E100000000").fix.kind_of?(BigDecimal).should == true - BigDecimal("2E-999").kind_of?(BigDecimal).should == true +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 - it "returns the integer part of the absolute value" do - a = BigDecimal("2E1000") - a.fix.should == a - b = BigDecimal("-2E1000") - b.fix.should == b - BigDecimal("0.123456789E5").fix.should == BigDecimal("0.12345E5") - BigDecimal("-0.123456789E5").fix.should == BigDecimal("-0.12345E5") - end + it "returns a BigDecimal" do + BigDecimal("2E100000000").fix.kind_of?(BigDecimal).should == true + BigDecimal("2E-999").kind_of?(BigDecimal).should == true + end - it "correctly handles special values" do - @infinity.fix.should == @infinity - @infinity_neg.fix.should == @infinity_neg - @nan.fix.should.nan? - end + it "returns the integer part of the absolute value" do + a = BigDecimal("2E1000") + a.fix.should == a + b = BigDecimal("-2E1000") + b.fix.should == b + BigDecimal("0.123456789E5").fix.should == BigDecimal("0.12345E5") + BigDecimal("-0.123456789E5").fix.should == BigDecimal("-0.12345E5") + end - it "returns 0 if the absolute value is < 1" do - BigDecimal("0.99999").fix.should == 0 - BigDecimal("-0.99999").fix.should == 0 - BigDecimal("0.000000001").fix.should == 0 - BigDecimal("-0.00000001").fix.should == 0 - BigDecimal("-1000000").fix.should_not == 0 - @zero.fix.should == 0 - @zero_pos.fix.should == @zero_pos - @zero_neg.fix.should == @zero_neg - end + it "correctly handles special values" do + @infinity.fix.should == @infinity + @infinity_neg.fix.should == @infinity_neg + @nan.fix.should.nan? + end - it "does not allow any arguments" do - -> { - @mixed.fix(10) - }.should raise_error(ArgumentError) - end + it "returns 0 if the absolute value is < 1" do + BigDecimal("0.99999").fix.should == 0 + BigDecimal("-0.99999").fix.should == 0 + BigDecimal("0.000000001").fix.should == 0 + BigDecimal("-0.00000001").fix.should == 0 + BigDecimal("-1000000").fix.should_not == 0 + @zero.fix.should == 0 + @zero_pos.fix.should == @zero_pos + @zero_neg.fix.should == @zero_neg + end + it "does not allow any arguments" do + -> { + @mixed.fix(10) + }.should raise_error(ArgumentError) end + end diff --git a/spec/ruby/library/bigdecimal/floor_spec.rb b/spec/ruby/library/bigdecimal/floor_spec.rb index e36843c1167..a7dfec2c9a1 100644 --- a/spec/ruby/library/bigdecimal/floor_spec.rb +++ b/spec/ruby/library/bigdecimal/floor_spec.rb @@ -1,103 +1,100 @@ require_relative '../../spec_helper' +require 'bigdecimal' -ruby_version_is ""..."3.4" do - require 'bigdecimal' +describe "BigDecimal#floor" do + before :each do + @one = BigDecimal("1") + @three = BigDecimal("3") + @four = BigDecimal("4") + @zero = BigDecimal("0") + @mixed = BigDecimal("1.23456789") + @mixed_big = BigDecimal("1.23456789E100") + @pos_int = BigDecimal("2E5555") + @neg_int = BigDecimal("-2E5555") + @pos_frac = BigDecimal("2E-9999") + @neg_frac = BigDecimal("-2E-9999") - describe "BigDecimal#floor" do - before :each do - @one = BigDecimal("1") - @three = BigDecimal("3") - @four = BigDecimal("4") - @zero = BigDecimal("0") - @mixed = BigDecimal("1.23456789") - @mixed_big = BigDecimal("1.23456789E100") - @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 + @infinity = BigDecimal("Infinity") + @infinity_neg = BigDecimal("-Infinity") + @nan = BigDecimal("NaN") + @zero_pos = BigDecimal("+0") + @zero_neg = BigDecimal("-0") + end - it "returns the greatest integer smaller or equal to self" do - @pos_int.floor.should == @pos_int - @neg_int.floor.should == @neg_int - @pos_frac.floor.should == @zero - @neg_frac.floor.should == BigDecimal("-1") - @zero.floor.should == 0 - @zero_pos.floor.should == @zero_pos - @zero_neg.floor.should == @zero_neg + it "returns the greatest integer smaller or equal to self" do + @pos_int.floor.should == @pos_int + @neg_int.floor.should == @neg_int + @pos_frac.floor.should == @zero + @neg_frac.floor.should == BigDecimal("-1") + @zero.floor.should == 0 + @zero_pos.floor.should == @zero_pos + @zero_neg.floor.should == @zero_neg - BigDecimal('2.3').floor.should == 2 - BigDecimal('2.5').floor.should == 2 - BigDecimal('2.9999').floor.should == 2 - BigDecimal('-2.3').floor.should == -3 - BigDecimal('-2.5').floor.should == -3 - BigDecimal('-2.9999').floor.should == -3 - BigDecimal('0.8').floor.should == 0 - BigDecimal('-0.8').floor.should == -1 - end + BigDecimal('2.3').floor.should == 2 + BigDecimal('2.5').floor.should == 2 + BigDecimal('2.9999').floor.should == 2 + BigDecimal('-2.3').floor.should == -3 + BigDecimal('-2.5').floor.should == -3 + BigDecimal('-2.9999').floor.should == -3 + BigDecimal('0.8').floor.should == 0 + BigDecimal('-0.8').floor.should == -1 + end - it "raise exception, if self is special value" do - -> { @infinity.floor }.should raise_error(FloatDomainError) - -> { @infinity_neg.floor }.should raise_error(FloatDomainError) - -> { @nan.floor }.should raise_error(FloatDomainError) - end + it "raise exception, if self is special value" do + -> { @infinity.floor }.should raise_error(FloatDomainError) + -> { @infinity_neg.floor }.should raise_error(FloatDomainError) + -> { @nan.floor }.should raise_error(FloatDomainError) + end - it "returns n digits right of the decimal point if given n > 0" do - @mixed.floor(1).should == BigDecimal("1.2") - @mixed.floor(5).should == BigDecimal("1.23456") + it "returns n digits right of the decimal point if given n > 0" do + @mixed.floor(1).should == BigDecimal("1.2") + @mixed.floor(5).should == BigDecimal("1.23456") - BigDecimal("-0.03").floor(1).should == BigDecimal("-0.1") - BigDecimal("0.03").floor(1).should == BigDecimal("0") + BigDecimal("-0.03").floor(1).should == BigDecimal("-0.1") + BigDecimal("0.03").floor(1).should == BigDecimal("0") - BigDecimal("23.45").floor(0).should == BigDecimal('23') - BigDecimal("23.45").floor(1).should == BigDecimal('23.4') - BigDecimal("23.45").floor(2).should == BigDecimal('23.45') + BigDecimal("23.45").floor(0).should == BigDecimal('23') + BigDecimal("23.45").floor(1).should == BigDecimal('23.4') + BigDecimal("23.45").floor(2).should == BigDecimal('23.45') - BigDecimal("-23.45").floor(0).should == BigDecimal('-24') - BigDecimal("-23.45").floor(1).should == BigDecimal('-23.5') - BigDecimal("-23.45").floor(2).should == BigDecimal('-23.45') + BigDecimal("-23.45").floor(0).should == BigDecimal('-24') + BigDecimal("-23.45").floor(1).should == BigDecimal('-23.5') + BigDecimal("-23.45").floor(2).should == BigDecimal('-23.45') - BigDecimal("2E-10").floor(0).should == @zero - BigDecimal("2E-10").floor(9).should == @zero - BigDecimal("2E-10").floor(10).should == BigDecimal('2E-10') - BigDecimal("2E-10").floor(11).should == BigDecimal('2E-10') + BigDecimal("2E-10").floor(0).should == @zero + BigDecimal("2E-10").floor(9).should == @zero + BigDecimal("2E-10").floor(10).should == BigDecimal('2E-10') + BigDecimal("2E-10").floor(11).should == BigDecimal('2E-10') - (1..10).each do |n| - # 0.3, 0.33, 0.333, etc. - (@one.div(@three,20)).floor(n).should == BigDecimal("0.#{'3'*n}") - # 1.3, 1.33, 1.333, etc. - (@four.div(@three,20)).floor(n).should == BigDecimal("1.#{'3'*n}") - (BigDecimal('31').div(@three,20)).floor(n).should == BigDecimal("10.#{'3'*n}") - end - (1..10).each do |n| - # -0.4, -0.34, -0.334, etc. - (-@one.div(@three,20)).floor(n).should == BigDecimal("-0.#{'3'*(n-1)}4") - end - (1..10).each do |n| - (@three.div(@one,20)).floor(n).should == @three - end - (1..10).each do |n| - (-@three.div(@one,20)).floor(n).should == -@three - end + (1..10).each do |n| + # 0.3, 0.33, 0.333, etc. + (@one.div(@three,20)).floor(n).should == BigDecimal("0.#{'3'*n}") + # 1.3, 1.33, 1.333, etc. + (@four.div(@three,20)).floor(n).should == BigDecimal("1.#{'3'*n}") + (BigDecimal('31').div(@three,20)).floor(n).should == BigDecimal("10.#{'3'*n}") end - - it "sets n digits left of the decimal point to 0, if given n < 0" do - BigDecimal("13345.234").floor(-2).should == BigDecimal("13300.0") - @mixed_big.floor(-99).should == BigDecimal("0.12E101") - @mixed_big.floor(-100).should == BigDecimal("0.1E101") - @mixed_big.floor(-95).should == BigDecimal("0.123456E101") - (1..10).each do |n| - BigDecimal('1.8').floor(-n).should == @zero - end - BigDecimal("1E10").floor(-30).should == @zero - BigDecimal("-1E10").floor(-30).should == BigDecimal('-1E30') + (1..10).each do |n| + # -0.4, -0.34, -0.334, etc. + (-@one.div(@three,20)).floor(n).should == BigDecimal("-0.#{'3'*(n-1)}4") + end + (1..10).each do |n| + (@three.div(@one,20)).floor(n).should == @three + end + (1..10).each do |n| + (-@three.div(@one,20)).floor(n).should == -@three end + end + it "sets n digits left of the decimal point to 0, if given n < 0" do + BigDecimal("13345.234").floor(-2).should == BigDecimal("13300.0") + @mixed_big.floor(-99).should == BigDecimal("0.12E101") + @mixed_big.floor(-100).should == BigDecimal("0.1E101") + @mixed_big.floor(-95).should == BigDecimal("0.123456E101") + (1..10).each do |n| + BigDecimal('1.8').floor(-n).should == @zero + end + BigDecimal("1E10").floor(-30).should == @zero + BigDecimal("-1E10").floor(-30).should == BigDecimal('-1E30') end + end diff --git a/spec/ruby/library/bigdecimal/frac_spec.rb b/spec/ruby/library/bigdecimal/frac_spec.rb index 9cf72d313ec..11ccf03c2f0 100644 --- a/spec/ruby/library/bigdecimal/frac_spec.rb +++ b/spec/ruby/library/bigdecimal/frac_spec.rb @@ -1,51 +1,48 @@ require_relative '../../spec_helper' +require 'bigdecimal' + +describe "BigDecimal#frac" 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 -ruby_version_is ""..."3.4" do - require 'bigdecimal' - - describe "BigDecimal#frac" 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 - - it "returns a BigDecimal" do - @pos_int.frac.kind_of?(BigDecimal).should == true - @neg_int.frac.kind_of?(BigDecimal).should == true - @pos_frac.kind_of?(BigDecimal).should == true - @neg_frac.kind_of?(BigDecimal).should == true - end - - it "returns the fractional part of the absolute value" do - @mixed.frac.should == BigDecimal("0.23456789") - @pos_frac.frac.should == @pos_frac - @neg_frac.frac.should == @neg_frac - end - - it "returns 0 if the value is 0" do - @zero.frac.should == @zero - end - - it "returns 0 if the value is an integer" do - @pos_int.frac.should == @zero - @neg_int.frac.should == @zero - end - - it "correctly handles special values" do - @infinity.frac.should == @infinity - @infinity_neg.frac.should == @infinity_neg - @nan.frac.should.nan? - end + it "returns a BigDecimal" do + @pos_int.frac.kind_of?(BigDecimal).should == true + @neg_int.frac.kind_of?(BigDecimal).should == true + @pos_frac.kind_of?(BigDecimal).should == true + @neg_frac.kind_of?(BigDecimal).should == true + end + it "returns the fractional part of the absolute value" do + @mixed.frac.should == BigDecimal("0.23456789") + @pos_frac.frac.should == @pos_frac + @neg_frac.frac.should == @neg_frac end + + it "returns 0 if the value is 0" do + @zero.frac.should == @zero + end + + it "returns 0 if the value is an integer" do + @pos_int.frac.should == @zero + @neg_int.frac.should == @zero + end + + it "correctly handles special values" do + @infinity.frac.should == @infinity + @infinity_neg.frac.should == @infinity_neg + @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 2af84673d38..78547fb85f1 100644 --- a/spec/ruby/library/bigdecimal/gt_spec.rb +++ b/spec/ruby/library/bigdecimal/gt_spec.rb @@ -1,99 +1,96 @@ require_relative '../../spec_helper' +require 'bigdecimal' -ruby_version_is ""..."3.4" do - require 'bigdecimal' +describe "BigDecimal#>" do + before :each do + @zero = BigDecimal("0") + @zero_pos = BigDecimal("+0") + @zero_neg = BigDecimal("-0") + @mixed = BigDecimal("1.23456789") + @pos_int = BigDecimal("2E5555") + @neg_int = BigDecimal("-2E5555") + @pos_frac = BigDecimal("2E-9999") + @neg_frac = BigDecimal("-2E-9999") - describe "BigDecimal#>" do - before :each do - @zero = BigDecimal("0") - @zero_pos = BigDecimal("+0") - @zero_neg = BigDecimal("-0") - @mixed = BigDecimal("1.23456789") - @pos_int = BigDecimal("2E5555") - @neg_int = BigDecimal("-2E5555") - @pos_frac = BigDecimal("2E-9999") - @neg_frac = BigDecimal("-2E-9999") - - @int_mock = mock('123') - class << @int_mock - def coerce(other) - return [other, BigDecimal('123')] - end - def >(other) - BigDecimal('123') > other - end + @int_mock = mock('123') + class << @int_mock + def coerce(other) + return [other, BigDecimal('123')] + end + def >(other) + BigDecimal('123') > other end + end - @values = [@mixed, @pos_int, @neg_int, @pos_frac, @neg_frac, - -2**32, -2**31, -2**30, -2**16, -2**8, -100, -10, -1, - @zero , 1, 2, 10, 10.5, 2**8, 2**16, 2**32, @int_mock, @zero_pos, @zero_neg] + @values = [@mixed, @pos_int, @neg_int, @pos_frac, @neg_frac, + -2**32, -2**31, -2**30, -2**16, -2**8, -100, -10, -1, + @zero , 1, 2, 10, 10.5, 2**8, 2**16, 2**32, @int_mock, @zero_pos, @zero_neg] - @infinity = BigDecimal("Infinity") - @infinity_neg = BigDecimal("-Infinity") + @infinity = BigDecimal("Infinity") + @infinity_neg = BigDecimal("-Infinity") - @float_infinity = Float::INFINITY - @float_infinity_neg = -Float::INFINITY + @float_infinity = Float::INFINITY + @float_infinity_neg = -Float::INFINITY - @nan = BigDecimal("NaN") - end + @nan = BigDecimal("NaN") + end - it "returns true if a > b" do - one = BigDecimal("1") - two = BigDecimal("2") + it "returns true if a > b" do + one = BigDecimal("1") + two = BigDecimal("2") - frac_1 = BigDecimal("1E-99999") - frac_2 = BigDecimal("0.9E-99999") - (@zero > one).should == false - (two > @zero).should == true - (frac_2 > frac_1).should == false + frac_1 = BigDecimal("1E-99999") + frac_2 = BigDecimal("0.9E-99999") + (@zero > one).should == false + (two > @zero).should == true + (frac_2 > frac_1).should == false - (@neg_int > @pos_int).should == false - (@pos_int > @neg_int).should == true - (@neg_int > @pos_frac).should == false - (@pos_frac > @neg_int).should == true - (@zero > @zero_pos).should == false - (@zero > @zero_neg).should == false - (@zero_neg > @zero_pos).should == false - (@zero_pos > @zero_neg).should == false - end + (@neg_int > @pos_int).should == false + (@pos_int > @neg_int).should == true + (@neg_int > @pos_frac).should == false + (@pos_frac > @neg_int).should == true + (@zero > @zero_pos).should == false + (@zero > @zero_neg).should == false + (@zero_neg > @zero_pos).should == false + (@zero_pos > @zero_neg).should == false + end - it "properly handles infinity values" do - @values.each { |val| - (val > @infinity).should == false - (@infinity > val).should == true - (val > @infinity_neg).should == true - (@infinity_neg > val).should == false - } - (@infinity > @infinity).should == false - (@infinity_neg > @infinity_neg).should == false - (@infinity > @infinity_neg).should == true - (@infinity_neg > @infinity).should == false - end + it "properly handles infinity values" do + @values.each { |val| + (val > @infinity).should == false + (@infinity > val).should == true + (val > @infinity_neg).should == true + (@infinity_neg > val).should == false + } + (@infinity > @infinity).should == false + (@infinity_neg > @infinity_neg).should == false + (@infinity > @infinity_neg).should == true + (@infinity_neg > @infinity).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 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 - @values += [@infinity, @infinity_neg, @nan] - @values.each { |val| - (@nan > val).should == false - (val > @nan).should == false - } - end + it "properly handles NaN values" do + @values += [@infinity, @infinity_neg, @nan] + @values.each { |val| + (@nan > val).should == false + (val > @nan).should == false + } + end - it "raises an ArgumentError if the argument can't be coerced into a BigDecimal" do - -> {@zero > nil }.should raise_error(ArgumentError) - -> {@infinity > nil }.should raise_error(ArgumentError) - -> {@infinity_neg > nil }.should raise_error(ArgumentError) - -> {@mixed > nil }.should raise_error(ArgumentError) - -> {@pos_int > nil }.should raise_error(ArgumentError) - -> {@neg_frac > nil }.should raise_error(ArgumentError) - end + it "raises an ArgumentError if the argument can't be coerced into a BigDecimal" do + -> {@zero > nil }.should raise_error(ArgumentError) + -> {@infinity > nil }.should raise_error(ArgumentError) + -> {@infinity_neg > nil }.should raise_error(ArgumentError) + -> {@mixed > nil }.should raise_error(ArgumentError) + -> {@pos_int > nil }.should raise_error(ArgumentError) + -> {@neg_frac > nil }.should raise_error(ArgumentError) end end diff --git a/spec/ruby/library/bigdecimal/gte_spec.rb b/spec/ruby/library/bigdecimal/gte_spec.rb index 1f9838bf25b..2a5cc025ba3 100644 --- a/spec/ruby/library/bigdecimal/gte_spec.rb +++ b/spec/ruby/library/bigdecimal/gte_spec.rb @@ -1,103 +1,100 @@ require_relative '../../spec_helper' - -ruby_version_is ""..."3.4" do - require 'bigdecimal' - - describe "BigDecimal#>=" do - before :each do - @zero = BigDecimal("0") - @zero_pos = BigDecimal("+0") - @zero_neg = BigDecimal("-0") - @mixed = BigDecimal("1.23456789") - @pos_int = BigDecimal("2E5555") - @neg_int = BigDecimal("-2E5555") - @pos_frac = BigDecimal("2E-9999") - @neg_frac = BigDecimal("-2E-9999") - - @int_mock = mock('123') - class << @int_mock - def coerce(other) - return [other, BigDecimal('123')] - end - def >=(other) - BigDecimal('123') >= other - end +require 'bigdecimal' + +describe "BigDecimal#>=" do + before :each do + @zero = BigDecimal("0") + @zero_pos = BigDecimal("+0") + @zero_neg = BigDecimal("-0") + @mixed = BigDecimal("1.23456789") + @pos_int = BigDecimal("2E5555") + @neg_int = BigDecimal("-2E5555") + @pos_frac = BigDecimal("2E-9999") + @neg_frac = BigDecimal("-2E-9999") + + @int_mock = mock('123') + class << @int_mock + def coerce(other) + return [other, BigDecimal('123')] + end + def >=(other) + BigDecimal('123') >= other end + end - @values = [@mixed, @pos_int, @neg_int, @pos_frac, @neg_frac, - -2**32, -2**31, -2**30, -2**16, -2**8, -100, -10, -1, - @zero , 1, 2, 10, 10.5, 2**8, 2**16, 2**32, @int_mock, @zero_pos, @zero_neg] + @values = [@mixed, @pos_int, @neg_int, @pos_frac, @neg_frac, + -2**32, -2**31, -2**30, -2**16, -2**8, -100, -10, -1, + @zero , 1, 2, 10, 10.5, 2**8, 2**16, 2**32, @int_mock, @zero_pos, @zero_neg] - @infinity = BigDecimal("Infinity") - @infinity_neg = BigDecimal("-Infinity") + @infinity = BigDecimal("Infinity") + @infinity_neg = BigDecimal("-Infinity") - @float_infinity = Float::INFINITY - @float_infinity_neg = -Float::INFINITY + @float_infinity = Float::INFINITY + @float_infinity_neg = -Float::INFINITY - @nan = BigDecimal("NaN") - end + @nan = BigDecimal("NaN") + end - it "returns true if a >= b" do - one = BigDecimal("1") - two = BigDecimal("2") + it "returns true if a >= b" do + one = BigDecimal("1") + two = BigDecimal("2") - frac_1 = BigDecimal("1E-99999") - frac_2 = BigDecimal("0.9E-99999") + frac_1 = BigDecimal("1E-99999") + frac_2 = BigDecimal("0.9E-99999") - (@zero >= one).should == false - (two >= @zero).should == true + (@zero >= one).should == false + (two >= @zero).should == true - (frac_2 >= frac_1).should == false - (two >= two).should == true - (frac_1 >= frac_1).should == true + (frac_2 >= frac_1).should == false + (two >= two).should == true + (frac_1 >= frac_1).should == true - (@neg_int >= @pos_int).should == false - (@pos_int >= @neg_int).should == true - (@neg_int >= @pos_frac).should == false - (@pos_frac >= @neg_int).should == true - (@zero >= @zero_pos).should == true - (@zero >= @zero_neg).should == true - (@zero_neg >= @zero_pos).should == true - (@zero_pos >= @zero_neg).should == true - end + (@neg_int >= @pos_int).should == false + (@pos_int >= @neg_int).should == true + (@neg_int >= @pos_frac).should == false + (@pos_frac >= @neg_int).should == true + (@zero >= @zero_pos).should == true + (@zero >= @zero_neg).should == true + (@zero_neg >= @zero_pos).should == true + (@zero_pos >= @zero_neg).should == true + end - it "properly handles infinity values" do - @values.each { |val| - (val >= @infinity).should == false - (@infinity >= val).should == true - (val >= @infinity_neg).should == true - (@infinity_neg >= val).should == false - } - (@infinity >= @infinity).should == true - (@infinity_neg >= @infinity_neg).should == true - (@infinity >= @infinity_neg).should == true - (@infinity_neg >= @infinity).should == false - end + it "properly handles infinity values" do + @values.each { |val| + (val >= @infinity).should == false + (@infinity >= val).should == true + (val >= @infinity_neg).should == true + (@infinity_neg >= val).should == false + } + (@infinity >= @infinity).should == true + (@infinity_neg >= @infinity_neg).should == true + (@infinity >= @infinity_neg).should == true + (@infinity_neg >= @infinity).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 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 - @values += [@infinity, @infinity_neg, @nan] - @values.each { |val| - (@nan >= val).should == false - (val >= @nan).should == false - } - end + it "properly handles NaN values" do + @values += [@infinity, @infinity_neg, @nan] + @values.each { |val| + (@nan >= val).should == false + (val >= @nan).should == false + } + end - it "returns nil if the argument is nil" do - -> {@zero >= nil }.should raise_error(ArgumentError) - -> {@infinity >= nil }.should raise_error(ArgumentError) - -> {@infinity_neg >= nil }.should raise_error(ArgumentError) - -> {@mixed >= nil }.should raise_error(ArgumentError) - -> {@pos_int >= nil }.should raise_error(ArgumentError) - -> {@neg_frac >= nil }.should raise_error(ArgumentError) - end + it "returns nil if the argument is nil" do + -> {@zero >= nil }.should raise_error(ArgumentError) + -> {@infinity >= nil }.should raise_error(ArgumentError) + -> {@infinity_neg >= nil }.should raise_error(ArgumentError) + -> {@mixed >= nil }.should raise_error(ArgumentError) + -> {@pos_int >= nil }.should raise_error(ArgumentError) + -> {@neg_frac >= nil }.should raise_error(ArgumentError) end end diff --git a/spec/ruby/library/bigdecimal/hash_spec.rb b/spec/ruby/library/bigdecimal/hash_spec.rb index 7eea0f6464d..7581c90f681 100644 --- a/spec/ruby/library/bigdecimal/hash_spec.rb +++ b/spec/ruby/library/bigdecimal/hash_spec.rb @@ -1,33 +1,30 @@ require_relative '../../spec_helper' +require 'bigdecimal' -ruby_version_is ""..."3.4" do - 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 +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 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 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 + 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 + 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 79a451d8577..025386107f6 100644 --- a/spec/ruby/library/bigdecimal/infinite_spec.rb +++ b/spec/ruby/library/bigdecimal/infinite_spec.rb @@ -1,35 +1,32 @@ require_relative '../../spec_helper' +require 'bigdecimal' -ruby_version_is ""..."3.4" do - require 'bigdecimal' +describe "BigDecimal#infinite?" do - describe "BigDecimal#infinite?" do - - it "returns 1 if self is Infinity" do - BigDecimal("Infinity").infinite?.should == 1 - end - - it "returns -1 if self is -Infinity" do - BigDecimal("-Infinity").infinite?.should == -1 - end + it "returns 1 if self is Infinity" do + BigDecimal("Infinity").infinite?.should == 1 + end - it "returns not true otherwise" do - e2_plus = BigDecimal("2E40001") - e3_minus = BigDecimal("3E-20001") - really_small_zero = BigDecimal("0E-200000000") - really_big_zero = BigDecimal("0E200000000000") - e3_minus.infinite?.should == nil - e2_plus.infinite?.should == nil - really_small_zero.infinite?.should == nil - really_big_zero.infinite?.should == nil - BigDecimal("0.000000000000000000000000").infinite?.should == nil - end + it "returns -1 if self is -Infinity" do + BigDecimal("-Infinity").infinite?.should == -1 + end - it "returns not true if self is NaN" do - # NaN is a special value which is neither finite nor infinite. - nan = BigDecimal("NaN") - nan.infinite?.should == nil - end + it "returns not true otherwise" do + e2_plus = BigDecimal("2E40001") + e3_minus = BigDecimal("3E-20001") + really_small_zero = BigDecimal("0E-200000000") + really_big_zero = BigDecimal("0E200000000000") + e3_minus.infinite?.should == nil + e2_plus.infinite?.should == nil + really_small_zero.infinite?.should == nil + really_big_zero.infinite?.should == nil + BigDecimal("0.000000000000000000000000").infinite?.should == nil + end + it "returns not true if self is NaN" do + # NaN is a special value which is neither finite nor infinite. + nan = BigDecimal("NaN") + nan.infinite?.should == nil end + end diff --git a/spec/ruby/library/bigdecimal/inspect_spec.rb b/spec/ruby/library/bigdecimal/inspect_spec.rb index a6f72f759f3..7ce47142b2b 100644 --- a/spec/ruby/library/bigdecimal/inspect_spec.rb +++ b/spec/ruby/library/bigdecimal/inspect_spec.rb @@ -1,33 +1,30 @@ require_relative '../../spec_helper' +require 'bigdecimal' -ruby_version_is ""..."3.4" do - require 'bigdecimal' +describe "BigDecimal#inspect" do - describe "BigDecimal#inspect" do - - before :each do - @bigdec = BigDecimal("1234.5678") - end + before :each do + @bigdec = BigDecimal("1234.5678") + end - it "returns String" do - @bigdec.inspect.kind_of?(String).should == true - end + it "returns String" do + @bigdec.inspect.kind_of?(String).should == true + end - it "looks like this" do - @bigdec.inspect.should == "0.12345678e4" - end + it "looks like this" do + @bigdec.inspect.should == "0.12345678e4" + 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 + 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 - 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 + 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 c1d130d4ec5..75cbc8b55c9 100644 --- a/spec/ruby/library/bigdecimal/limit_spec.rb +++ b/spec/ruby/library/bigdecimal/limit_spec.rb @@ -1,58 +1,55 @@ require_relative '../../spec_helper' +require_relative 'fixtures/classes' +require 'bigdecimal' + +describe "BigDecimal.limit" do + it "returns the value before set if the passed argument is nil or is not specified" do + old = BigDecimal.limit + BigDecimal.limit.should == 0 + BigDecimal.limit(10).should == 0 + BigDecimal.limit.should == 10 + BigDecimal.limit(old) + end -ruby_version_is ""..."3.4" do - require_relative 'fixtures/classes' - require 'bigdecimal' - - describe "BigDecimal.limit" do - it "returns the value before set if the passed argument is nil or is not specified" do - old = BigDecimal.limit - BigDecimal.limit.should == 0 - BigDecimal.limit(10).should == 0 - BigDecimal.limit.should == 10 - BigDecimal.limit(old) + 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 - 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 + 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 - 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 + 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 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 + 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 7cffb12f7b9..02390e76e33 100644 --- a/spec/ruby/library/bigdecimal/lt_spec.rb +++ b/spec/ruby/library/bigdecimal/lt_spec.rb @@ -1,97 +1,94 @@ require_relative '../../spec_helper' +require 'bigdecimal' -ruby_version_is ""..."3.4" do - require 'bigdecimal' +describe "BigDecimal#<" do + before :each do + @zero = BigDecimal("0") + @zero_pos = BigDecimal("+0") + @zero_neg = BigDecimal("-0") + @mixed = BigDecimal("1.23456789") + @pos_int = BigDecimal("2E5555") + @neg_int = BigDecimal("-2E5555") + @pos_frac = BigDecimal("2E-9999") + @neg_frac = BigDecimal("-2E-9999") - describe "BigDecimal#<" do - before :each do - @zero = BigDecimal("0") - @zero_pos = BigDecimal("+0") - @zero_neg = BigDecimal("-0") - @mixed = BigDecimal("1.23456789") - @pos_int = BigDecimal("2E5555") - @neg_int = BigDecimal("-2E5555") - @pos_frac = BigDecimal("2E-9999") - @neg_frac = BigDecimal("-2E-9999") - - @int_mock = mock('123') - class << @int_mock - def coerce(other) - return [other, BigDecimal('123')] - end - def <(other) - BigDecimal('123') < other - end + @int_mock = mock('123') + class << @int_mock + def coerce(other) + return [other, BigDecimal('123')] + end + def <(other) + BigDecimal('123') < other end + end - @values = [@mixed, @pos_int, @neg_int, @pos_frac, @neg_frac, - -2**32, -2**31, -2**30, -2**16, -2**8, -100, -10, -1, - @zero , 1, 2, 10, 10.5, 2**8, 2**16, 2**32, @int_mock, @zero_pos, @zero_neg] + @values = [@mixed, @pos_int, @neg_int, @pos_frac, @neg_frac, + -2**32, -2**31, -2**30, -2**16, -2**8, -100, -10, -1, + @zero , 1, 2, 10, 10.5, 2**8, 2**16, 2**32, @int_mock, @zero_pos, @zero_neg] - @infinity = BigDecimal("Infinity") - @infinity_neg = BigDecimal("-Infinity") + @infinity = BigDecimal("Infinity") + @infinity_neg = BigDecimal("-Infinity") - @float_infinity = Float::INFINITY - @float_infinity_neg = -Float::INFINITY + @float_infinity = Float::INFINITY + @float_infinity_neg = -Float::INFINITY - @nan = BigDecimal("NaN") - end + @nan = BigDecimal("NaN") + end - it "returns true if a < b" do - one = BigDecimal("1") - two = BigDecimal("2") - frac_1 = BigDecimal("1E-99999") - frac_2 = BigDecimal("0.9E-99999") - (@zero < one).should == true - (two < @zero).should == false - (frac_2 < frac_1).should == true - (@neg_int < @pos_int).should == true - (@pos_int < @neg_int).should == false - (@neg_int < @pos_frac).should == true - (@pos_frac < @neg_int).should == false - (@zero < @zero_pos).should == false - (@zero < @zero_neg).should == false - (@zero_neg < @zero_pos).should == false - (@zero_pos < @zero_neg).should == false - end + it "returns true if a < b" do + one = BigDecimal("1") + two = BigDecimal("2") + frac_1 = BigDecimal("1E-99999") + frac_2 = BigDecimal("0.9E-99999") + (@zero < one).should == true + (two < @zero).should == false + (frac_2 < frac_1).should == true + (@neg_int < @pos_int).should == true + (@pos_int < @neg_int).should == false + (@neg_int < @pos_frac).should == true + (@pos_frac < @neg_int).should == false + (@zero < @zero_pos).should == false + (@zero < @zero_neg).should == false + (@zero_neg < @zero_pos).should == false + (@zero_pos < @zero_neg).should == false + end - it "properly handles infinity values" do - @values.each { |val| - (val < @infinity).should == true - (@infinity < val).should == false - (val < @infinity_neg).should == false - (@infinity_neg < val).should == true - } - (@infinity < @infinity).should == false - (@infinity_neg < @infinity_neg).should == false - (@infinity < @infinity_neg).should == false - (@infinity_neg < @infinity).should == true - end + it "properly handles infinity values" do + @values.each { |val| + (val < @infinity).should == true + (@infinity < val).should == false + (val < @infinity_neg).should == false + (@infinity_neg < val).should == true + } + (@infinity < @infinity).should == false + (@infinity_neg < @infinity_neg).should == false + (@infinity < @infinity_neg).should == false + (@infinity_neg < @infinity).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 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 - @values += [@infinity, @infinity_neg, @nan] - @values.each { |val| - (@nan < val).should == false - (val < @nan).should == false - } - end + it "properly handles NaN values" do + @values += [@infinity, @infinity_neg, @nan] + @values.each { |val| + (@nan < val).should == false + (val < @nan).should == false + } + end - it "raises an ArgumentError if the argument can't be coerced into a BigDecimal" do - -> {@zero < nil }.should raise_error(ArgumentError) - -> {@infinity < nil }.should raise_error(ArgumentError) - -> {@infinity_neg < nil }.should raise_error(ArgumentError) - -> {@mixed < nil }.should raise_error(ArgumentError) - -> {@pos_int < nil }.should raise_error(ArgumentError) - -> {@neg_frac < nil }.should raise_error(ArgumentError) - end + it "raises an ArgumentError if the argument can't be coerced into a BigDecimal" do + -> {@zero < nil }.should raise_error(ArgumentError) + -> {@infinity < nil }.should raise_error(ArgumentError) + -> {@infinity_neg < nil }.should raise_error(ArgumentError) + -> {@mixed < nil }.should raise_error(ArgumentError) + -> {@pos_int < nil }.should raise_error(ArgumentError) + -> {@neg_frac < nil }.should raise_error(ArgumentError) end end diff --git a/spec/ruby/library/bigdecimal/lte_spec.rb b/spec/ruby/library/bigdecimal/lte_spec.rb index 2dc6bdc9437..b92be04123f 100644 --- a/spec/ruby/library/bigdecimal/lte_spec.rb +++ b/spec/ruby/library/bigdecimal/lte_spec.rb @@ -1,103 +1,100 @@ require_relative '../../spec_helper' - -ruby_version_is ""..."3.4" do - require 'bigdecimal' - - describe "BigDecimal#<=" do - before :each do - @zero = BigDecimal("0") - @zero_pos = BigDecimal("+0") - @zero_neg = BigDecimal("-0") - @mixed = BigDecimal("1.23456789") - @pos_int = BigDecimal("2E5555") - @neg_int = BigDecimal("-2E5555") - @pos_frac = BigDecimal("2E-9999") - @neg_frac = BigDecimal("-2E-9999") - - @int_mock = mock('123') - class << @int_mock - def coerce(other) - return [other, BigDecimal('123')] - end - def <=(other) - BigDecimal('123') <= other - end +require 'bigdecimal' + +describe "BigDecimal#<=" do + before :each do + @zero = BigDecimal("0") + @zero_pos = BigDecimal("+0") + @zero_neg = BigDecimal("-0") + @mixed = BigDecimal("1.23456789") + @pos_int = BigDecimal("2E5555") + @neg_int = BigDecimal("-2E5555") + @pos_frac = BigDecimal("2E-9999") + @neg_frac = BigDecimal("-2E-9999") + + @int_mock = mock('123') + class << @int_mock + def coerce(other) + return [other, BigDecimal('123')] + end + def <=(other) + BigDecimal('123') <= other end + end - @values = [@mixed, @pos_int, @neg_int, @pos_frac, @neg_frac, - -2**32, -2**31, -2**30, -2**16, -2**8, -100, -10, -1, - @zero , 1, 2, 10, 10.5, 2**8, 2**16, 2**32, @int_mock, @zero_pos, @zero_neg] + @values = [@mixed, @pos_int, @neg_int, @pos_frac, @neg_frac, + -2**32, -2**31, -2**30, -2**16, -2**8, -100, -10, -1, + @zero , 1, 2, 10, 10.5, 2**8, 2**16, 2**32, @int_mock, @zero_pos, @zero_neg] - @infinity = BigDecimal("Infinity") - @infinity_neg = BigDecimal("-Infinity") + @infinity = BigDecimal("Infinity") + @infinity_neg = BigDecimal("-Infinity") - @float_infinity = Float::INFINITY - @float_infinity_neg = -Float::INFINITY + @float_infinity = Float::INFINITY + @float_infinity_neg = -Float::INFINITY - @nan = BigDecimal("NaN") - end + @nan = BigDecimal("NaN") + end - it "returns true if a <= b" do - one = BigDecimal("1") - two = BigDecimal("2") + it "returns true if a <= b" do + one = BigDecimal("1") + two = BigDecimal("2") - frac_1 = BigDecimal("1E-99999") - frac_2 = BigDecimal("0.9E-99999") + frac_1 = BigDecimal("1E-99999") + frac_2 = BigDecimal("0.9E-99999") - (@zero <= one).should == true - (two <= @zero).should == false + (@zero <= one).should == true + (two <= @zero).should == false - (frac_2 <= frac_1).should == true - (two <= two).should == true - (frac_1 <= frac_1).should == true + (frac_2 <= frac_1).should == true + (two <= two).should == true + (frac_1 <= frac_1).should == true - (@neg_int <= @pos_int).should == true - (@pos_int <= @neg_int).should == false - (@neg_int <= @pos_frac).should == true - (@pos_frac <= @neg_int).should == false - (@zero <= @zero_pos).should == true - (@zero <= @zero_neg).should == true - (@zero_neg <= @zero_pos).should == true - (@zero_pos <= @zero_neg).should == true - end + (@neg_int <= @pos_int).should == true + (@pos_int <= @neg_int).should == false + (@neg_int <= @pos_frac).should == true + (@pos_frac <= @neg_int).should == false + (@zero <= @zero_pos).should == true + (@zero <= @zero_neg).should == true + (@zero_neg <= @zero_pos).should == true + (@zero_pos <= @zero_neg).should == true + end - it "properly handles infinity values" do - @values.each { |val| - (val <= @infinity).should == true - (@infinity <= val).should == false - (val <= @infinity_neg).should == false - (@infinity_neg <= val).should == true - } - (@infinity <= @infinity).should == true - (@infinity_neg <= @infinity_neg).should == true - (@infinity <= @infinity_neg).should == false - (@infinity_neg <= @infinity).should == true - end + it "properly handles infinity values" do + @values.each { |val| + (val <= @infinity).should == true + (@infinity <= val).should == false + (val <= @infinity_neg).should == false + (@infinity_neg <= val).should == true + } + (@infinity <= @infinity).should == true + (@infinity_neg <= @infinity_neg).should == true + (@infinity <= @infinity_neg).should == false + (@infinity_neg <= @infinity).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 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 - @values += [@infinity, @infinity_neg, @nan] - @values.each { |val| - (@nan <= val).should == false - (val <= @nan).should == false - } - end + it "properly handles NaN values" do + @values += [@infinity, @infinity_neg, @nan] + @values.each { |val| + (@nan <= val).should == false + (val <= @nan).should == false + } + end - it "raises an ArgumentError if the argument can't be coerced into a BigDecimal" do - -> {@zero <= nil }.should raise_error(ArgumentError) - -> {@infinity <= nil }.should raise_error(ArgumentError) - -> {@infinity_neg <= nil }.should raise_error(ArgumentError) - -> {@mixed <= nil }.should raise_error(ArgumentError) - -> {@pos_int <= nil }.should raise_error(ArgumentError) - -> {@neg_frac <= nil }.should raise_error(ArgumentError) - end + it "raises an ArgumentError if the argument can't be coerced into a BigDecimal" do + -> {@zero <= nil }.should raise_error(ArgumentError) + -> {@infinity <= nil }.should raise_error(ArgumentError) + -> {@infinity_neg <= nil }.should raise_error(ArgumentError) + -> {@mixed <= nil }.should raise_error(ArgumentError) + -> {@pos_int <= nil }.should raise_error(ArgumentError) + -> {@neg_frac <= nil }.should raise_error(ArgumentError) end end diff --git a/spec/ruby/library/bigdecimal/minus_spec.rb b/spec/ruby/library/bigdecimal/minus_spec.rb index e65b9bcffc9..bd3c19584b8 100644 --- a/spec/ruby/library/bigdecimal/minus_spec.rb +++ b/spec/ruby/library/bigdecimal/minus_spec.rb @@ -1,69 +1,66 @@ require_relative '../../spec_helper' +require 'bigdecimal' -ruby_version_is ""..."3.4" do - require 'bigdecimal' +describe "BigDecimal#-" do - describe "BigDecimal#-" do - - before :each do - @one = BigDecimal("1") - @zero = BigDecimal("0") - @two = BigDecimal("2") - @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") - end + before :each do + @one = BigDecimal("1") + @zero = BigDecimal("0") + @two = BigDecimal("2") + @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") + end - it "returns a - b" do - (@two - @one).should == @one - (@one - @two).should == @one_minus - (@one - @one_minus).should == @two - (@frac_2 - @frac_1).should == BigDecimal("-0.1E-99999") - (@two - @two).should == @zero - (@frac_1 - @frac_1).should == @zero - (BigDecimal('1.23456789') - BigDecimal('1.2')).should == BigDecimal("0.03456789") - end + it "returns a - b" do + (@two - @one).should == @one + (@one - @two).should == @one_minus + (@one - @one_minus).should == @two + (@frac_2 - @frac_1).should == BigDecimal("-0.1E-99999") + (@two - @two).should == @zero + (@frac_1 - @frac_1).should == @zero + (BigDecimal('1.23456789') - BigDecimal('1.2')).should == BigDecimal("0.03456789") + end - it "returns NaN if NaN is involved" do - (@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 if NaN is involved" do + (@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).should.nan? - (@infinity_minus - @infinity_minus).should.nan? - end + it "returns NaN both operands are infinite with the same sign" do + (@infinity - @infinity).should.nan? + (@infinity_minus - @infinity_minus).should.nan? + end - it "returns Infinity or -Infinity if these are involved" do - (@infinity - @infinity_minus).should == @infinity - (@infinity_minus - @infinity).should == @infinity_minus + it "returns Infinity or -Infinity if these are involved" do + (@infinity - @infinity_minus).should == @infinity + (@infinity_minus - @infinity).should == @infinity_minus - (@infinity - @zero).should == @infinity - (@infinity - @frac_2).should == @infinity - (@infinity - @two).should == @infinity - (@infinity - @one_minus).should == @infinity + (@infinity - @zero).should == @infinity + (@infinity - @frac_2).should == @infinity + (@infinity - @two).should == @infinity + (@infinity - @one_minus).should == @infinity - (@zero - @infinity).should == @infinity_minus - (@frac_2 - @infinity).should == @infinity_minus - (@two - @infinity).should == @infinity_minus - (@one_minus - @infinity).should == @infinity_minus - end + (@zero - @infinity).should == @infinity_minus + (@frac_2 - @infinity).should == @infinity_minus + (@two - @infinity).should == @infinity_minus + (@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 + 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 62aeb773573..73fa1a118ea 100644 --- a/spec/ruby/library/bigdecimal/mode_spec.rb +++ b/spec/ruby/library/bigdecimal/mode_spec.rb @@ -1,39 +1,36 @@ require_relative '../../spec_helper' +require 'bigdecimal' -ruby_version_is ""..."3.4" do - require 'bigdecimal' - - describe "BigDecimal.mode" do - #the default value of BigDecimal exception constants is false - after :each do - BigDecimal.mode(BigDecimal::EXCEPTION_NaN, false) - BigDecimal.mode(BigDecimal::EXCEPTION_INFINITY, false) - BigDecimal.mode(BigDecimal::EXCEPTION_UNDERFLOW, false) - BigDecimal.mode(BigDecimal::EXCEPTION_OVERFLOW, false) - BigDecimal.mode(BigDecimal::EXCEPTION_ZERODIVIDE, false) - end +describe "BigDecimal.mode" do + #the default value of BigDecimal exception constants is false + after :each do + BigDecimal.mode(BigDecimal::EXCEPTION_NaN, false) + BigDecimal.mode(BigDecimal::EXCEPTION_INFINITY, false) + BigDecimal.mode(BigDecimal::EXCEPTION_UNDERFLOW, false) + BigDecimal.mode(BigDecimal::EXCEPTION_OVERFLOW, false) + BigDecimal.mode(BigDecimal::EXCEPTION_ZERODIVIDE, false) + end - it "returns the appropriate value and continue the computation if the flag is false" do - 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 + it "returns the appropriate value and continue the computation if the flag is false" do + 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 - it "returns Infinity when too big" do - BigDecimal("1E11111111111111111111").should == BigDecimal("Infinity") - (BigDecimal("1E1000000000000000000")**10).should == BigDecimal("Infinity") - end + it "returns Infinity when too big" do + BigDecimal("1E11111111111111111111").should == BigDecimal("Infinity") + (BigDecimal("1E1000000000000000000")**10).should == BigDecimal("Infinity") + end - it "raise an exception if the flag is true" do - BigDecimal.mode(BigDecimal::EXCEPTION_NaN, true) - -> { BigDecimal("NaN").add(BigDecimal("1"),0) }.should raise_error(FloatDomainError) - BigDecimal.mode(BigDecimal::EXCEPTION_INFINITY, true) - -> { BigDecimal("0").add(BigDecimal("Infinity"),0) }.should raise_error(FloatDomainError) - BigDecimal.mode(BigDecimal::EXCEPTION_ZERODIVIDE, true) - -> { BigDecimal("1").quo(BigDecimal("0")) }.should raise_error(FloatDomainError) - BigDecimal.mode(BigDecimal::EXCEPTION_OVERFLOW, true) - -> { BigDecimal("1E11111111111111111111") }.should raise_error(FloatDomainError) - -> { (BigDecimal("1E1000000000000000000")**10) }.should raise_error(FloatDomainError) - end + it "raise an exception if the flag is true" do + BigDecimal.mode(BigDecimal::EXCEPTION_NaN, true) + -> { BigDecimal("NaN").add(BigDecimal("1"),0) }.should raise_error(FloatDomainError) + BigDecimal.mode(BigDecimal::EXCEPTION_INFINITY, true) + -> { BigDecimal("0").add(BigDecimal("Infinity"),0) }.should raise_error(FloatDomainError) + BigDecimal.mode(BigDecimal::EXCEPTION_ZERODIVIDE, true) + -> { BigDecimal("1").quo(BigDecimal("0")) }.should raise_error(FloatDomainError) + BigDecimal.mode(BigDecimal::EXCEPTION_OVERFLOW, true) + -> { BigDecimal("1E11111111111111111111") }.should raise_error(FloatDomainError) + -> { (BigDecimal("1E1000000000000000000")**10) }.should raise_error(FloatDomainError) end end diff --git a/spec/ruby/library/bigdecimal/modulo_spec.rb b/spec/ruby/library/bigdecimal/modulo_spec.rb index 682b9ec334f..035d31bd982 100644 --- a/spec/ruby/library/bigdecimal/modulo_spec.rb +++ b/spec/ruby/library/bigdecimal/modulo_spec.rb @@ -1,15 +1,12 @@ require_relative '../../spec_helper' +require_relative 'shared/modulo' -ruby_version_is ""..."3.4" do - require_relative 'shared/modulo' - - describe "BigDecimal#%" do - it_behaves_like :bigdecimal_modulo, :% - it_behaves_like :bigdecimal_modulo_zerodivisionerror, :% - end +describe "BigDecimal#%" do + it_behaves_like :bigdecimal_modulo, :% + it_behaves_like :bigdecimal_modulo_zerodivisionerror, :% +end - describe "BigDecimal#modulo" do - it_behaves_like :bigdecimal_modulo, :modulo - it_behaves_like :bigdecimal_modulo_zerodivisionerror, :modulo - end +describe "BigDecimal#modulo" do + it_behaves_like :bigdecimal_modulo, :modulo + it_behaves_like :bigdecimal_modulo_zerodivisionerror, :modulo end diff --git a/spec/ruby/library/bigdecimal/mult_spec.rb b/spec/ruby/library/bigdecimal/mult_spec.rb index 29cb0c226d9..b7f8044b0b2 100644 --- a/spec/ruby/library/bigdecimal/mult_spec.rb +++ b/spec/ruby/library/bigdecimal/mult_spec.rb @@ -1,35 +1,32 @@ require_relative '../../spec_helper' +require_relative 'shared/mult' +require 'bigdecimal' -ruby_version_is ""..."3.4" do - require_relative 'shared/mult' - require 'bigdecimal' - - describe "BigDecimal#mult" do - it_behaves_like :bigdecimal_mult, :mult, [10] - end +describe "BigDecimal#mult" do + it_behaves_like :bigdecimal_mult, :mult, [10] +end - describe "BigDecimal#mult" do - before :each do - @one = BigDecimal "1" - @e3_minus = BigDecimal("3E-20001") - @e3_plus = BigDecimal("3E20001") - @e = BigDecimal "1.00000000000000000000123456789" - @tolerance = @e.sub @one, 1000 - @tolerance2 = BigDecimal "30001E-20005" +describe "BigDecimal#mult" do + before :each do + @one = BigDecimal "1" + @e3_minus = BigDecimal("3E-20001") + @e3_plus = BigDecimal("3E20001") + @e = BigDecimal "1.00000000000000000000123456789" + @tolerance = @e.sub @one, 1000 + @tolerance2 = BigDecimal "30001E-20005" - end + end - it "multiply self with other with (optional) precision" do - @e.mult(@one, 1).should be_close(@one, @tolerance) - @e3_minus.mult(@one, 1).should be_close(0, @tolerance2) - end + it "multiply self with other with (optional) precision" do + @e.mult(@one, 1).should be_close(@one, @tolerance) + @e3_minus.mult(@one, 1).should be_close(0, @tolerance2) + end - describe "with Object" do - it "tries to coerce the other operand to self" do - object = mock("Object") - object.should_receive(:coerce).with(@e3_minus).and_return([@e3_minus, @e3_plus]) - @e3_minus.mult(object, 1).should == BigDecimal("9") - end + describe "with Object" do + it "tries to coerce the other operand to self" do + object = mock("Object") + object.should_receive(:coerce).with(@e3_minus).and_return([@e3_minus, @e3_plus]) + @e3_minus.mult(object, 1).should == BigDecimal("9") end end end diff --git a/spec/ruby/library/bigdecimal/multiply_spec.rb b/spec/ruby/library/bigdecimal/multiply_spec.rb index 2887bcc5a92..a8ce1da32ed 100644 --- a/spec/ruby/library/bigdecimal/multiply_spec.rb +++ b/spec/ruby/library/bigdecimal/multiply_spec.rb @@ -1,44 +1,41 @@ require_relative '../../spec_helper' +require_relative 'shared/mult' +require 'bigdecimal' -ruby_version_is ""..."3.4" do - require_relative 'shared/mult' - require 'bigdecimal' +describe "BigDecimal#*" do + it_behaves_like :bigdecimal_mult, :*, [] +end - describe "BigDecimal#*" do - it_behaves_like :bigdecimal_mult, :*, [] +describe "BigDecimal#*" do + before :each do + @three = BigDecimal("3") + @e3_minus = BigDecimal("3E-20001") + @e3_plus = BigDecimal("3E20001") + @e = BigDecimal("1.00000000000000000000123456789") + @one = BigDecimal("1") end - describe "BigDecimal#*" do - before :each do - @three = BigDecimal("3") - @e3_minus = BigDecimal("3E-20001") - @e3_plus = BigDecimal("3E20001") - @e = BigDecimal("1.00000000000000000000123456789") - @one = BigDecimal("1") - end - - it "multiply self with other" do - (@one * @one).should == @one - (@e3_minus * @e3_plus).should == BigDecimal("9") - # Can't do this till we implement ** - # (@e3_minus * @e3_minus).should == @e3_minus ** 2 - # So let's rewrite it as: - (@e3_minus * @e3_minus).should == BigDecimal("9E-40002") - (@e * @one).should == @e - end + it "multiply self with other" do + (@one * @one).should == @one + (@e3_minus * @e3_plus).should == BigDecimal("9") + # Can't do this till we implement ** + # (@e3_minus * @e3_minus).should == @e3_minus ** 2 + # So let's rewrite it as: + (@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 + 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 + 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 0839ed675df..9eaf69b6106 100644 --- a/spec/ruby/library/bigdecimal/nan_spec.rb +++ b/spec/ruby/library/bigdecimal/nan_spec.rb @@ -1,26 +1,23 @@ require_relative '../../spec_helper' +require 'bigdecimal' -ruby_version_is ""..."3.4" do - require 'bigdecimal' +describe "BigDecimal#nan?" do - describe "BigDecimal#nan?" do - - it "returns true if self is not a number" do - BigDecimal("NaN").should.nan? - end - - it "returns false if self is not a NaN" do - 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 + it "returns true if self is not a number" do + BigDecimal("NaN").should.nan? + end + it "returns false if self is not a NaN" do + 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/nonzero_spec.rb b/spec/ruby/library/bigdecimal/nonzero_spec.rb index 895e8cc429f..f43c4393cd3 100644 --- a/spec/ruby/library/bigdecimal/nonzero_spec.rb +++ b/spec/ruby/library/bigdecimal/nonzero_spec.rb @@ -1,32 +1,29 @@ require_relative '../../spec_helper' +require 'bigdecimal' -ruby_version_is ""..."3.4" do - require 'bigdecimal' +describe "BigDecimal#nonzero?" do - describe "BigDecimal#nonzero?" do - - it "returns self if self doesn't equal zero" do - # documentation says, it returns true. (04/10/08) - e2_plus = BigDecimal("2E40001") - e3_minus = BigDecimal("3E-20001") - 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) - end - - it "returns nil otherwise" do - # documentation states, it should return false. (04/10/08) - really_small_zero = BigDecimal("0E-200000000") - really_big_zero = BigDecimal("0E200000000000") - really_small_zero.nonzero?.should == nil - really_big_zero.nonzero?.should == nil - BigDecimal("0.000000000000000000000000").nonzero?.should == nil - end + it "returns self if self doesn't equal zero" do + # documentation says, it returns true. (04/10/08) + e2_plus = BigDecimal("2E40001") + e3_minus = BigDecimal("3E-20001") + 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) + end + it "returns nil otherwise" do + # documentation states, it should return false. (04/10/08) + really_small_zero = BigDecimal("0E-200000000") + really_big_zero = BigDecimal("0E200000000000") + really_small_zero.nonzero?.should == nil + really_big_zero.nonzero?.should == nil + BigDecimal("0.000000000000000000000000").nonzero?.should == nil end + end diff --git a/spec/ruby/library/bigdecimal/plus_spec.rb b/spec/ruby/library/bigdecimal/plus_spec.rb index e1ae0e31638..d1934841c8d 100644 --- a/spec/ruby/library/bigdecimal/plus_spec.rb +++ b/spec/ruby/library/bigdecimal/plus_spec.rb @@ -1,57 +1,54 @@ require_relative '../../spec_helper' +require 'bigdecimal' + +describe "BigDecimal#+" do + + before :each do + @one = BigDecimal("1") + @zero = BigDecimal("0") + @two = BigDecimal("2") + @three = BigDecimal("3") + @ten = BigDecimal("10") + @eleven = BigDecimal("11") + @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") + end -ruby_version_is ""..."3.4" do - require 'bigdecimal' - - describe "BigDecimal#+" do - - before :each do - @one = BigDecimal("1") - @zero = BigDecimal("0") - @two = BigDecimal("2") - @three = BigDecimal("3") - @ten = BigDecimal("10") - @eleven = BigDecimal("11") - @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") - end - - it "returns a + b" do - (@two + @one).should == @three - (@one + @two).should == @three - (@one + @one_minus).should == @zero - (@zero + @one).should == @one - (@ten + @one).should == @eleven - (@frac_1 + @frac_2).should == BigDecimal("1.9E-99999") - (@frac_2 + @frac_1).should == BigDecimal("1.9E-99999") - (@frac_1 + @frac_1).should == BigDecimal("2E-99999") - end + it "returns a + b" do + (@two + @one).should == @three + (@one + @two).should == @three + (@one + @one_minus).should == @zero + (@zero + @one).should == @one + (@ten + @one).should == @eleven + (@frac_1 + @frac_2).should == BigDecimal("1.9E-99999") + (@frac_2 + @frac_1).should == BigDecimal("1.9E-99999") + (@frac_1 + @frac_1).should == BigDecimal("2E-99999") + end - it "returns NaN if NaN is involved" do - (@one + @nan).should.nan? - (@nan + @one).should.nan? - end + it "returns NaN if NaN is involved" do + (@one + @nan).should.nan? + (@nan + @one).should.nan? + end - it "returns Infinity or -Infinity if these are involved" do - (@zero + @infinity).should == @infinity - (@frac_2 + @infinity).should == @infinity - (@two + @infinity_minus).should == @infinity_minus - end + it "returns Infinity or -Infinity if these are involved" do + (@zero + @infinity).should == @infinity + (@frac_2 + @infinity).should == @infinity + (@two + @infinity_minus).should == @infinity_minus + end - it "returns NaN if Infinity + (- Infinity)" do - (@infinity + @infinity_minus).should.nan? - end + it "returns NaN if Infinity + (- Infinity)" do + (@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 + 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 6ab0b9f2ca1..63a45a18872 100644 --- a/spec/ruby/library/bigdecimal/power_spec.rb +++ b/spec/ruby/library/bigdecimal/power_spec.rb @@ -1,9 +1,6 @@ require_relative '../../spec_helper' +require_relative 'shared/power' -ruby_version_is ""..."3.4" do - require_relative 'shared/power' - - describe "BigDecimal#power" do - it_behaves_like :bigdecimal_power, :power - end +describe "BigDecimal#power" do + 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 index d32778b5417..5fda8d30879 100644 --- a/spec/ruby/library/bigdecimal/precs_spec.rb +++ b/spec/ruby/library/bigdecimal/precs_spec.rb @@ -1,57 +1,54 @@ require_relative '../../spec_helper' +require 'bigdecimal' -ruby_version_is ""..."3.4" do - 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") - 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 + @arr = [BigDecimal("2E40001"), BigDecimal("3E-20001"),\ + @infinity, @infinity_neg, @nan, @zero, @zero_neg] + @precision = BigDecimal::BASE.to_s.length - 1 + end - it "returns array of two values" do - suppress_warning do - @arr.each do |x| - x.precs.kind_of?(Array).should == true - x.precs.size.should == 2 - end + it "returns array of two values" do + suppress_warning do + @arr.each do |x| + x.precs.kind_of?(Array).should == true + x.precs.size.should == 2 end end + end - it "returns Integers as array values" do - suppress_warning do - @arr.each do |x| - x.precs[0].kind_of?(Integer).should == true - x.precs[1].kind_of?(Integer).should == true - end + it "returns Integers as array values" do + suppress_warning do + @arr.each do |x| + x.precs[0].kind_of?(Integer).should == true + x.precs[1].kind_of?(Integer).should == true end end + end - it "returns the current value of significant digits as the first value" do - suppress_warning do - BigDecimal("3.14159").precs[0].should >= 6 - BigDecimal('1').precs[0].should == BigDecimal('1' + '0' * 100).precs[0] - [@infinity, @infinity_neg, @nan, @zero, @zero_neg].each do |value| - value.precs[0].should <= @precision - end + it "returns the current value of significant digits as the first value" do + suppress_warning do + BigDecimal("3.14159").precs[0].should >= 6 + BigDecimal('1').precs[0].should == BigDecimal('1' + '0' * 100).precs[0] + [@infinity, @infinity_neg, @nan, @zero, @zero_neg].each do |value| + value.precs[0].should <= @precision end end + end - it "returns the maximum number of significant digits as the second value" do - suppress_warning do - BigDecimal("3.14159").precs[1].should >= 6 - BigDecimal('1').precs[1].should >= 1 - BigDecimal('1' + '0' * 100).precs[1].should >= 101 - [@infinity, @infinity_neg, @nan, @zero, @zero_neg].each do |value| - value.precs[1].should >= 1 - end + it "returns the maximum number of significant digits as the second value" do + suppress_warning do + BigDecimal("3.14159").precs[1].should >= 6 + BigDecimal('1').precs[1].should >= 1 + BigDecimal('1' + '0' * 100).precs[1].should >= 101 + [@infinity, @infinity_neg, @nan, @zero, @zero_neg].each do |value| + value.precs[1].should >= 1 end end end diff --git a/spec/ruby/library/bigdecimal/quo_spec.rb b/spec/ruby/library/bigdecimal/quo_spec.rb index b839c380b48..65a4330303d 100644 --- a/spec/ruby/library/bigdecimal/quo_spec.rb +++ b/spec/ruby/library/bigdecimal/quo_spec.rb @@ -1,15 +1,12 @@ require_relative '../../spec_helper' +require_relative 'shared/quo' +require 'bigdecimal' -ruby_version_is ""..."3.4" do - require_relative 'shared/quo' - require 'bigdecimal' +describe "BigDecimal#quo" do + it_behaves_like :bigdecimal_quo, :quo, [] - describe "BigDecimal#quo" do - it_behaves_like :bigdecimal_quo, :quo, [] - - it "returns NaN if NaN is involved" do - BigDecimal("1").quo(BigDecimal("NaN")).should.nan? - BigDecimal("NaN").quo(BigDecimal("1")).should.nan? - end + it "returns NaN if NaN is involved" do + 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 dde0a5bc2dd..bac5f37ba96 100644 --- a/spec/ruby/library/bigdecimal/remainder_spec.rb +++ b/spec/ruby/library/bigdecimal/remainder_spec.rb @@ -1,97 +1,94 @@ require_relative '../../spec_helper' +require 'bigdecimal' + +describe "BigDecimal#remainder" do + + before :each do + @zero = BigDecimal("0") + @one = BigDecimal("1") + @three = BigDecimal("3") + @mixed = BigDecimal("1.23456789") + @pos_int = BigDecimal("2E5555") + @neg_int = BigDecimal("-2E5555") + @pos_frac = BigDecimal("2E-9999") + @neg_frac = BigDecimal("-2E-9999") + @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") + end -ruby_version_is ""..."3.4" do - require 'bigdecimal' - - describe "BigDecimal#remainder" do - - before :each do - @zero = BigDecimal("0") - @one = BigDecimal("1") - @three = BigDecimal("3") - @mixed = BigDecimal("1.23456789") - @pos_int = BigDecimal("2E5555") - @neg_int = BigDecimal("-2E5555") - @pos_frac = BigDecimal("2E-9999") - @neg_frac = BigDecimal("-2E-9999") - @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") - end - - it "it equals modulo, if both values are of same sign" do - BigDecimal('1234567890123456789012345679').remainder(BigDecimal('1')).should == @zero - BigDecimal('123456789').remainder(BigDecimal('333333333333333333333333333E-50')).should == BigDecimal('0.12233333333333333333345679E-24') - - @mixed.remainder(@pos_frac).should == @mixed % @pos_frac - @pos_int.remainder(@pos_frac).should == @pos_int % @pos_frac - @neg_frac.remainder(@neg_int).should == @neg_frac % @neg_int - @neg_int.remainder(@neg_frac).should == @neg_int % @neg_frac - end - - it "means self-arg*(self/arg).truncate" do - @mixed.remainder(@neg_frac).should == @mixed - @neg_frac * (@mixed / @neg_frac).truncate - @pos_int.remainder(@neg_frac).should == @pos_int - @neg_frac * (@pos_int / @neg_frac).truncate - @neg_frac.remainder(@pos_int).should == @neg_frac - @pos_int * (@neg_frac / @pos_int).truncate - @neg_int.remainder(@pos_frac).should == @neg_int - @pos_frac * (@neg_int / @pos_frac).truncate - end - - it "returns NaN used with zero" do - @mixed.remainder(@zero).should.nan? - @zero.remainder(@zero).should.nan? - end + it "it equals modulo, if both values are of same sign" do + BigDecimal('1234567890123456789012345679').remainder(BigDecimal('1')).should == @zero + BigDecimal('123456789').remainder(BigDecimal('333333333333333333333333333E-50')).should == BigDecimal('0.12233333333333333333345679E-24') - it "returns zero if used on zero" do - @zero.remainder(@mixed).should == @zero - end + @mixed.remainder(@pos_frac).should == @mixed % @pos_frac + @pos_int.remainder(@pos_frac).should == @pos_int % @pos_frac + @neg_frac.remainder(@neg_int).should == @neg_frac % @neg_int + @neg_int.remainder(@neg_frac).should == @neg_int % @neg_frac + end - it "returns NaN if NaN is involved" do - @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 "means self-arg*(self/arg).truncate" do + @mixed.remainder(@neg_frac).should == @mixed - @neg_frac * (@mixed / @neg_frac).truncate + @pos_int.remainder(@neg_frac).should == @pos_int - @neg_frac * (@pos_int / @neg_frac).truncate + @neg_frac.remainder(@pos_int).should == @neg_frac - @pos_int * (@neg_frac / @pos_int).truncate + @neg_int.remainder(@pos_frac).should == @neg_int - @pos_frac * (@neg_int / @pos_frac).truncate + end - version_is BigDecimal::VERSION, ""..."3.1.4" do #ruby_version_is ""..."3.3" do - it "returns NaN if Infinity is involved" do - @infinity.remainder(@infinity).should.nan? - @infinity.remainder(@one).should.nan? - @infinity.remainder(@mixed).should.nan? - @infinity.remainder(@one_minus).should.nan? - @infinity.remainder(@frac_1).should.nan? - @one.remainder(@infinity).should.nan? + it "returns NaN used with zero" do + @mixed.remainder(@zero).should.nan? + @zero.remainder(@zero).should.nan? + end - @infinity_minus.remainder(@infinity_minus).should.nan? - @infinity_minus.remainder(@one).should.nan? - @one.remainder(@infinity_minus).should.nan? - @frac_2.remainder(@infinity_minus).should.nan? + it "returns zero if used on zero" do + @zero.remainder(@mixed).should == @zero + end - @infinity.remainder(@infinity_minus).should.nan? - @infinity_minus.remainder(@infinity).should.nan? - end - end + it "returns NaN if NaN is involved" do + @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 - @three.remainder(2).should == @one + version_is BigDecimal::VERSION, ""..."3.1.4" do #ruby_version_is ""..."3.3" do + it "returns NaN if Infinity is involved" do + @infinity.remainder(@infinity).should.nan? + @infinity.remainder(@one).should.nan? + @infinity.remainder(@mixed).should.nan? + @infinity.remainder(@one_minus).should.nan? + @infinity.remainder(@frac_1).should.nan? + @one.remainder(@infinity).should.nan? + + @infinity_minus.remainder(@infinity_minus).should.nan? + @infinity_minus.remainder(@one).should.nan? + @one.remainder(@infinity_minus).should.nan? + @frac_2.remainder(@infinity_minus).should.nan? + + @infinity.remainder(@infinity_minus).should.nan? + @infinity_minus.remainder(@infinity).should.nan? end + 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 "coerces arguments to BigDecimal if possible" do + @three.remainder(2).should == @one + end - it "raises TypeError if the argument cannot be coerced to BigDecimal" do - -> { - @one.remainder('2') - }.should raise_error(TypeError) + 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 + -> { + @one.remainder('2') + }.should raise_error(TypeError) end + end diff --git a/spec/ruby/library/bigdecimal/round_spec.rb b/spec/ruby/library/bigdecimal/round_spec.rb index 2c966ab4445..fba52df65d3 100644 --- a/spec/ruby/library/bigdecimal/round_spec.rb +++ b/spec/ruby/library/bigdecimal/round_spec.rb @@ -1,245 +1,242 @@ require_relative '../../spec_helper' +require 'bigdecimal' + +describe "BigDecimal#round" do + before :each do + @one = BigDecimal("1") + @two = BigDecimal("2") + @three = BigDecimal("3") + + @neg_one = BigDecimal("-1") + @neg_two = BigDecimal("-2") + @neg_three = BigDecimal("-3") + + @p1_50 = BigDecimal("1.50") + @p1_51 = BigDecimal("1.51") + @p1_49 = BigDecimal("1.49") + @n1_50 = BigDecimal("-1.50") + @n1_51 = BigDecimal("-1.51") + @n1_49 = BigDecimal("-1.49") + + @p2_50 = BigDecimal("2.50") + @p2_51 = BigDecimal("2.51") + @p2_49 = BigDecimal("2.49") + @n2_50 = BigDecimal("-2.50") + @n2_51 = BigDecimal("-2.51") + @n2_49 = BigDecimal("-2.49") + end -ruby_version_is ""..."3.4" do - require 'bigdecimal' - - describe "BigDecimal#round" do - before :each do - @one = BigDecimal("1") - @two = BigDecimal("2") - @three = BigDecimal("3") - - @neg_one = BigDecimal("-1") - @neg_two = BigDecimal("-2") - @neg_three = BigDecimal("-3") - - @p1_50 = BigDecimal("1.50") - @p1_51 = BigDecimal("1.51") - @p1_49 = BigDecimal("1.49") - @n1_50 = BigDecimal("-1.50") - @n1_51 = BigDecimal("-1.51") - @n1_49 = BigDecimal("-1.49") - - @p2_50 = BigDecimal("2.50") - @p2_51 = BigDecimal("2.51") - @p2_49 = BigDecimal("2.49") - @n2_50 = BigDecimal("-2.50") - @n2_51 = BigDecimal("-2.51") - @n2_49 = BigDecimal("-2.49") - end - - after :each do - BigDecimal.mode(BigDecimal::ROUND_MODE, BigDecimal::ROUND_HALF_UP) - end + after :each do + BigDecimal.mode(BigDecimal::ROUND_MODE, BigDecimal::ROUND_HALF_UP) + end - it "uses default rounding method unless given" do - @p1_50.round(0).should == @two - @p1_51.round(0).should == @two - @p1_49.round(0).should == @one - @n1_50.round(0).should == @neg_two - @n1_51.round(0).should == @neg_two - @n1_49.round(0).should == @neg_one - - @p2_50.round(0).should == @three - @p2_51.round(0).should == @three - @p2_49.round(0).should == @two - @n2_50.round(0).should == @neg_three - @n2_51.round(0).should == @neg_three - @n2_49.round(0).should == @neg_two - - BigDecimal.mode(BigDecimal::ROUND_MODE, BigDecimal::ROUND_DOWN) - - @p1_50.round(0).should == @one - @p1_51.round(0).should == @one - @p1_49.round(0).should == @one - @n1_50.round(0).should == @neg_one - @n1_51.round(0).should == @neg_one - @n1_49.round(0).should == @neg_one - - @p2_50.round(0).should == @two - @p2_51.round(0).should == @two - @p2_49.round(0).should == @two - @n2_50.round(0).should == @neg_two - @n2_51.round(0).should == @neg_two - @n2_49.round(0).should == @neg_two - end + it "uses default rounding method unless given" do + @p1_50.round(0).should == @two + @p1_51.round(0).should == @two + @p1_49.round(0).should == @one + @n1_50.round(0).should == @neg_two + @n1_51.round(0).should == @neg_two + @n1_49.round(0).should == @neg_one + + @p2_50.round(0).should == @three + @p2_51.round(0).should == @three + @p2_49.round(0).should == @two + @n2_50.round(0).should == @neg_three + @n2_51.round(0).should == @neg_three + @n2_49.round(0).should == @neg_two + + BigDecimal.mode(BigDecimal::ROUND_MODE, BigDecimal::ROUND_DOWN) + + @p1_50.round(0).should == @one + @p1_51.round(0).should == @one + @p1_49.round(0).should == @one + @n1_50.round(0).should == @neg_one + @n1_51.round(0).should == @neg_one + @n1_49.round(0).should == @neg_one + + @p2_50.round(0).should == @two + @p2_51.round(0).should == @two + @p2_49.round(0).should == @two + @n2_50.round(0).should == @neg_two + @n2_51.round(0).should == @neg_two + @n2_49.round(0).should == @neg_two + end - ["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 + ["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 - ["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 + ["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 - ["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 + ["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 - ["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 + ["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 - ["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 + ["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 - ["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 + ["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 - ["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 + ["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 - -> { BigDecimal('NaN').round }.should raise_error(FloatDomainError) - -> { BigDecimal('Infinity').round }.should raise_error(FloatDomainError) - -> { BigDecimal('-Infinity').round }.should raise_error(FloatDomainError) - end + it 'raise exception, if self is special value' do + -> { BigDecimal('NaN').round }.should raise_error(FloatDomainError) + -> { BigDecimal('Infinity').round }.should raise_error(FloatDomainError) + -> { BigDecimal('-Infinity').round }.should raise_error(FloatDomainError) + end - it 'do not raise exception, if self is special value and precision is given' do - -> { BigDecimal('NaN').round(2) }.should_not raise_error(FloatDomainError) - -> { BigDecimal('Infinity').round(2) }.should_not raise_error(FloatDomainError) - -> { BigDecimal('-Infinity').round(2) }.should_not raise_error(FloatDomainError) - end + it 'do not raise exception, if self is special value and precision is given' do + -> { BigDecimal('NaN').round(2) }.should_not raise_error(FloatDomainError) + -> { BigDecimal('Infinity').round(2) }.should_not raise_error(FloatDomainError) + -> { BigDecimal('-Infinity').round(2) }.should_not raise_error(FloatDomainError) + end - version_is BigDecimal::VERSION, ''...'3.1.3' do #ruby_version_is ''...'3.2' do - it 'raise for a non-existent round mode' do - -> { @p1_50.round(0, :nonsense) }.should raise_error(ArgumentError, "invalid rounding mode") - end + version_is BigDecimal::VERSION, ''...'3.1.3' do #ruby_version_is ''...'3.2' do + it 'raise for a non-existent round mode' do + -> { @p1_50.round(0, :nonsense) }.should raise_error(ArgumentError, "invalid rounding mode") end + end - version_is BigDecimal::VERSION, '3.1.3' do #ruby_version_is '3.2' do - it 'raise for a non-existent round mode' do - -> { @p1_50.round(0, :nonsense) }.should raise_error(ArgumentError, "invalid rounding mode (nonsense)") - end + version_is BigDecimal::VERSION, '3.1.3' do #ruby_version_is '3.2' do + it 'raise for a non-existent round mode' do + -> { @p1_50.round(0, :nonsense) }.should raise_error(ArgumentError, "invalid rounding mode (nonsense)") end end end diff --git a/spec/ruby/library/bigdecimal/sign_spec.rb b/spec/ruby/library/bigdecimal/sign_spec.rb index c43ac05393e..ae2c28e9fd2 100644 --- a/spec/ruby/library/bigdecimal/sign_spec.rb +++ b/spec/ruby/library/bigdecimal/sign_spec.rb @@ -1,49 +1,46 @@ require_relative '../../spec_helper' +require 'bigdecimal' + +describe "BigDecimal#sign" do + + it "defines several constants for signs" do + # are these really correct? + BigDecimal::SIGN_POSITIVE_INFINITE.should == 3 + BigDecimal::SIGN_NEGATIVE_INFINITE.should == -3 + BigDecimal::SIGN_POSITIVE_ZERO.should == 1 + BigDecimal::SIGN_NEGATIVE_ZERO.should == -1 + BigDecimal::SIGN_POSITIVE_FINITE.should == 2 + BigDecimal::SIGN_NEGATIVE_FINITE.should == -2 + end -ruby_version_is ""..."3.4" do - require 'bigdecimal' - - describe "BigDecimal#sign" do - - it "defines several constants for signs" do - # are these really correct? - BigDecimal::SIGN_POSITIVE_INFINITE.should == 3 - BigDecimal::SIGN_NEGATIVE_INFINITE.should == -3 - BigDecimal::SIGN_POSITIVE_ZERO.should == 1 - BigDecimal::SIGN_NEGATIVE_ZERO.should == -1 - BigDecimal::SIGN_POSITIVE_FINITE.should == 2 - BigDecimal::SIGN_NEGATIVE_FINITE.should == -2 - end - - it "returns positive value if BigDecimal greater than 0" do - BigDecimal("1").sign.should == BigDecimal::SIGN_POSITIVE_FINITE - BigDecimal("1E-20000000").sign.should == BigDecimal::SIGN_POSITIVE_FINITE - BigDecimal("1E200000000").sign.should == BigDecimal::SIGN_POSITIVE_FINITE - BigDecimal("Infinity").sign.should == BigDecimal::SIGN_POSITIVE_INFINITE - end - - it "returns negative value if BigDecimal less than 0" do - BigDecimal("-1").sign.should == BigDecimal::SIGN_NEGATIVE_FINITE - BigDecimal("-1E-9990000").sign.should == BigDecimal::SIGN_NEGATIVE_FINITE - BigDecimal("-1E20000000").sign.should == BigDecimal::SIGN_NEGATIVE_FINITE - BigDecimal("-Infinity").sign.should == BigDecimal::SIGN_NEGATIVE_INFINITE - end - - it "returns positive zero if BigDecimal equals positive zero" do - BigDecimal("0").sign.should == BigDecimal::SIGN_POSITIVE_ZERO - BigDecimal("0E-200000000").sign.should == BigDecimal::SIGN_POSITIVE_ZERO - BigDecimal("0E200000000").sign.should == BigDecimal::SIGN_POSITIVE_ZERO - end - - it "returns negative zero if BigDecimal equals negative zero" do - BigDecimal("-0").sign.should == BigDecimal::SIGN_NEGATIVE_ZERO - BigDecimal("-0E-200000000").sign.should == BigDecimal::SIGN_NEGATIVE_ZERO - BigDecimal("-0E200000000").sign.should == BigDecimal::SIGN_NEGATIVE_ZERO - end - - it "returns BigDecimal::SIGN_NaN if BigDecimal is NaN" do - BigDecimal("NaN").sign.should == BigDecimal::SIGN_NaN - end + it "returns positive value if BigDecimal greater than 0" do + BigDecimal("1").sign.should == BigDecimal::SIGN_POSITIVE_FINITE + BigDecimal("1E-20000000").sign.should == BigDecimal::SIGN_POSITIVE_FINITE + BigDecimal("1E200000000").sign.should == BigDecimal::SIGN_POSITIVE_FINITE + BigDecimal("Infinity").sign.should == BigDecimal::SIGN_POSITIVE_INFINITE + end + it "returns negative value if BigDecimal less than 0" do + BigDecimal("-1").sign.should == BigDecimal::SIGN_NEGATIVE_FINITE + BigDecimal("-1E-9990000").sign.should == BigDecimal::SIGN_NEGATIVE_FINITE + BigDecimal("-1E20000000").sign.should == BigDecimal::SIGN_NEGATIVE_FINITE + BigDecimal("-Infinity").sign.should == BigDecimal::SIGN_NEGATIVE_INFINITE end + + it "returns positive zero if BigDecimal equals positive zero" do + BigDecimal("0").sign.should == BigDecimal::SIGN_POSITIVE_ZERO + BigDecimal("0E-200000000").sign.should == BigDecimal::SIGN_POSITIVE_ZERO + BigDecimal("0E200000000").sign.should == BigDecimal::SIGN_POSITIVE_ZERO + end + + it "returns negative zero if BigDecimal equals negative zero" do + BigDecimal("-0").sign.should == BigDecimal::SIGN_NEGATIVE_ZERO + BigDecimal("-0E-200000000").sign.should == BigDecimal::SIGN_NEGATIVE_ZERO + BigDecimal("-0E200000000").sign.should == BigDecimal::SIGN_NEGATIVE_ZERO + end + + it "returns BigDecimal::SIGN_NaN if BigDecimal is NaN" do + BigDecimal("NaN").sign.should == BigDecimal::SIGN_NaN + end + end diff --git a/spec/ruby/library/bigdecimal/split_spec.rb b/spec/ruby/library/bigdecimal/split_spec.rb index a8752e32391..f9b4bab5f74 100644 --- a/spec/ruby/library/bigdecimal/split_spec.rb +++ b/spec/ruby/library/bigdecimal/split_spec.rb @@ -1,89 +1,86 @@ require_relative '../../spec_helper' +require 'bigdecimal' -ruby_version_is ""..."3.4" do - require 'bigdecimal' +describe "BigDecimal#split" do - describe "BigDecimal#split" do + before :each do + @arr = BigDecimal("0.314159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593014782083152134043E1").split + @arr_neg = BigDecimal("-0.314159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593014782083152134043E1").split + @digits = "922337203685477580810101333333333333333333333333333" + @arr_big = BigDecimal("00#{@digits}000").split + @arr_big_neg = BigDecimal("-00#{@digits}000").split + @huge = BigDecimal('100000000000000000000000000000000000000000001E90000000').split - before :each do - @arr = BigDecimal("0.314159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593014782083152134043E1").split - @arr_neg = BigDecimal("-0.314159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593014782083152134043E1").split - @digits = "922337203685477580810101333333333333333333333333333" - @arr_big = BigDecimal("00#{@digits}000").split - @arr_big_neg = BigDecimal("-00#{@digits}000").split - @huge = BigDecimal('100000000000000000000000000000000000000000001E90000000').split - - @infinity = BigDecimal("Infinity") - @infinity_neg = BigDecimal("-Infinity") - @nan = BigDecimal("NaN") - @zero = BigDecimal("0") - @zero_neg = BigDecimal("-0") - end - - it "splits BigDecimal in an array with four values" do - @arr.size.should == 4 - end + @infinity = BigDecimal("Infinity") + @infinity_neg = BigDecimal("-Infinity") + @nan = BigDecimal("NaN") + @zero = BigDecimal("0") + @zero_neg = BigDecimal("-0") + end - it "first value: 1 for numbers > 0" do - @arr[0].should == 1 - @arr_big[0].should == 1 - @zero.split[0].should == 1 - @huge[0].should == 1 - BigDecimal("+0").split[0].should == 1 - BigDecimal("1E400").split[0].should == 1 - @infinity.split[0].should == 1 - end + it "splits BigDecimal in an array with four values" do + @arr.size.should == 4 + end - it "first value: -1 for numbers < 0" do - @arr_neg[0].should == -1 - @arr_big_neg[0].should == -1 - @zero_neg.split[0].should == -1 - BigDecimal("-1E400").split[0].should == -1 - @infinity_neg.split[0].should == -1 - end + it "first value: 1 for numbers > 0" do + @arr[0].should == 1 + @arr_big[0].should == 1 + @zero.split[0].should == 1 + @huge[0].should == 1 + BigDecimal("+0").split[0].should == 1 + BigDecimal("1E400").split[0].should == 1 + @infinity.split[0].should == 1 + end - it "first value: 0 if BigDecimal is NaN" do - BigDecimal("NaN").split[0].should == 0 - end + it "first value: -1 for numbers < 0" do + @arr_neg[0].should == -1 + @arr_big_neg[0].should == -1 + @zero_neg.split[0].should == -1 + BigDecimal("-1E400").split[0].should == -1 + @infinity_neg.split[0].should == -1 + end - it "second value: a string with the significant digits" do - string = "314159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593014782083152134043" - @arr[1].should == string - @arr_big[1].should == @digits - @arr_big_neg[1].should == @digits - @huge[1].should == "100000000000000000000000000000000000000000001" - @infinity.split[1].should == @infinity.to_s - @nan.split[1].should == @nan.to_s - @infinity_neg.split[1].should == @infinity.to_s - @zero.split[1].should == "0" - BigDecimal("-0").split[1].should == "0" - end + it "first value: 0 if BigDecimal is NaN" do + BigDecimal("NaN").split[0].should == 0 + 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 - end + it "second value: a string with the significant digits" do + string = "314159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593014782083152134043" + @arr[1].should == string + @arr_big[1].should == @digits + @arr_big_neg[1].should == @digits + @huge[1].should == "100000000000000000000000000000000000000000001" + @infinity.split[1].should == @infinity.to_s + @nan.split[1].should == @nan.to_s + @infinity_neg.split[1].should == @infinity.to_s + @zero.split[1].should == "0" + BigDecimal("-0").split[1].should == "0" + end - it "fourth value: the exponent" do - @arr[3].should == 1 - @arr_neg[3].should == 1 - @arr_big[3].should == 54 - @arr_big_neg[3].should == 54 - @huge[3].should == 90000045 - @infinity.split[3].should == 0 - @nan.split[3].should == 0 - @infinity_neg.split[3].should == 0 - @zero.split[3].should == 0 - @zero_neg.split[3].should == 0 - 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 + end + it "fourth value: the exponent" do + @arr[3].should == 1 + @arr_neg[3].should == 1 + @arr_big[3].should == 54 + @arr_big_neg[3].should == 54 + @huge[3].should == 90000045 + @infinity.split[3].should == 0 + @nan.split[3].should == 0 + @infinity_neg.split[3].should == 0 + @zero.split[3].should == 0 + @zero_neg.split[3].should == 0 end + end diff --git a/spec/ruby/library/bigdecimal/sqrt_spec.rb b/spec/ruby/library/bigdecimal/sqrt_spec.rb index daf95dbfe94..8fd1ec0f39f 100644 --- a/spec/ruby/library/bigdecimal/sqrt_spec.rb +++ b/spec/ruby/library/bigdecimal/sqrt_spec.rb @@ -1,115 +1,114 @@ require_relative '../../spec_helper' +require_relative 'fixtures/classes' +require 'bigdecimal' + +describe "BigDecimal#sqrt" do + before :each do + @one = BigDecimal("1") + @zero = BigDecimal("0") + @zero_pos = BigDecimal("+0") + @zero_neg = BigDecimal("-0") + @two = BigDecimal("2.0") + @three = BigDecimal("3.0") + @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") + end -ruby_version_is ""..."3.4" do - require_relative 'fixtures/classes' - require 'bigdecimal' - - describe "BigDecimal#sqrt" do - before :each do - @one = BigDecimal("1") - @zero = BigDecimal("0") - @zero_pos = BigDecimal("+0") - @zero_neg = BigDecimal("-0") - @two = BigDecimal("2.0") - @three = BigDecimal("3.0") - @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") - end - - it "returns square root of 2 with desired precision" do - string = "1.41421356237309504880168872420969807856967187537694807317667973799073247846210703885038753432764157" - (1..99).each { |idx| - @two.sqrt(idx).should be_close(BigDecimal(string), BigDecimal("1E-#{idx-1}")) - } - end + it "returns square root of 2 with desired precision" do + string = "1.41421356237309504880168872420969807856967187537694807317667973799073247846210703885038753432764157" + (1..99).each { |idx| + @two.sqrt(idx).should be_close(BigDecimal(string), BigDecimal("1E-#{idx-1}")) + } + end - it "returns square root of 3 with desired precision" do - sqrt_3 = "1.732050807568877293527446341505872366942805253810380628055806979451933016908800037081146186757248575" - (1..99).each { |idx| - @three.sqrt(idx).should be_close(BigDecimal(sqrt_3), BigDecimal("1E-#{idx-1}")) - } - end + it "returns square root of 3 with desired precision" do + sqrt_3 = "1.732050807568877293527446341505872366942805253810380628055806979451933016908800037081146186757248575" + (1..99).each { |idx| + @three.sqrt(idx).should be_close(BigDecimal(sqrt_3), BigDecimal("1E-#{idx-1}")) + } + end - it "returns square root of 121 with desired precision" do - BigDecimal('121').sqrt(5).should be_close(11, 0.00001) - end + it "returns square root of 121 with desired precision" do + BigDecimal('121').sqrt(5).should be_close(11, 0.00001) + end + platform_is_not wordsize: 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 - -> { - @one.sqrt - }.should raise_error(ArgumentError) - end - - it "raises ArgumentError if a negative number is given" do - -> { - @one.sqrt(-1) - }.should raise_error(ArgumentError) - end + it "raises ArgumentError when no argument is given" do + -> { + @one.sqrt + }.should raise_error(ArgumentError) + end - it "raises ArgumentError if 2 arguments are given" do - -> { - @one.sqrt(1, 1) - }.should raise_error(ArgumentError) - end + it "raises ArgumentError if a negative number is given" do + -> { + @one.sqrt(-1) + }.should raise_error(ArgumentError) + end - it "raises TypeError if nil is given" do - -> { - @one.sqrt(nil) - }.should raise_error(TypeError) - end + it "raises ArgumentError if 2 arguments are given" do + -> { + @one.sqrt(1, 1) + }.should raise_error(ArgumentError) + end - it "raises TypeError if a string is given" do - -> { - @one.sqrt("stuff") - }.should raise_error(TypeError) - end + it "raises TypeError if nil is given" do + -> { + @one.sqrt(nil) + }.should raise_error(TypeError) + end - it "raises TypeError if a plain Object is given" do - -> { - @one.sqrt(Object.new) - }.should raise_error(TypeError) - end + it "raises TypeError if a string is given" do + -> { + @one.sqrt("stuff") + }.should raise_error(TypeError) + end - it "returns 1 if precision is 0 or 1" do - @one.sqrt(1).should == 1 - @one.sqrt(0).should == 1 - end + it "raises TypeError if a plain Object is given" do + -> { + @one.sqrt(Object.new) + }.should raise_error(TypeError) + end - it "raises FloatDomainError on negative values" do - -> { - BigDecimal('-1').sqrt(10) - }.should raise_error(FloatDomainError) - end + it "returns 1 if precision is 0 or 1" do + @one.sqrt(1).should == 1 + @one.sqrt(0).should == 1 + end - it "returns positive infinity for infinity" do - @infinity.sqrt(1).should == @infinity - end + it "raises FloatDomainError on negative values" do + -> { + BigDecimal('-1').sqrt(10) + }.should raise_error(FloatDomainError) + end - it "raises FloatDomainError for negative infinity" do - -> { - @infinity_minus.sqrt(1) - }.should raise_error(FloatDomainError) - end + it "returns positive infinity for infinity" do + @infinity.sqrt(1).should == @infinity + end - it "raises FloatDomainError for NaN" do - -> { - @nan.sqrt(1) - }.should raise_error(FloatDomainError) - end + it "raises FloatDomainError for negative infinity" do + -> { + @infinity_minus.sqrt(1) + }.should raise_error(FloatDomainError) + end - it "returns 0 for 0, +0.0 and -0.0" do - @zero.sqrt(1).should == 0 - @zero_pos.sqrt(1).should == 0 - @zero_neg.sqrt(1).should == 0 - end + it "raises FloatDomainError for NaN" do + -> { + @nan.sqrt(1) + }.should raise_error(FloatDomainError) + end + it "returns 0 for 0, +0.0 and -0.0" do + @zero.sqrt(1).should == 0 + @zero_pos.sqrt(1).should == 0 + @zero_neg.sqrt(1).should == 0 end + end diff --git a/spec/ruby/library/bigdecimal/sub_spec.rb b/spec/ruby/library/bigdecimal/sub_spec.rb index aa4e2a86689..bddfec2186d 100644 --- a/spec/ruby/library/bigdecimal/sub_spec.rb +++ b/spec/ruby/library/bigdecimal/sub_spec.rb @@ -1,73 +1,70 @@ require_relative '../../spec_helper' +require 'bigdecimal' -ruby_version_is ""..."3.4" do - require 'bigdecimal' +describe "BigDecimal#sub" do - describe "BigDecimal#sub" do - - before :each 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 + before :each 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 - # documentation states, that precision is optional - # but implementation raises ArgumentError if not given. + it "returns a - b with given precision" do + # documentation states, that precision is optional + # but implementation raises ArgumentError if not given. - @two.sub(@one, 1).should == @one - @one.sub(@two, 1).should == @one_minus - @one.sub(@one_minus, 1).should == @two - @frac_2.sub(@frac_1, 1000000).should == BigDecimal("-0.1E-99999") - @frac_2.sub(@frac_1, 1).should == BigDecimal("-0.1E-99999") - # the above two examples puzzle me. - in_arow_one = BigDecimal("1.23456789") - in_arow_two = BigDecimal("1.2345678") - in_arow_one.sub(in_arow_two, 10).should == BigDecimal("0.9E-7") - @two.sub(@two,1).should == @zero - @frac_1.sub(@frac_1, 1000000).should == @zero - end - - describe "with Object" do - it "tries to coerce the other operand to self" do - object = mock("Object") - object.should_receive(:coerce).with(@frac_3).and_return([@frac_3, @frac_4]) - @frac_3.sub(object, 1).should == BigDecimal("-0.9E15") - end - end + @two.sub(@one, 1).should == @one + @one.sub(@two, 1).should == @one_minus + @one.sub(@one_minus, 1).should == @two + @frac_2.sub(@frac_1, 1000000).should == BigDecimal("-0.1E-99999") + @frac_2.sub(@frac_1, 1).should == BigDecimal("-0.1E-99999") + # the above two examples puzzle me. + in_arow_one = BigDecimal("1.23456789") + in_arow_two = BigDecimal("1.2345678") + in_arow_one.sub(in_arow_two, 10).should == BigDecimal("0.9E-7") + @two.sub(@two,1).should == @zero + @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 + describe "with Object" do + it "tries to coerce the other operand to self" do + object = mock("Object") + object.should_receive(:coerce).with(@frac_3).and_return([@frac_3, @frac_4]) + @frac_3.sub(object, 1).should == BigDecimal("-0.9E15") end + end - it "returns NaN if NaN is involved" do - @one.sub(@nan, 1).should.nan? - @nan.sub(@one, 1).should.nan? + describe "with Rational" do + it "produces a BigDecimal" do + (@three - Rational(500, 2)).should == BigDecimal('-0.247e3') end + end - it "returns NaN if both values are infinite with the same signs" do - @infinity.sub(@infinity, 1).should.nan? - @infinity_minus.sub(@infinity_minus, 1).should.nan? - end + it "returns NaN if NaN is involved" do + @one.sub(@nan, 1).should.nan? + @nan.sub(@one, 1).should.nan? + end - it "returns Infinity or -Infinity if these are involved" do - @infinity.sub(@infinity_minus, 1).should == @infinity - @infinity_minus.sub(@infinity, 1).should == @infinity_minus - @zero.sub(@infinity, 1).should == @infinity_minus - @frac_2.sub( @infinity, 1).should == @infinity_minus - @two.sub(@infinity, 1).should == @infinity_minus - end + it "returns NaN if both values are infinite with the same signs" do + @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 + @infinity.sub(@infinity_minus, 1).should == @infinity + @infinity_minus.sub(@infinity, 1).should == @infinity_minus + @zero.sub(@infinity, 1).should == @infinity_minus + @frac_2.sub( @infinity, 1).should == @infinity_minus + @two.sub(@infinity, 1).should == @infinity_minus end + end diff --git a/spec/ruby/library/bigdecimal/to_d_spec.rb b/spec/ruby/library/bigdecimal/to_d_spec.rb index ae2f11fe6df..50aea99bf7e 100644 --- a/spec/ruby/library/bigdecimal/to_d_spec.rb +++ b/spec/ruby/library/bigdecimal/to_d_spec.rb @@ -1,13 +1,10 @@ require_relative '../../spec_helper' +require 'bigdecimal' +require 'bigdecimal/util' -ruby_version_is ""..."3.4" do - 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 +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 c91e123dbfa..84d4d49de23 100644 --- a/spec/ruby/library/bigdecimal/to_f_spec.rb +++ b/spec/ruby/library/bigdecimal/to_f_spec.rb @@ -1,57 +1,54 @@ require_relative '../../spec_helper' +require 'bigdecimal' + +describe "BigDecimal#to_f" do + before :each do + @one = BigDecimal("1") + @zero = BigDecimal("0") + @zero_pos = BigDecimal("+0") + @zero_neg = 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") + @vals = [@one, @zero, @two, @three, @frac_1, @frac_2] + @spec_vals = [@zero_pos, @zero_neg, @nan, @infinity, @infinity_minus] + 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) } + end + + it "rounds correctly to Float precision" do + bigdec = BigDecimal("3.141592653589793238462643383279502884197169399375") + bigdec.to_f.should be_close(3.14159265358979, TOLERANCE) + @one.to_f.should == 1.0 + @two.to_f.should == 2.0 + @three.to_f.should be_close(3.0, TOLERANCE) + @one_minus.to_f.should == -1.0 + + # regression test for [ruby-talk:338957] + BigDecimal("10.03").to_f.should == 10.03 + end + + it "properly handles special values" do + @zero.to_f.should == 0 + @zero.to_f.to_s.should == "0.0" + + @nan.to_f.should.nan? + + @infinity.to_f.infinite?.should == 1 + @infinity_minus.to_f.infinite?.should == -1 + end -ruby_version_is ""..."3.4" do - require 'bigdecimal' - - describe "BigDecimal#to_f" do - before :each do - @one = BigDecimal("1") - @zero = BigDecimal("0") - @zero_pos = BigDecimal("+0") - @zero_neg = 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") - @vals = [@one, @zero, @two, @three, @frac_1, @frac_2] - @spec_vals = [@zero_pos, @zero_neg, @nan, @infinity, @infinity_minus] - 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) } - end - - it "rounds correctly to Float precision" do - bigdec = BigDecimal("3.141592653589793238462643383279502884197169399375") - bigdec.to_f.should be_close(3.14159265358979, TOLERANCE) - @one.to_f.should == 1.0 - @two.to_f.should == 2.0 - @three.to_f.should be_close(3.0, TOLERANCE) - @one_minus.to_f.should == -1.0 - - # regression test for [ruby-talk:338957] - BigDecimal("10.03").to_f.should == 10.03 - end - - it "properly handles special values" do - @zero.to_f.should == 0 - @zero.to_f.to_s.should == "0.0" - - @nan.to_f.should.nan? - - @infinity.to_f.infinite?.should == 1 - @infinity_minus.to_f.infinite?.should == -1 - end - - it "remembers negative zero when converted to float" do - @zero_neg.to_f.should == 0 - @zero_neg.to_f.to_s.should == "-0.0" - end + it "remembers negative zero when converted to float" do + @zero_neg.to_f.should == 0 + @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 08367374e2d..09481fce154 100644 --- a/spec/ruby/library/bigdecimal/to_i_spec.rb +++ b/spec/ruby/library/bigdecimal/to_i_spec.rb @@ -1,10 +1,7 @@ require_relative '../../spec_helper' +require_relative 'shared/to_int' +require 'bigdecimal' -ruby_version_is ""..."3.4" do - require_relative 'shared/to_int' - require 'bigdecimal' - - describe "BigDecimal#to_i" do - it_behaves_like :bigdecimal_to_int, :to_i - end +describe "BigDecimal#to_i" do + it_behaves_like :bigdecimal_to_int, :to_i end diff --git a/spec/ruby/library/bigdecimal/to_int_spec.rb b/spec/ruby/library/bigdecimal/to_int_spec.rb index 8ded7bcaf97..4df67498452 100644 --- a/spec/ruby/library/bigdecimal/to_int_spec.rb +++ b/spec/ruby/library/bigdecimal/to_int_spec.rb @@ -1,11 +1,8 @@ require_relative '../../spec_helper' +require_relative 'shared/to_int' +require 'bigdecimal' -ruby_version_is ""..."3.4" do - require_relative 'shared/to_int' - require 'bigdecimal' - - describe "BigDecimal#to_int" do - it_behaves_like :bigdecimal_to_int, :to_int - end +describe "BigDecimal#to_int" do + it_behaves_like :bigdecimal_to_int, :to_int end diff --git a/spec/ruby/library/bigdecimal/to_r_spec.rb b/spec/ruby/library/bigdecimal/to_r_spec.rb index 0d787a2effd..c350beff08c 100644 --- a/spec/ruby/library/bigdecimal/to_r_spec.rb +++ b/spec/ruby/library/bigdecimal/to_r_spec.rb @@ -1,31 +1,28 @@ require_relative '../../spec_helper' +require 'bigdecimal' -ruby_version_is ""..."3.4" do - require 'bigdecimal' +describe "BigDecimal#to_r" do - describe "BigDecimal#to_r" do - - it "returns a Rational" do - BigDecimal("3.14159").to_r.should be_kind_of(Rational) - end - - it "returns a Rational with bignum values" do - r = BigDecimal("3.141592653589793238462643").to_r - r.numerator.should eql(3141592653589793238462643) - r.denominator.should eql(1000000000000000000000000) - end + it "returns a Rational" do + BigDecimal("3.14159").to_r.should be_kind_of(Rational) + 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 with bignum values" do + r = BigDecimal("3.141592653589793238462643").to_r + r.numerator.should eql(3141592653589793238462643) + r.denominator.should eql(1000000000000000000000000) + 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 + 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 02f1ce0d3e1..ba9f960eb32 100644 --- a/spec/ruby/library/bigdecimal/to_s_spec.rb +++ b/spec/ruby/library/bigdecimal/to_s_spec.rb @@ -1,103 +1,100 @@ require_relative '../../spec_helper' +require 'bigdecimal' -ruby_version_is ""..."3.4" do - require 'bigdecimal' +describe "BigDecimal#to_s" do - describe "BigDecimal#to_s" do - - before :each do - @bigdec_str = "3.14159265358979323846264338327950288419716939937" - @bigneg_str = "-3.1415926535897932384626433832795028841971693993" - @bigdec = BigDecimal(@bigdec_str) - @bigneg = BigDecimal(@bigneg_str) - @internal = Encoding.default_internal - end + before :each do + @bigdec_str = "3.14159265358979323846264338327950288419716939937" + @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 + after :each do + Encoding.default_internal = @internal + end - it "return type is of class String" do - @bigdec.to_s.kind_of?(String).should == true - @bigneg.to_s.kind_of?(String).should == true - end + it "return type is of class String" do + @bigdec.to_s.kind_of?(String).should == true + @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]*$/ - end + 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 "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 - -> {@bigdec.to_s("F")}.should_not raise_error() - end + it "takes an optional argument" do + -> {@bigdec.to_s("F")}.should_not raise_error() + end - it "starts with + if + is supplied and value is positive" do - @bigdec.to_s("+").should =~ /^\+.*/ - @bigneg.to_s("+").should_not =~ /^\+.*/ - end + it "starts with + if + is supplied and value is positive" do + @bigdec.to_s("+").should =~ /^\+.*/ + @bigneg.to_s("+").should_not =~ /^\+.*/ + end - 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 - @bigdec.to_s(3).should =~ re - - str1 = '-123.45678 90123 45678 9' - BigDecimal("-123.45678901234567890").to_s('5F').should == str1 - # trailing zeroes removed - BigDecimal("1.00000000000").to_s('1F').should == "1.0" - # 0 is treated as no spaces - BigDecimal("1.2345").to_s('0F').should == "1.2345" - end + 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 + @bigdec.to_s(3).should =~ re + + str1 = '-123.45678 90123 45678 9' + BigDecimal("-123.45678901234567890").to_s('5F').should == str1 + # trailing zeroes removed + BigDecimal("1.00000000000").to_s('1F').should == "1.0" + # 0 is treated as no spaces + BigDecimal("1.2345").to_s('0F').should == "1.2345" + end - version_is BigDecimal::VERSION, "3.1.5" do #ruby_version_is '3.3' do - 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 + version_is BigDecimal::VERSION, "3.1.5" do #ruby_version_is '3.3' do + 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 + end - it "can return a leading space for values > 0" do - @bigdec.to_s(" F").should =~ /\ .*/ - @bigneg.to_s(" F").should_not =~ /\ .*/ - end + it "can return a leading space for values > 0" do + @bigdec.to_s(" F").should =~ /\ .*/ + @bigneg.to_s(" F").should_not =~ /\ .*/ + end - it "removes trailing spaces in floating point notation" do - 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" + it "removes trailing spaces in floating point notation" do + 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 + 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 - @bigdec.to_s("E").should =~ /^0\.[0-9]*E[0-9]*$/i - end + it "can use engineering notation" do + @bigdec.to_s("E").should =~ /^0\.[0-9]*E[0-9]*$/i + end - it "can use conventional floating point notation" do - %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 + it "can use conventional floating point notation" do + %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 - 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 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 + 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 fbb5b697794..4ad9eb92d1e 100644 --- a/spec/ruby/library/bigdecimal/truncate_spec.rb +++ b/spec/ruby/library/bigdecimal/truncate_spec.rb @@ -1,84 +1,81 @@ require_relative '../../spec_helper' +require 'bigdecimal' -ruby_version_is ""..."3.4" do - require 'bigdecimal' +describe "BigDecimal#truncate" do - 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') - end + before :each do + @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 - @arr.each do |x| - BigDecimal(x).truncate.kind_of?(Integer).should == true - end + it "returns value of type Integer." do + @arr.each do |x| + BigDecimal(x).truncate.kind_of?(Integer).should == true end + end - it "returns the integer part as a BigDecimal if no precision given" do - BigDecimal(@arr[0]).truncate.should == 3 - BigDecimal(@arr[1]).truncate.should == 8 - BigDecimal(@arr[2]).truncate.should == 3 - BigDecimal('0').truncate.should == 0 - BigDecimal('0.1').truncate.should == 0 - BigDecimal('-0.1').truncate.should == 0 - BigDecimal('1.5').truncate.should == 1 - BigDecimal('-1.5').truncate.should == -1 - BigDecimal('1E10').truncate.should == BigDecimal('1E10') - BigDecimal('-1E10').truncate.should == BigDecimal('-1E10') - BigDecimal('1.8888E10').truncate.should == BigDecimal('1.8888E10') - BigDecimal('-1E-1').truncate.should == 0 - end + it "returns the integer part as a BigDecimal if no precision given" do + BigDecimal(@arr[0]).truncate.should == 3 + BigDecimal(@arr[1]).truncate.should == 8 + BigDecimal(@arr[2]).truncate.should == 3 + BigDecimal('0').truncate.should == 0 + BigDecimal('0.1').truncate.should == 0 + BigDecimal('-0.1').truncate.should == 0 + BigDecimal('1.5').truncate.should == 1 + BigDecimal('-1.5').truncate.should == -1 + BigDecimal('1E10').truncate.should == BigDecimal('1E10') + BigDecimal('-1E10').truncate.should == BigDecimal('-1E10') + BigDecimal('1.8888E10').truncate.should == BigDecimal('1.8888E10') + BigDecimal('-1E-1').truncate.should == 0 + end - it "returns value of given precision otherwise" do - BigDecimal('-1.55').truncate(1).should == BigDecimal('-1.5') - BigDecimal('1.55').truncate(1).should == BigDecimal('1.5') - BigDecimal(@arr[0]).truncate(2).should == BigDecimal("3.14") - BigDecimal('123.456').truncate(2).should == BigDecimal("123.45") - BigDecimal('123.456789').truncate(4).should == BigDecimal("123.4567") - BigDecimal('0.456789').truncate(10).should == BigDecimal("0.456789") - BigDecimal('-1E-1').truncate(1).should == BigDecimal('-0.1') - BigDecimal('-1E-1').truncate(2).should == BigDecimal('-0.1E0') - BigDecimal('-1E-1').truncate.should == BigDecimal('0') - BigDecimal('-1E-1').truncate(0).should == BigDecimal('0') - BigDecimal('-1E-1').truncate(-1).should == BigDecimal('0') - BigDecimal('-1E-1').truncate(-2).should == BigDecimal('0') + it "returns value of given precision otherwise" do + BigDecimal('-1.55').truncate(1).should == BigDecimal('-1.5') + BigDecimal('1.55').truncate(1).should == BigDecimal('1.5') + BigDecimal(@arr[0]).truncate(2).should == BigDecimal("3.14") + BigDecimal('123.456').truncate(2).should == BigDecimal("123.45") + BigDecimal('123.456789').truncate(4).should == BigDecimal("123.4567") + BigDecimal('0.456789').truncate(10).should == BigDecimal("0.456789") + BigDecimal('-1E-1').truncate(1).should == BigDecimal('-0.1') + BigDecimal('-1E-1').truncate(2).should == BigDecimal('-0.1E0') + BigDecimal('-1E-1').truncate.should == BigDecimal('0') + BigDecimal('-1E-1').truncate(0).should == BigDecimal('0') + BigDecimal('-1E-1').truncate(-1).should == BigDecimal('0') + BigDecimal('-1E-1').truncate(-2).should == BigDecimal('0') - BigDecimal(@arr[1]).truncate(1).should == BigDecimal("8.7") - BigDecimal(@arr[2]).truncate(100).should == BigDecimal(\ - "3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679") - end + BigDecimal(@arr[1]).truncate(1).should == BigDecimal("8.7") + BigDecimal(@arr[2]).truncate(100).should == BigDecimal(\ + "3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679") + end - it "sets n digits left of the decimal point to 0, if given n < 0" do - @big.truncate(-1).should == BigDecimal("123450.0") - @big.truncate(-2).should == BigDecimal("123400.0") - BigDecimal(@arr[2]).truncate(-1).should == 0 - end + it "sets n digits left of the decimal point to 0, if given n < 0" do + @big.truncate(-1).should == BigDecimal("123450.0") + @big.truncate(-2).should == BigDecimal("123400.0") + BigDecimal(@arr[2]).truncate(-1).should == 0 + end - it "returns NaN if self is NaN" do - @nan.truncate(-1).should.nan? - @nan.truncate(+1).should.nan? - @nan.truncate(0).should.nan? - end + it "returns NaN if self is NaN" do + @nan.truncate(-1).should.nan? + @nan.truncate(+1).should.nan? + @nan.truncate(0).should.nan? + end - it "returns Infinity if self is infinite" do - @infinity.truncate(-1).should == @infinity - @infinity.truncate(+1).should == @infinity - @infinity.truncate(0).should == @infinity + it "returns Infinity if self is infinite" do + @infinity.truncate(-1).should == @infinity + @infinity.truncate(+1).should == @infinity + @infinity.truncate(0).should == @infinity - @infinity_negative.truncate(-1).should == @infinity_negative - @infinity_negative.truncate(+1).should == @infinity_negative - @infinity_negative.truncate(0).should == @infinity_negative - end + @infinity_negative.truncate(-1).should == @infinity_negative + @infinity_negative.truncate(+1).should == @infinity_negative + @infinity_negative.truncate(0).should == @infinity_negative + end - it "returns the same value if self is special value" do - -> { @nan.truncate }.should raise_error(FloatDomainError) - -> { @infinity.truncate }.should raise_error(FloatDomainError) - -> { @infinity_negative.truncate }.should raise_error(FloatDomainError) - end + it "returns the same value if self is special value" do + -> { @nan.truncate }.should raise_error(FloatDomainError) + -> { @infinity.truncate }.should raise_error(FloatDomainError) + -> { @infinity_negative.truncate }.should raise_error(FloatDomainError) end end diff --git a/spec/ruby/library/bigdecimal/uminus_spec.rb b/spec/ruby/library/bigdecimal/uminus_spec.rb index 612321915f3..c780cdfac5a 100644 --- a/spec/ruby/library/bigdecimal/uminus_spec.rb +++ b/spec/ruby/library/bigdecimal/uminus_spec.rb @@ -1,61 +1,58 @@ require_relative '../../spec_helper' +require 'bigdecimal' -ruby_version_is ""..."3.4" do - require 'bigdecimal' - - describe "BigDecimal#-@" do - before :each do - @one = BigDecimal("1") - @zero = BigDecimal("0") - @zero_pos = BigDecimal("+0") - @zero_neg = BigDecimal("-0") - @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") - @big = BigDecimal("333E99999") - @big_neg = BigDecimal("-333E99999") - @values = [@one, @zero, @zero_pos, @zero_neg, @infinity, - @infinity_minus, @one_minus, @frac_1, @frac_2, @big, @big_neg] - end +describe "BigDecimal#-@" do + before :each do + @one = BigDecimal("1") + @zero = BigDecimal("0") + @zero_pos = BigDecimal("+0") + @zero_neg = BigDecimal("-0") + @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") + @big = BigDecimal("333E99999") + @big_neg = BigDecimal("-333E99999") + @values = [@one, @zero, @zero_pos, @zero_neg, @infinity, + @infinity_minus, @one_minus, @frac_1, @frac_2, @big, @big_neg] + end - it "negates self" do - @one.send(:-@).should == @one_minus - @one_minus.send(:-@).should == @one - @frac_1.send(:-@).should == BigDecimal("-1E-99999") - @frac_2.send(:-@).should == BigDecimal("-0.9E-99999") - @big.send(:-@).should == @big_neg - @big_neg.send(:-@).should == @big - BigDecimal("2.221").send(:-@).should == BigDecimal("-2.221") - BigDecimal("2E10000").send(:-@).should == BigDecimal("-2E10000") - some_number = BigDecimal("2455999221.5512") - some_number_neg = BigDecimal("-2455999221.5512") - some_number.send(:-@).should == some_number_neg - (-BigDecimal("-5.5")).should == BigDecimal("5.5") - another_number = BigDecimal("-8.551551551551551551") - another_number_pos = BigDecimal("8.551551551551551551") - another_number.send(:-@).should == another_number_pos - @values.each do |val| - (val.send(:-@).send(:-@)).should == val - end + it "negates self" do + @one.send(:-@).should == @one_minus + @one_minus.send(:-@).should == @one + @frac_1.send(:-@).should == BigDecimal("-1E-99999") + @frac_2.send(:-@).should == BigDecimal("-0.9E-99999") + @big.send(:-@).should == @big_neg + @big_neg.send(:-@).should == @big + BigDecimal("2.221").send(:-@).should == BigDecimal("-2.221") + BigDecimal("2E10000").send(:-@).should == BigDecimal("-2E10000") + some_number = BigDecimal("2455999221.5512") + some_number_neg = BigDecimal("-2455999221.5512") + some_number.send(:-@).should == some_number_neg + (-BigDecimal("-5.5")).should == BigDecimal("5.5") + another_number = BigDecimal("-8.551551551551551551") + another_number_pos = BigDecimal("8.551551551551551551") + another_number.send(:-@).should == another_number_pos + @values.each do |val| + (val.send(:-@).send(:-@)).should == val end + end - it "properly handles special values" do - @infinity.send(:-@).should == @infinity_minus - @infinity_minus.send(:-@).should == @infinity - @infinity.send(:-@).infinite?.should == -1 - @infinity_minus.send(:-@).infinite?.should == 1 + it "properly handles special values" do + @infinity.send(:-@).should == @infinity_minus + @infinity_minus.send(:-@).should == @infinity + @infinity.send(:-@).infinite?.should == -1 + @infinity_minus.send(:-@).infinite?.should == 1 - @zero.send(:-@).should == @zero - @zero.send(:-@).sign.should == -1 - @zero_pos.send(:-@).should == @zero - @zero_pos.send(:-@).sign.should == -1 - @zero_neg.send(:-@).should == @zero - @zero_neg.send(:-@).sign.should == 1 + @zero.send(:-@).should == @zero + @zero.send(:-@).sign.should == -1 + @zero_pos.send(:-@).should == @zero + @zero_pos.send(:-@).sign.should == -1 + @zero_neg.send(:-@).should == @zero + @zero_neg.send(:-@).sign.should == 1 - @nan.send(:-@).should.nan? - end + @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 9610593401c..77483046b74 100644 --- a/spec/ruby/library/bigdecimal/uplus_spec.rb +++ b/spec/ruby/library/bigdecimal/uplus_spec.rb @@ -1,20 +1,17 @@ require_relative '../../spec_helper' +require 'bigdecimal' -ruby_version_is ""..."3.4" do - require 'bigdecimal' - - describe "BigDecimal#+@" do - it "returns the same value with same sign (twos complement)" do - first = BigDecimal("34.56") - first.send(:+@).should == first - second = BigDecimal("-34.56") - second.send(:+@).should == second - third = BigDecimal("0.0") - third.send(:+@).should == third - fourth = BigDecimal("2E1000000") - fourth.send(:+@).should == fourth - fifth = BigDecimal("123456789E-1000000") - fifth.send(:+@).should == fifth - end +describe "BigDecimal#+@" do + it "returns the same value with same sign (twos complement)" do + first = BigDecimal("34.56") + first.send(:+@).should == first + second = BigDecimal("-34.56") + second.send(:+@).should == second + third = BigDecimal("0.0") + third.send(:+@).should == third + fourth = BigDecimal("2E1000000") + fourth.send(:+@).should == fourth + fifth = BigDecimal("123456789E-1000000") + fifth.send(:+@).should == fifth end end diff --git a/spec/ruby/library/bigdecimal/util_spec.rb b/spec/ruby/library/bigdecimal/util_spec.rb index 4ef82935d15..fc67fcf200b 100644 --- a/spec/ruby/library/bigdecimal/util_spec.rb +++ b/spec/ruby/library/bigdecimal/util_spec.rb @@ -1,43 +1,40 @@ require_relative '../../spec_helper' +require 'bigdecimal' +require 'bigdecimal/util' -ruby_version_is ""..."3.4" do - 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 +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 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 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 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 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 + 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 + 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/zero_spec.rb b/spec/ruby/library/bigdecimal/zero_spec.rb index 94bd7d1a407..2563210939e 100644 --- a/spec/ruby/library/bigdecimal/zero_spec.rb +++ b/spec/ruby/library/bigdecimal/zero_spec.rb @@ -1,30 +1,27 @@ require_relative '../../spec_helper' +require 'bigdecimal' -ruby_version_is ""..."3.4" do - require 'bigdecimal' +describe "BigDecimal#zero?" do - 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.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").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 + it "returns true if self does equal zero" do + really_small_zero = BigDecimal("0E-200000000") + really_big_zero = BigDecimal("0E200000000000") + 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").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 22df38bb294..00000000000 --- a/spec/ruby/library/bigmath/log_spec.rb +++ /dev/null @@ -1,13 +0,0 @@ -require_relative '../../spec_helper' - -ruby_version_is ""..."3.4" do - 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 -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 d3f667c602e..599e640624e 100644 --- a/spec/ruby/library/csv/basicwriter/close_on_terminate_spec.rb +++ b/spec/ruby/library/csv/basicwriter/close_on_terminate_spec.rb @@ -1,9 +1,6 @@ require_relative '../../../spec_helper' +require 'csv' -ruby_version_is ""..."3.4" do - require 'csv' - - describe "CSV::BasicWriter#close_on_terminate" do - it "needs to be reviewed for spec completeness" - end +describe "CSV::BasicWriter#close_on_terminate" do + it "needs to be reviewed for spec completeness" end diff --git a/spec/ruby/library/csv/basicwriter/initialize_spec.rb b/spec/ruby/library/csv/basicwriter/initialize_spec.rb index af86bc177bd..2c13c93f2eb 100644 --- a/spec/ruby/library/csv/basicwriter/initialize_spec.rb +++ b/spec/ruby/library/csv/basicwriter/initialize_spec.rb @@ -1,9 +1,6 @@ require_relative '../../../spec_helper' +require 'csv' -ruby_version_is ""..."3.4" do - require 'csv' - - describe "CSV::BasicWriter#initialize" do - it "needs to be reviewed for spec completeness" - end +describe "CSV::BasicWriter#initialize" do + it "needs to be reviewed for spec completeness" end diff --git a/spec/ruby/library/csv/basicwriter/terminate_spec.rb b/spec/ruby/library/csv/basicwriter/terminate_spec.rb index 5396295a616..8c53db3f0ba 100644 --- a/spec/ruby/library/csv/basicwriter/terminate_spec.rb +++ b/spec/ruby/library/csv/basicwriter/terminate_spec.rb @@ -1,9 +1,6 @@ require_relative '../../../spec_helper' +require 'csv' -ruby_version_is ""..."3.4" do - require 'csv' - - describe "CSV::BasicWriter#terminate" do - it "needs to be reviewed for spec completeness" - end +describe "CSV::BasicWriter#terminate" do + it "needs to be reviewed for spec completeness" end diff --git a/spec/ruby/library/csv/cell/data_spec.rb b/spec/ruby/library/csv/cell/data_spec.rb index 14f49ace964..aa034b0b62e 100644 --- a/spec/ruby/library/csv/cell/data_spec.rb +++ b/spec/ruby/library/csv/cell/data_spec.rb @@ -1,9 +1,6 @@ require_relative '../../../spec_helper' +require 'csv' -ruby_version_is ""..."3.4" do - require 'csv' - - describe "CSV::Cell#data" do - it "needs to be reviewed for spec completeness" - end +describe "CSV::Cell#data" do + it "needs to be reviewed for spec completeness" end diff --git a/spec/ruby/library/csv/cell/initialize_spec.rb b/spec/ruby/library/csv/cell/initialize_spec.rb index ff3ac554708..c9e506676ca 100644 --- a/spec/ruby/library/csv/cell/initialize_spec.rb +++ b/spec/ruby/library/csv/cell/initialize_spec.rb @@ -1,9 +1,6 @@ require_relative '../../../spec_helper' +require 'csv' -ruby_version_is ""..."3.4" do - require 'csv' - - describe "CSV::Cell#initialize" do - it "needs to be reviewed for spec completeness" - end +describe "CSV::Cell#initialize" do + it "needs to be reviewed for spec completeness" end diff --git a/spec/ruby/library/csv/foreach_spec.rb b/spec/ruby/library/csv/foreach_spec.rb index c8aa1b80091..36b3cd152fa 100644 --- a/spec/ruby/library/csv/foreach_spec.rb +++ b/spec/ruby/library/csv/foreach_spec.rb @@ -1,9 +1,6 @@ require_relative '../../spec_helper' +require 'csv' -ruby_version_is ""..."3.4" do - require 'csv' - - describe "CSV.foreach" do - it "needs to be reviewed for spec completeness" - end +describe "CSV.foreach" do + it "needs to be reviewed for spec completeness" end diff --git a/spec/ruby/library/csv/generate_line_spec.rb b/spec/ruby/library/csv/generate_line_spec.rb index 0830bbdb63f..656365b109e 100644 --- a/spec/ruby/library/csv/generate_line_spec.rb +++ b/spec/ruby/library/csv/generate_line_spec.rb @@ -1,33 +1,30 @@ require_relative '../../spec_helper' +require 'csv' -ruby_version_is ""..."3.4" do - require 'csv' +describe "CSV.generate_line" do - describe "CSV.generate_line" do - - it "generates an empty string" do - result = CSV.generate_line([]) - result.should == "\n" - end + it "generates an empty string" do + result = CSV.generate_line([]) + result.should == "\n" + end - it "generates the string 'foo,bar'" do - result = CSV.generate_line(["foo", "bar"]) - result.should == "foo,bar\n" - end + it "generates the string 'foo,bar'" do + result = CSV.generate_line(["foo", "bar"]) + result.should == "foo,bar\n" + end - it "generates the string 'foo;bar'" do - result = CSV.generate_line(["foo", "bar"], col_sep: ?;) - result.should == "foo;bar\n" - end + it "generates the string 'foo;bar'" do + result = CSV.generate_line(["foo", "bar"], col_sep: ?;) + result.should == "foo;bar\n" + end - it "generates the string 'foo,,bar'" do - result = CSV.generate_line(["foo", nil, "bar"]) - result.should == "foo,,bar\n" - end + it "generates the string 'foo,,bar'" do + result = CSV.generate_line(["foo", nil, "bar"]) + result.should == "foo,,bar\n" + end - it "generates the string 'foo;;bar'" do - result = CSV.generate_line(["foo", nil, "bar"], col_sep: ?;) - result.should == "foo;;bar\n" - end + it "generates the string 'foo;;bar'" do + result = CSV.generate_line(["foo", nil, "bar"], col_sep: ?;) + result.should == "foo;;bar\n" end end diff --git a/spec/ruby/library/csv/generate_row_spec.rb b/spec/ruby/library/csv/generate_row_spec.rb index aff5332a9e9..79dfc34000a 100644 --- a/spec/ruby/library/csv/generate_row_spec.rb +++ b/spec/ruby/library/csv/generate_row_spec.rb @@ -1,9 +1,6 @@ require_relative '../../spec_helper' +require 'csv' -ruby_version_is ""..."3.4" do - require 'csv' - - describe "CSV.generate_row" do - it "needs to be reviewed for spec completeness" - end +describe "CSV.generate_row" do + it "needs to be reviewed for spec completeness" end diff --git a/spec/ruby/library/csv/generate_spec.rb b/spec/ruby/library/csv/generate_spec.rb index de476d437f2..0a1e3d9604f 100644 --- a/spec/ruby/library/csv/generate_spec.rb +++ b/spec/ruby/library/csv/generate_spec.rb @@ -1,35 +1,32 @@ require_relative '../../spec_helper' +require 'csv' +require 'tempfile' -ruby_version_is ""..."3.4" do - require 'csv' - require 'tempfile' +describe "CSV.generate" do - describe "CSV.generate" do - - it "returns CSV string" do - csv_str = CSV.generate do |csv| - csv.add_row [1, 2, 3] - csv << [4, 5, 6] - end - csv_str.should == "1,2,3\n4,5,6\n" + it "returns CSV string" do + csv_str = CSV.generate do |csv| + csv.add_row [1, 2, 3] + csv << [4, 5, 6] end + csv_str.should == "1,2,3\n4,5,6\n" + end - it "accepts a col separator" do - csv_str = CSV.generate(col_sep: ";") do |csv| - csv.add_row [1, 2, 3] - csv << [4, 5, 6] - end - csv_str.should == "1;2;3\n4;5;6\n" + it "accepts a col separator" do + csv_str = CSV.generate(col_sep: ";") do |csv| + csv.add_row [1, 2, 3] + csv << [4, 5, 6] end + csv_str.should == "1;2;3\n4;5;6\n" + end - it "appends and returns the argument itself" do - str = "" - csv_str = CSV.generate(str) do |csv| - csv.add_row [1, 2, 3] - csv << [4, 5, 6] - end - csv_str.should equal str - str.should == "1,2,3\n4,5,6\n" + it "appends and returns the argument itself" do + str = "" + csv_str = CSV.generate(str) do |csv| + csv.add_row [1, 2, 3] + csv << [4, 5, 6] end + 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 5711a816ecd..e2fda86080d 100644 --- a/spec/ruby/library/csv/iobuf/close_spec.rb +++ b/spec/ruby/library/csv/iobuf/close_spec.rb @@ -1,9 +1,6 @@ require_relative '../../../spec_helper' +require 'csv' -ruby_version_is ""..."3.4" do - require 'csv' - - describe "CSV::IOBuf#close" do - it "needs to be reviewed for spec completeness" - end +describe "CSV::IOBuf#close" do + it "needs to be reviewed for spec completeness" end diff --git a/spec/ruby/library/csv/iobuf/initialize_spec.rb b/spec/ruby/library/csv/iobuf/initialize_spec.rb index 0073bd44813..f08e82548a0 100644 --- a/spec/ruby/library/csv/iobuf/initialize_spec.rb +++ b/spec/ruby/library/csv/iobuf/initialize_spec.rb @@ -1,9 +1,6 @@ require_relative '../../../spec_helper' +require 'csv' -ruby_version_is ""..."3.4" do - require 'csv' - - describe "CSV::IOBuf#initialize" do - it "needs to be reviewed for spec completeness" - end +describe "CSV::IOBuf#initialize" do + it "needs to be reviewed for spec completeness" end diff --git a/spec/ruby/library/csv/iobuf/read_spec.rb b/spec/ruby/library/csv/iobuf/read_spec.rb index e74d8178ddf..b45334ee2ae 100644 --- a/spec/ruby/library/csv/iobuf/read_spec.rb +++ b/spec/ruby/library/csv/iobuf/read_spec.rb @@ -1,9 +1,6 @@ require_relative '../../../spec_helper' +require 'csv' -ruby_version_is ""..."3.4" do - require 'csv' - - describe "CSV::IOBuf#read" do - it "needs to be reviewed for spec completeness" - end +describe "CSV::IOBuf#read" do + it "needs to be reviewed for spec completeness" end diff --git a/spec/ruby/library/csv/iobuf/terminate_spec.rb b/spec/ruby/library/csv/iobuf/terminate_spec.rb index e4ab00bc4f2..69289e960c2 100644 --- a/spec/ruby/library/csv/iobuf/terminate_spec.rb +++ b/spec/ruby/library/csv/iobuf/terminate_spec.rb @@ -1,9 +1,6 @@ require_relative '../../../spec_helper' +require 'csv' -ruby_version_is ""..."3.4" do - require 'csv' - - describe "CSV::IOBuf#terminate" do - it "needs to be reviewed for spec completeness" - end +describe "CSV::IOBuf#terminate" do + it "needs to be reviewed for spec completeness" end 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 25026091aa2..4887ade1a1f 100644 --- a/spec/ruby/library/csv/ioreader/close_on_terminate_spec.rb +++ b/spec/ruby/library/csv/ioreader/close_on_terminate_spec.rb @@ -1,9 +1,6 @@ require_relative '../../../spec_helper' +require 'csv' -ruby_version_is ""..."3.4" do - require 'csv' - - describe "CSV::IOReader#close_on_terminate" do - it "needs to be reviewed for spec completeness" - end +describe "CSV::IOReader#close_on_terminate" do + it "needs to be reviewed for spec completeness" end diff --git a/spec/ruby/library/csv/ioreader/get_row_spec.rb b/spec/ruby/library/csv/ioreader/get_row_spec.rb index c2258738d11..5fd2178b1b1 100644 --- a/spec/ruby/library/csv/ioreader/get_row_spec.rb +++ b/spec/ruby/library/csv/ioreader/get_row_spec.rb @@ -1,9 +1,6 @@ require_relative '../../../spec_helper' +require 'csv' -ruby_version_is ""..."3.4" do - require 'csv' - - describe "CSV::IOReader#get_row" do - it "needs to be reviewed for spec completeness" - end +describe "CSV::IOReader#get_row" do + it "needs to be reviewed for spec completeness" end diff --git a/spec/ruby/library/csv/ioreader/initialize_spec.rb b/spec/ruby/library/csv/ioreader/initialize_spec.rb index 4f3a75cc8e3..4e8c0964dfb 100644 --- a/spec/ruby/library/csv/ioreader/initialize_spec.rb +++ b/spec/ruby/library/csv/ioreader/initialize_spec.rb @@ -1,9 +1,6 @@ require_relative '../../../spec_helper' +require 'csv' -ruby_version_is ""..."3.4" do - require 'csv' - - describe "CSV::IOReader#initialize" do - it "needs to be reviewed for spec completeness" - end +describe "CSV::IOReader#initialize" do + it "needs to be reviewed for spec completeness" end diff --git a/spec/ruby/library/csv/ioreader/terminate_spec.rb b/spec/ruby/library/csv/ioreader/terminate_spec.rb index 2403d02a9f2..676cd03a0ff 100644 --- a/spec/ruby/library/csv/ioreader/terminate_spec.rb +++ b/spec/ruby/library/csv/ioreader/terminate_spec.rb @@ -1,9 +1,6 @@ require_relative '../../../spec_helper' +require 'csv' -ruby_version_is ""..."3.4" do - require 'csv' - - describe "CSV::IOReader#terminate" do - it "needs to be reviewed for spec completeness" - end +describe "CSV::IOReader#terminate" do + it "needs to be reviewed for spec completeness" end diff --git a/spec/ruby/library/csv/liberal_parsing_spec.rb b/spec/ruby/library/csv/liberal_parsing_spec.rb index d344229d5b9..98786580271 100644 --- a/spec/ruby/library/csv/liberal_parsing_spec.rb +++ b/spec/ruby/library/csv/liberal_parsing_spec.rb @@ -1,22 +1,19 @@ require_relative '../../spec_helper' +require 'csv' -ruby_version_is ""..."3.4" do - require 'csv' - - 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 +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.should_not.liberal_parsing? - 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.should_not.liberal_parsing? - 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 4b5f934e523..2d310cda3e5 100644 --- a/spec/ruby/library/csv/open_spec.rb +++ b/spec/ruby/library/csv/open_spec.rb @@ -1,9 +1,6 @@ require_relative '../../spec_helper' +require 'csv' -ruby_version_is ""..."3.4" do - require 'csv' - - describe "CSV.open" do - it "needs to be reviewed for spec completeness" - end +describe "CSV.open" do + it "needs to be reviewed for spec completeness" end diff --git a/spec/ruby/library/csv/parse_spec.rb b/spec/ruby/library/csv/parse_spec.rb index 921ee0648d4..ef5d4ea3ca1 100644 --- a/spec/ruby/library/csv/parse_spec.rb +++ b/spec/ruby/library/csv/parse_spec.rb @@ -1,96 +1,93 @@ require_relative '../../spec_helper' +require 'csv' -ruby_version_is ""..."3.4" do - require 'csv' - - describe "CSV.parse" do - - it "parses '' into []" do - result = CSV.parse '' - result.should be_kind_of(Array) - result.should == [] - end - - it "parses '\n' into [[]]" do - result = CSV.parse "\n" - result.should == [[]] - end - - it "parses 'foo' into [['foo']]" do - result = CSV.parse 'foo' - result.should == [['foo']] - end - - it "parses 'foo,bar,baz' into [['foo','bar','baz']]" do - result = CSV.parse 'foo,bar,baz' - result.should == [['foo','bar','baz']] - end - - it "parses 'foo,baz' into [[foo,nil,baz]]" do - result = CSV.parse 'foo,,baz' - result.should == [['foo',nil,'baz']] - end - - it "parses '\nfoo' into [[],['foo']]" do - result = CSV.parse "\nfoo" - result.should == [[],['foo']] - end - - it "parses 'foo\n' into [['foo']]" do - result = CSV.parse "foo\n" - result.should == [['foo']] - end - - it "parses 'foo\nbar' into [['foo'],['bar']]" do - result = CSV.parse "foo\nbar" - result.should == [['foo'],['bar']] - end - - it "parses 'foo,bar\nbaz,quz' into [['foo','bar'],['baz','quz']]" do - result = CSV.parse "foo,bar\nbaz,quz" - result.should == [['foo','bar'],['baz','quz']] - end - - it "parses 'foo,bar'\nbaz' into [['foo','bar'],['baz']]" do - result = CSV.parse "foo,bar\nbaz" - result.should == [['foo','bar'],['baz']] - end - - it "parses 'foo\nbar,baz' into [['foo'],['bar','baz']]" do - result = CSV.parse "foo\nbar,baz" - result.should == [['foo'],['bar','baz']] - end - - it "parses '\n\nbar' into [[],[],'bar']]" do - result = CSV.parse "\n\nbar" - result.should == [[],[],['bar']] - end - - it "parses 'foo' into [['foo']] with a separator of ;" do - result = CSV.parse "foo", col_sep: ?; - result.should == [['foo']] - end - - it "parses 'foo;bar' into [['foo','bar']] with a separator of ;" do - result = CSV.parse "foo;bar", col_sep: ?; - result.should == [['foo','bar']] - end - - it "parses 'foo;bar\nbaz;quz' into [['foo','bar'],['baz','quz']] with a separator of ;" do - result = CSV.parse "foo;bar\nbaz;quz", col_sep: ?; - result.should == [['foo','bar'],['baz','quz']] - end - - it "raises CSV::MalformedCSVError exception if input is illegal" do - -> { - CSV.parse('"quoted" field') - }.should raise_error(CSV::MalformedCSVError) - 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 +describe "CSV.parse" do + + it "parses '' into []" do + result = CSV.parse '' + result.should be_kind_of(Array) + result.should == [] + end + + it "parses '\n' into [[]]" do + result = CSV.parse "\n" + result.should == [[]] + end + + it "parses 'foo' into [['foo']]" do + result = CSV.parse 'foo' + result.should == [['foo']] + end + + it "parses 'foo,bar,baz' into [['foo','bar','baz']]" do + result = CSV.parse 'foo,bar,baz' + result.should == [['foo','bar','baz']] + end + + it "parses 'foo,baz' into [[foo,nil,baz]]" do + result = CSV.parse 'foo,,baz' + result.should == [['foo',nil,'baz']] + end + + it "parses '\nfoo' into [[],['foo']]" do + result = CSV.parse "\nfoo" + result.should == [[],['foo']] + end + + it "parses 'foo\n' into [['foo']]" do + result = CSV.parse "foo\n" + result.should == [['foo']] + end + + it "parses 'foo\nbar' into [['foo'],['bar']]" do + result = CSV.parse "foo\nbar" + result.should == [['foo'],['bar']] + end + + it "parses 'foo,bar\nbaz,quz' into [['foo','bar'],['baz','quz']]" do + result = CSV.parse "foo,bar\nbaz,quz" + result.should == [['foo','bar'],['baz','quz']] + end + + it "parses 'foo,bar'\nbaz' into [['foo','bar'],['baz']]" do + result = CSV.parse "foo,bar\nbaz" + result.should == [['foo','bar'],['baz']] + end + + it "parses 'foo\nbar,baz' into [['foo'],['bar','baz']]" do + result = CSV.parse "foo\nbar,baz" + result.should == [['foo'],['bar','baz']] + end + + it "parses '\n\nbar' into [[],[],'bar']]" do + result = CSV.parse "\n\nbar" + result.should == [[],[],['bar']] + end + + it "parses 'foo' into [['foo']] with a separator of ;" do + result = CSV.parse "foo", col_sep: ?; + result.should == [['foo']] + end + + it "parses 'foo;bar' into [['foo','bar']] with a separator of ;" do + result = CSV.parse "foo;bar", col_sep: ?; + result.should == [['foo','bar']] + end + + it "parses 'foo;bar\nbaz;quz' into [['foo','bar'],['baz','quz']] with a separator of ;" do + result = CSV.parse "foo;bar\nbaz;quz", col_sep: ?; + result.should == [['foo','bar'],['baz','quz']] + end + + it "raises CSV::MalformedCSVError exception if input is illegal" do + -> { + CSV.parse('"quoted" field') + }.should raise_error(CSV::MalformedCSVError) + 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 e455a40f739..2e6bb65d56c 100644 --- a/spec/ruby/library/csv/read_spec.rb +++ b/spec/ruby/library/csv/read_spec.rb @@ -1,9 +1,6 @@ require_relative '../../spec_helper' +require 'csv' -ruby_version_is ""..."3.4" do - require 'csv' - - describe "CSV.read" do - it "needs to be reviewed for spec completeness" - end +describe "CSV.read" do + it "needs to be reviewed for spec completeness" end diff --git a/spec/ruby/library/csv/readlines_spec.rb b/spec/ruby/library/csv/readlines_spec.rb index 9ca08592522..14dea34381d 100644 --- a/spec/ruby/library/csv/readlines_spec.rb +++ b/spec/ruby/library/csv/readlines_spec.rb @@ -1,38 +1,35 @@ require_relative '../../spec_helper' +require 'csv' -ruby_version_is ""..."3.4" do - require 'csv' +describe "CSV.readlines" do + it "needs to be reviewed for spec completeness" +end - describe "CSV.readlines" do - it "needs to be reviewed for spec completeness" +describe "CSV#readlines" do + it "returns an Array of Array containing each element in a one-line CSV file" do + file = CSV.new "a, b, c" + file.readlines.should == [["a", " b", " c"]] end - describe "CSV#readlines" do - it "returns an Array of Array containing each element in a one-line CSV file" do - file = CSV.new "a, b, c" - file.readlines.should == [["a", " b", " c"]] - end - - it "returns an Array of Arrays containing each element in a multi-line CSV file" do - file = CSV.new "a, b, c\nd, e, f" - file.readlines.should == [["a", " b", " c"], ["d", " e", " f"]] - end + it "returns an Array of Arrays containing each element in a multi-line CSV file" do + file = CSV.new "a, b, c\nd, e, f" + file.readlines.should == [["a", " b", " c"], ["d", " e", " f"]] + end - it "returns nil for a missing value" do - file = CSV.new "a,, b, c" - file.readlines.should == [["a", nil, " b", " c"]] - end + it "returns nil for a missing value" do + file = CSV.new "a,, b, c" + file.readlines.should == [["a", nil, " b", " c"]] + end - it "raises CSV::MalformedCSVError exception if input is illegal" do - csv = CSV.new('"quoted" field') - -> { csv.readlines }.should raise_error(CSV::MalformedCSVError) - end + it "raises CSV::MalformedCSVError exception if input is illegal" do + csv = CSV.new('"quoted" field') + -> { csv.readlines }.should raise_error(CSV::MalformedCSVError) + 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 + 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 42a9eb68beb..58c530c5007 100644 --- a/spec/ruby/library/csv/streambuf/add_buf_spec.rb +++ b/spec/ruby/library/csv/streambuf/add_buf_spec.rb @@ -1,9 +1,6 @@ require_relative '../../../spec_helper' +require 'csv' -ruby_version_is ""..."3.4" do - require 'csv' - - describe "CSV::StreamBuf#add_buf" do - it "needs to be reviewed for spec completeness" - end +describe "CSV::StreamBuf#add_buf" do + it "needs to be reviewed for spec completeness" end diff --git a/spec/ruby/library/csv/streambuf/buf_size_spec.rb b/spec/ruby/library/csv/streambuf/buf_size_spec.rb index 9a9d34bdefa..1793c8b65e3 100644 --- a/spec/ruby/library/csv/streambuf/buf_size_spec.rb +++ b/spec/ruby/library/csv/streambuf/buf_size_spec.rb @@ -1,9 +1,6 @@ require_relative '../../../spec_helper' +require 'csv' -ruby_version_is ""..."3.4" do - require 'csv' - - describe "CSV::StreamBuf#buf_size" do - it "needs to be reviewed for spec completeness" - end +describe "CSV::StreamBuf#buf_size" do + it "needs to be reviewed for spec completeness" end diff --git a/spec/ruby/library/csv/streambuf/drop_spec.rb b/spec/ruby/library/csv/streambuf/drop_spec.rb index befe0da2f8e..448f0a2196b 100644 --- a/spec/ruby/library/csv/streambuf/drop_spec.rb +++ b/spec/ruby/library/csv/streambuf/drop_spec.rb @@ -1,9 +1,6 @@ require_relative '../../../spec_helper' +require 'csv' -ruby_version_is ""..."3.4" do - require 'csv' - - describe "CSV::StreamBuf#drop" do - it "needs to be reviewed for spec completeness" - end +describe "CSV::StreamBuf#drop" do + it "needs to be reviewed for spec completeness" end diff --git a/spec/ruby/library/csv/streambuf/element_reference_spec.rb b/spec/ruby/library/csv/streambuf/element_reference_spec.rb index 5ff42beeeed..5a75901830e 100644 --- a/spec/ruby/library/csv/streambuf/element_reference_spec.rb +++ b/spec/ruby/library/csv/streambuf/element_reference_spec.rb @@ -1,9 +1,6 @@ require_relative '../../../spec_helper' +require 'csv' -ruby_version_is ""..."3.4" do - require 'csv' - - describe "CSV::StreamBuf#[]" do - it "needs to be reviewed for spec completeness" - end +describe "CSV::StreamBuf#[]" do + it "needs to be reviewed for spec completeness" end diff --git a/spec/ruby/library/csv/streambuf/get_spec.rb b/spec/ruby/library/csv/streambuf/get_spec.rb index 0aa5e72e8f1..2255e55e918 100644 --- a/spec/ruby/library/csv/streambuf/get_spec.rb +++ b/spec/ruby/library/csv/streambuf/get_spec.rb @@ -1,9 +1,6 @@ require_relative '../../../spec_helper' +require 'csv' -ruby_version_is ""..."3.4" do - require 'csv' - - describe "CSV::StreamBuf#get" do - it "needs to be reviewed for spec completeness" - end +describe "CSV::StreamBuf#get" do + it "needs to be reviewed for spec completeness" end 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 f38cb7d8f8c..563b8b2d4ae 100644 --- a/spec/ruby/library/csv/streambuf/idx_is_eos_spec.rb +++ b/spec/ruby/library/csv/streambuf/idx_is_eos_spec.rb @@ -1,9 +1,6 @@ require_relative '../../../spec_helper' +require 'csv' -ruby_version_is ""..."3.4" do - require 'csv' - - describe "CSV::StreamBuf#idx_is_eos?" do - it "needs to be reviewed for spec completeness" - end +describe "CSV::StreamBuf#idx_is_eos?" do + it "needs to be reviewed for spec completeness" end diff --git a/spec/ruby/library/csv/streambuf/initialize_spec.rb b/spec/ruby/library/csv/streambuf/initialize_spec.rb index 3655b02e25b..1273c98094f 100644 --- a/spec/ruby/library/csv/streambuf/initialize_spec.rb +++ b/spec/ruby/library/csv/streambuf/initialize_spec.rb @@ -1,9 +1,6 @@ require_relative '../../../spec_helper' +require 'csv' -ruby_version_is ""..."3.4" do - require 'csv' - - describe "CSV::StreamBuf#initialize" do - it "needs to be reviewed for spec completeness" - end +describe "CSV::StreamBuf#initialize" do + it "needs to be reviewed for spec completeness" end diff --git a/spec/ruby/library/csv/streambuf/is_eos_spec.rb b/spec/ruby/library/csv/streambuf/is_eos_spec.rb index 9891536fead..a0a3c1e0b0d 100644 --- a/spec/ruby/library/csv/streambuf/is_eos_spec.rb +++ b/spec/ruby/library/csv/streambuf/is_eos_spec.rb @@ -1,9 +1,6 @@ require_relative '../../../spec_helper' +require 'csv' -ruby_version_is ""..."3.4" do - require 'csv' - - describe "CSV::StreamBuf#is_eos?" do - it "needs to be reviewed for spec completeness" - end +describe "CSV::StreamBuf#is_eos?" do + it "needs to be reviewed for spec completeness" end diff --git a/spec/ruby/library/csv/streambuf/read_spec.rb b/spec/ruby/library/csv/streambuf/read_spec.rb index 7a82d0d13d5..cf98c534097 100644 --- a/spec/ruby/library/csv/streambuf/read_spec.rb +++ b/spec/ruby/library/csv/streambuf/read_spec.rb @@ -1,9 +1,6 @@ require_relative '../../../spec_helper' +require 'csv' -ruby_version_is ""..."3.4" do - require 'csv' - - describe "CSV::StreamBuf#read" do - it "needs to be reviewed for spec completeness" - end +describe "CSV::StreamBuf#read" do + it "needs to be reviewed for spec completeness" end diff --git a/spec/ruby/library/csv/streambuf/rel_buf_spec.rb b/spec/ruby/library/csv/streambuf/rel_buf_spec.rb index 2994f5c950b..548e347200f 100644 --- a/spec/ruby/library/csv/streambuf/rel_buf_spec.rb +++ b/spec/ruby/library/csv/streambuf/rel_buf_spec.rb @@ -1,9 +1,6 @@ require_relative '../../../spec_helper' +require 'csv' -ruby_version_is ""..."3.4" do - require 'csv' - - describe "CSV::StreamBuf#rel_buf" do - it "needs to be reviewed for spec completeness" - end +describe "CSV::StreamBuf#rel_buf" do + it "needs to be reviewed for spec completeness" end diff --git a/spec/ruby/library/csv/streambuf/terminate_spec.rb b/spec/ruby/library/csv/streambuf/terminate_spec.rb index e720d83703a..247b33184af 100644 --- a/spec/ruby/library/csv/streambuf/terminate_spec.rb +++ b/spec/ruby/library/csv/streambuf/terminate_spec.rb @@ -1,9 +1,6 @@ require_relative '../../../spec_helper' +require 'csv' -ruby_version_is ""..."3.4" do - require 'csv' - - describe "CSV::StreamBuf#terminate" do - it "needs to be reviewed for spec completeness" - end +describe "CSV::StreamBuf#terminate" do + it "needs to be reviewed for spec completeness" end diff --git a/spec/ruby/library/csv/stringreader/get_row_spec.rb b/spec/ruby/library/csv/stringreader/get_row_spec.rb index b4a13cf38a6..5cc34470613 100644 --- a/spec/ruby/library/csv/stringreader/get_row_spec.rb +++ b/spec/ruby/library/csv/stringreader/get_row_spec.rb @@ -1,9 +1,6 @@ require_relative '../../../spec_helper' +require 'csv' -ruby_version_is ""..."3.4" do - require 'csv' - - describe "CSV::StringReader#get_row" do - it "needs to be reviewed for spec completeness" - end +describe "CSV::StringReader#get_row" do + it "needs to be reviewed for spec completeness" end diff --git a/spec/ruby/library/csv/stringreader/initialize_spec.rb b/spec/ruby/library/csv/stringreader/initialize_spec.rb index 2c71d8a8b80..4e3634847e0 100644 --- a/spec/ruby/library/csv/stringreader/initialize_spec.rb +++ b/spec/ruby/library/csv/stringreader/initialize_spec.rb @@ -1,9 +1,6 @@ require_relative '../../../spec_helper' +require 'csv' -ruby_version_is ""..."3.4" do - require 'csv' - - describe "CSV::StringReader#initialize" do - it "needs to be reviewed for spec completeness" - end +describe "CSV::StringReader#initialize" do + it "needs to be reviewed for spec completeness" end diff --git a/spec/ruby/library/csv/writer/add_row_spec.rb b/spec/ruby/library/csv/writer/add_row_spec.rb index 27af76a6372..2f074b45db6 100644 --- a/spec/ruby/library/csv/writer/add_row_spec.rb +++ b/spec/ruby/library/csv/writer/add_row_spec.rb @@ -1,9 +1,6 @@ require_relative '../../../spec_helper' +require 'csv' -ruby_version_is ""..."3.4" do - require 'csv' - - describe "CSV::Writer#add_row" do - it "needs to be reviewed for spec completeness" - end +describe "CSV::Writer#add_row" do + it "needs to be reviewed for spec completeness" end diff --git a/spec/ruby/library/csv/writer/append_spec.rb b/spec/ruby/library/csv/writer/append_spec.rb index 1c968e2b97d..4e1f6728c2b 100644 --- a/spec/ruby/library/csv/writer/append_spec.rb +++ b/spec/ruby/library/csv/writer/append_spec.rb @@ -1,9 +1,6 @@ require_relative '../../../spec_helper' +require 'csv' -ruby_version_is ""..."3.4" do - require 'csv' - - describe "CSV::Writer#<<" do - it "needs to be reviewed for spec completeness" - end +describe "CSV::Writer#<<" do + it "needs to be reviewed for spec completeness" end diff --git a/spec/ruby/library/csv/writer/close_spec.rb b/spec/ruby/library/csv/writer/close_spec.rb index 65292dc4d0e..1a87094bb7c 100644 --- a/spec/ruby/library/csv/writer/close_spec.rb +++ b/spec/ruby/library/csv/writer/close_spec.rb @@ -1,9 +1,6 @@ require_relative '../../../spec_helper' +require 'csv' -ruby_version_is ""..."3.4" do - require 'csv' - - describe "CSV::Writer#close" do - it "needs to be reviewed for spec completeness" - end +describe "CSV::Writer#close" do + it "needs to be reviewed for spec completeness" end diff --git a/spec/ruby/library/csv/writer/create_spec.rb b/spec/ruby/library/csv/writer/create_spec.rb index 0af9f44ff4e..a4514d55780 100644 --- a/spec/ruby/library/csv/writer/create_spec.rb +++ b/spec/ruby/library/csv/writer/create_spec.rb @@ -1,9 +1,6 @@ require_relative '../../../spec_helper' +require 'csv' -ruby_version_is ""..."3.4" do - require 'csv' - - describe "CSV::Writer.create" do - it "needs to be reviewed for spec completeness" - end +describe "CSV::Writer.create" do + it "needs to be reviewed for spec completeness" end diff --git a/spec/ruby/library/csv/writer/generate_spec.rb b/spec/ruby/library/csv/writer/generate_spec.rb index 8200ae566d3..6ea91617772 100644 --- a/spec/ruby/library/csv/writer/generate_spec.rb +++ b/spec/ruby/library/csv/writer/generate_spec.rb @@ -1,9 +1,6 @@ require_relative '../../../spec_helper' +require 'csv' -ruby_version_is ""..."3.4" do - require 'csv' - - describe "CSV::Writer.generate" do - it "needs to be reviewed for spec completeness" - end +describe "CSV::Writer.generate" do + it "needs to be reviewed for spec completeness" end diff --git a/spec/ruby/library/csv/writer/initialize_spec.rb b/spec/ruby/library/csv/writer/initialize_spec.rb index 574f39978a0..6bba8f8d0a2 100644 --- a/spec/ruby/library/csv/writer/initialize_spec.rb +++ b/spec/ruby/library/csv/writer/initialize_spec.rb @@ -1,9 +1,6 @@ require_relative '../../../spec_helper' +require 'csv' -ruby_version_is ""..."3.4" do - require 'csv' - - describe "CSV::Writer#initialize" do - it "needs to be reviewed for spec completeness" - end +describe "CSV::Writer#initialize" do + it "needs to be reviewed for spec completeness" end diff --git a/spec/ruby/library/csv/writer/terminate_spec.rb b/spec/ruby/library/csv/writer/terminate_spec.rb index 56b78e10888..77136dd018d 100644 --- a/spec/ruby/library/csv/writer/terminate_spec.rb +++ b/spec/ruby/library/csv/writer/terminate_spec.rb @@ -1,9 +1,6 @@ require_relative '../../../spec_helper' +require 'csv' -ruby_version_is ""..."3.4" do - require 'csv' - - describe "CSV::Writer#terminate" do - it "needs to be reviewed for spec completeness" - end +describe "CSV::Writer#terminate" do + it "needs to be reviewed for spec completeness" end diff --git a/spec/ruby/library/drb/start_service_spec.rb b/spec/ruby/library/drb/start_service_spec.rb index 1ed2081d80e..57a8cf6e15d 100644 --- a/spec/ruby/library/drb/start_service_spec.rb +++ b/spec/ruby/library/drb/start_service_spec.rb @@ -1,6 +1,8 @@ require_relative '../../spec_helper' -ruby_version_is ""..."3.4" do +# 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' diff --git a/spec/ruby/library/getoptlong/each_option_spec.rb b/spec/ruby/library/getoptlong/each_option_spec.rb index 87dd825264c..c6d82af86d4 100644 --- a/spec/ruby/library/getoptlong/each_option_spec.rb +++ b/spec/ruby/library/getoptlong/each_option_spec.rb @@ -1,10 +1,7 @@ require_relative '../../spec_helper' +require 'getoptlong' +require_relative 'shared/each' -ruby_version_is ""..."3.4" do - require 'getoptlong' - require_relative 'shared/each' - - describe "GetoptLong#each_option" do - it_behaves_like :getoptlong_each, :each_option - end +describe "GetoptLong#each_option" do + it_behaves_like :getoptlong_each, :each_option end diff --git a/spec/ruby/library/getoptlong/each_spec.rb b/spec/ruby/library/getoptlong/each_spec.rb index d40b17d8cb6..d9022f02af2 100644 --- a/spec/ruby/library/getoptlong/each_spec.rb +++ b/spec/ruby/library/getoptlong/each_spec.rb @@ -1,10 +1,7 @@ require_relative '../../spec_helper' +require 'getoptlong' +require_relative 'shared/each' -ruby_version_is ""..."3.4" do - require 'getoptlong' - require_relative 'shared/each' - - describe "GetoptLong#each" do - it_behaves_like :getoptlong_each, :each - end +describe "GetoptLong#each" do + it_behaves_like :getoptlong_each, :each end diff --git a/spec/ruby/library/getoptlong/error_message_spec.rb b/spec/ruby/library/getoptlong/error_message_spec.rb index bcca728720b..1ed9419f6cc 100644 --- a/spec/ruby/library/getoptlong/error_message_spec.rb +++ b/spec/ruby/library/getoptlong/error_message_spec.rb @@ -1,26 +1,23 @@ require_relative '../../spec_helper' +require 'getoptlong' -ruby_version_is ""..."3.4" do - require 'getoptlong' +describe "GetoptLong#error_message" do + it "returns nil if no error occurred" do + opts = GetoptLong.new + opts.error_message.should == nil + end - describe "GetoptLong#error_message" do - it "returns nil if no error occurred" do + it "returns the error message of the last error that occurred" do + argv [] do opts = GetoptLong.new - opts.error_message.should == nil - end - - it "returns the error message of the last error that occurred" do - argv [] do - opts = GetoptLong.new - opts.quiet = true - opts.get - -> { - opts.ordering = GetoptLong::PERMUTE - }.should raise_error(ArgumentError) { |e| - e.message.should == "argument error" - opts.error_message.should == "argument error" - } - end + opts.quiet = true + opts.get + -> { + opts.ordering = GetoptLong::PERMUTE + }.should raise_error(ArgumentError) { |e| + e.message.should == "argument error" + opts.error_message.should == "argument error" + } end end end diff --git a/spec/ruby/library/getoptlong/get_option_spec.rb b/spec/ruby/library/getoptlong/get_option_spec.rb index f8f81bce50e..3cb20443796 100644 --- a/spec/ruby/library/getoptlong/get_option_spec.rb +++ b/spec/ruby/library/getoptlong/get_option_spec.rb @@ -1,10 +1,7 @@ require_relative '../../spec_helper' +require 'getoptlong' +require_relative 'shared/get' -ruby_version_is ""..."3.4" do - require 'getoptlong' - require_relative 'shared/get' - - describe "GetoptLong#get_option" do - it_behaves_like :getoptlong_get, :get_option - end +describe "GetoptLong#get_option" do + it_behaves_like :getoptlong_get, :get_option end diff --git a/spec/ruby/library/getoptlong/get_spec.rb b/spec/ruby/library/getoptlong/get_spec.rb index bb901dff786..a8ec586fc9d 100644 --- a/spec/ruby/library/getoptlong/get_spec.rb +++ b/spec/ruby/library/getoptlong/get_spec.rb @@ -1,10 +1,7 @@ require_relative '../../spec_helper' +require 'getoptlong' +require_relative 'shared/get' -ruby_version_is ""..."3.4" do - require 'getoptlong' - require_relative 'shared/get' - - describe "GetoptLong#get" do - it_behaves_like :getoptlong_get, :get - end +describe "GetoptLong#get" do + it_behaves_like :getoptlong_get, :get end diff --git a/spec/ruby/library/getoptlong/initialize_spec.rb b/spec/ruby/library/getoptlong/initialize_spec.rb index f0e5d605b26..782edbd981c 100644 --- a/spec/ruby/library/getoptlong/initialize_spec.rb +++ b/spec/ruby/library/getoptlong/initialize_spec.rb @@ -1,31 +1,28 @@ require_relative '../../spec_helper' +require 'getoptlong' -ruby_version_is ""..."3.4" do - require 'getoptlong' +describe "GetoptLong#initialize" do + it "sets ordering to REQUIRE_ORDER if ENV['POSIXLY_CORRECT'] is set" do + begin + old_env_value = ENV["POSIXLY_CORRECT"] + ENV["POSIXLY_CORRECT"] = "" - describe "GetoptLong#initialize" do - it "sets ordering to REQUIRE_ORDER if ENV['POSIXLY_CORRECT'] is set" do - begin - old_env_value = ENV["POSIXLY_CORRECT"] - ENV["POSIXLY_CORRECT"] = "" - - opt = GetoptLong.new - opt.ordering.should == GetoptLong::REQUIRE_ORDER - ensure - ENV["POSIXLY_CORRECT"] = old_env_value - end + opt = GetoptLong.new + opt.ordering.should == GetoptLong::REQUIRE_ORDER + ensure + ENV["POSIXLY_CORRECT"] = old_env_value end + end - it "sets ordering to PERMUTE if ENV['POSIXLY_CORRECT'] is not set" do - begin - old_env_value = ENV["POSIXLY_CORRECT"] - ENV["POSIXLY_CORRECT"] = nil + it "sets ordering to PERMUTE if ENV['POSIXLY_CORRECT'] is not set" do + begin + old_env_value = ENV["POSIXLY_CORRECT"] + ENV["POSIXLY_CORRECT"] = nil - opt = GetoptLong.new - opt.ordering.should == GetoptLong::PERMUTE - ensure - ENV["POSIXLY_CORRECT"] = old_env_value - end + opt = GetoptLong.new + opt.ordering.should == GetoptLong::PERMUTE + ensure + ENV["POSIXLY_CORRECT"] = old_env_value end end end diff --git a/spec/ruby/library/getoptlong/ordering_spec.rb b/spec/ruby/library/getoptlong/ordering_spec.rb index b0b5b9be54f..695d1cafa75 100644 --- a/spec/ruby/library/getoptlong/ordering_spec.rb +++ b/spec/ruby/library/getoptlong/ordering_spec.rb @@ -1,41 +1,38 @@ require_relative '../../spec_helper' +require 'getoptlong' -ruby_version_is ""..."3.4" do - require 'getoptlong' - - describe "GetoptLong#ordering=" do - it "raises an ArgumentError if called after processing has started" do - argv [ "--size", "10k", "--verbose" ] do - opts = GetoptLong.new([ '--size', GetoptLong::REQUIRED_ARGUMENT ], - [ '--verbose', GetoptLong::NO_ARGUMENT ]) - opts.quiet = true - opts.get - - -> { - opts.ordering = GetoptLong::PERMUTE - }.should raise_error(ArgumentError) - end - end - - it "raises an ArgumentError if given an invalid value" do - opts = GetoptLong.new +describe "GetoptLong#ordering=" do + it "raises an ArgumentError if called after processing has started" do + argv [ "--size", "10k", "--verbose" ] do + opts = GetoptLong.new([ '--size', GetoptLong::REQUIRED_ARGUMENT ], + [ '--verbose', GetoptLong::NO_ARGUMENT ]) + opts.quiet = true + opts.get -> { - opts.ordering = 12345 + opts.ordering = GetoptLong::PERMUTE }.should raise_error(ArgumentError) end + end - it "does not allow changing ordering to PERMUTE if ENV['POSIXLY_CORRECT'] is set" do - begin - old_env_value = ENV['POSIXLY_CORRECT'] - ENV['POSIXLY_CORRECT'] = "" + it "raises an ArgumentError if given an invalid value" do + opts = GetoptLong.new - opts = GetoptLong.new - opts.ordering = GetoptLong::PERMUTE - opts.ordering.should == GetoptLong::REQUIRE_ORDER - ensure - ENV['POSIXLY_CORRECT'] = old_env_value - end + -> { + opts.ordering = 12345 + }.should raise_error(ArgumentError) + end + + it "does not allow changing ordering to PERMUTE if ENV['POSIXLY_CORRECT'] is set" do + begin + old_env_value = ENV['POSIXLY_CORRECT'] + ENV['POSIXLY_CORRECT'] = "" + + opts = GetoptLong.new + opts.ordering = GetoptLong::PERMUTE + opts.ordering.should == GetoptLong::REQUIRE_ORDER + ensure + ENV['POSIXLY_CORRECT'] = old_env_value end end end diff --git a/spec/ruby/library/getoptlong/set_options_spec.rb b/spec/ruby/library/getoptlong/set_options_spec.rb index 0e77696a951..36b9c579c41 100644 --- a/spec/ruby/library/getoptlong/set_options_spec.rb +++ b/spec/ruby/library/getoptlong/set_options_spec.rb @@ -1,101 +1,98 @@ require_relative '../../spec_helper' +require 'getoptlong' -ruby_version_is ""..."3.4" do - require 'getoptlong' - - describe "GetoptLong#set_options" do - before :each do - @opts = GetoptLong.new - end +describe "GetoptLong#set_options" do + before :each do + @opts = GetoptLong.new + end - it "allows setting command line options" do - argv ["--size", "10k", "-v", "arg1", "arg2"] do - @opts.set_options( - ["--size", GetoptLong::REQUIRED_ARGUMENT], - ["--verbose", "-v", GetoptLong::NO_ARGUMENT] - ) + it "allows setting command line options" do + argv ["--size", "10k", "-v", "arg1", "arg2"] do + @opts.set_options( + ["--size", GetoptLong::REQUIRED_ARGUMENT], + ["--verbose", "-v", GetoptLong::NO_ARGUMENT] + ) - @opts.get.should == ["--size", "10k"] - @opts.get.should == ["--verbose", ""] - @opts.get.should == nil - end + @opts.get.should == ["--size", "10k"] + @opts.get.should == ["--verbose", ""] + @opts.get.should == nil end + end - it "discards previously defined command line options" do - argv ["--size", "10k", "-v", "arg1", "arg2"] do - @opts.set_options( - ["--size", GetoptLong::REQUIRED_ARGUMENT], - ["--verbose", "-v", GetoptLong::NO_ARGUMENT] - ) + it "discards previously defined command line options" do + argv ["--size", "10k", "-v", "arg1", "arg2"] do + @opts.set_options( + ["--size", GetoptLong::REQUIRED_ARGUMENT], + ["--verbose", "-v", GetoptLong::NO_ARGUMENT] + ) - @opts.set_options( - ["-s", "--size", GetoptLong::REQUIRED_ARGUMENT], - ["-v", GetoptLong::NO_ARGUMENT] - ) + @opts.set_options( + ["-s", "--size", GetoptLong::REQUIRED_ARGUMENT], + ["-v", GetoptLong::NO_ARGUMENT] + ) - @opts.get.should == ["-s", "10k"] - @opts.get.should == ["-v", ""] - @opts.get.should == nil - end + @opts.get.should == ["-s", "10k"] + @opts.get.should == ["-v", ""] + @opts.get.should == nil end + end - it "raises an ArgumentError if too many argument flags where given" do - argv [] do - -> { - @opts.set_options(["--size", GetoptLong::NO_ARGUMENT, GetoptLong::REQUIRED_ARGUMENT]) - }.should raise_error(ArgumentError) - end + it "raises an ArgumentError if too many argument flags where given" do + argv [] do + -> { + @opts.set_options(["--size", GetoptLong::NO_ARGUMENT, GetoptLong::REQUIRED_ARGUMENT]) + }.should raise_error(ArgumentError) end + end - it "raises a RuntimeError if processing has already started" do - argv [] do - @opts.get - -> { - @opts.set_options() - }.should raise_error(RuntimeError) - end + it "raises a RuntimeError if processing has already started" do + argv [] do + @opts.get + -> { + @opts.set_options() + }.should raise_error(RuntimeError) end + end - it "raises an ArgumentError if no argument flag was given" do - argv [] do - -> { - @opts.set_options(["--size"]) - }.should raise_error(ArgumentError) - end + it "raises an ArgumentError if no argument flag was given" do + argv [] do + -> { + @opts.set_options(["--size"]) + }.should raise_error(ArgumentError) end + end - it "raises an ArgumentError if one of the given arguments is not an Array" do - argv [] do - -> { - @opts.set_options( - ["--size", GetoptLong::REQUIRED_ARGUMENT], - "test") - }.should raise_error(ArgumentError) - end + it "raises an ArgumentError if one of the given arguments is not an Array" do + argv [] do + -> { + @opts.set_options( + ["--size", GetoptLong::REQUIRED_ARGUMENT], + "test") + }.should raise_error(ArgumentError) end + end - it "raises an ArgumentError if the same option is given twice" do - argv [] do - -> { - @opts.set_options( - ["--size", GetoptLong::NO_ARGUMENT], - ["--size", GetoptLong::OPTIONAL_ARGUMENT]) - }.should raise_error(ArgumentError) + it "raises an ArgumentError if the same option is given twice" do + argv [] do + -> { + @opts.set_options( + ["--size", GetoptLong::NO_ARGUMENT], + ["--size", GetoptLong::OPTIONAL_ARGUMENT]) + }.should raise_error(ArgumentError) - -> { - @opts.set_options( - ["--size", GetoptLong::NO_ARGUMENT], - ["-s", "--size", GetoptLong::OPTIONAL_ARGUMENT]) - }.should raise_error(ArgumentError) - end + -> { + @opts.set_options( + ["--size", GetoptLong::NO_ARGUMENT], + ["-s", "--size", GetoptLong::OPTIONAL_ARGUMENT]) + }.should raise_error(ArgumentError) end + end - it "raises an ArgumentError if the given option is invalid" do - argv [] do - -> { - @opts.set_options(["-size", GetoptLong::NO_ARGUMENT]) - }.should raise_error(ArgumentError) - end + it "raises an ArgumentError if the given option is invalid" do + argv [] do + -> { + @opts.set_options(["-size", GetoptLong::NO_ARGUMENT]) + }.should raise_error(ArgumentError) end end end diff --git a/spec/ruby/library/getoptlong/terminate_spec.rb b/spec/ruby/library/getoptlong/terminate_spec.rb index f767fcaa0a3..a12d1df2ef6 100644 --- a/spec/ruby/library/getoptlong/terminate_spec.rb +++ b/spec/ruby/library/getoptlong/terminate_spec.rb @@ -1,33 +1,30 @@ require_relative '../../spec_helper' +require 'getoptlong' -ruby_version_is ""..."3.4" do - require 'getoptlong' - - describe "GetoptLong#terminate" 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 +describe "GetoptLong#terminate" 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 "terminates option processing" do - argv [ "--size", "10k", "-v", "-q", "a.txt", "b.txt" ] do - @opts.get.should == [ "--size", "10k" ] - @opts.terminate - @opts.get.should == nil - end + it "terminates option processing" do + argv [ "--size", "10k", "-v", "-q", "a.txt", "b.txt" ] do + @opts.get.should == [ "--size", "10k" ] + @opts.terminate + @opts.get.should == nil end + end - it "returns self when option processing is terminated" do - @opts.terminate.should == @opts - end + it "returns self when option processing is terminated" do + @opts.terminate.should == @opts + end - it "returns nil when option processing was already terminated" do - @opts.terminate - @opts.terminate.should == nil - end + it "returns nil when option processing was already terminated" do + @opts.terminate + @opts.terminate.should == nil end end diff --git a/spec/ruby/library/getoptlong/terminated_spec.rb b/spec/ruby/library/getoptlong/terminated_spec.rb index 06c2ce71f4e..6108a7f6e90 100644 --- a/spec/ruby/library/getoptlong/terminated_spec.rb +++ b/spec/ruby/library/getoptlong/terminated_spec.rb @@ -1,20 +1,17 @@ require_relative '../../spec_helper' +require 'getoptlong' -ruby_version_is ""..."3.4" do - 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.should_not.terminated? - 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.should_not.terminated? + opts.get.should == ["--size", "10k"] + opts.should_not.terminated? - opts.get.should == ["--size", "10k"] - opts.should_not.terminated? - - opts.get.should == nil - opts.should.terminated? - end + opts.get.should == nil + opts.should.terminated? end end end diff --git a/spec/ruby/library/matrix/I_spec.rb b/spec/ruby/library/matrix/I_spec.rb index aa064ed54bc..6eeffe8e98c 100644 --- a/spec/ruby/library/matrix/I_spec.rb +++ b/spec/ruby/library/matrix/I_spec.rb @@ -1,9 +1,6 @@ require_relative '../../spec_helper' +require_relative 'shared/identity' -ruby_version_is ""..."3.1" do - require_relative 'shared/identity' - - describe "Matrix.I" do - it_behaves_like :matrix_identity, :I - end +describe "Matrix.I" do + it_behaves_like :matrix_identity, :I end diff --git a/spec/ruby/library/matrix/antisymmetric_spec.rb b/spec/ruby/library/matrix/antisymmetric_spec.rb index dcc3c30f3e0..200df703cb8 100644 --- a/spec/ruby/library/matrix/antisymmetric_spec.rb +++ b/spec/ruby/library/matrix/antisymmetric_spec.rb @@ -1,38 +1,36 @@ require_relative '../../spec_helper' -ruby_version_is ""..."3.1" do - require 'matrix' +require 'matrix' - describe "Matrix#antisymmetric?" do - it "returns true for an antisymmetric Matrix" do - Matrix[[0, -2, Complex(1, 3)], [2, 0, 5], [-Complex(1, 3), -5, 0]].antisymmetric?.should be_true - end +describe "Matrix#antisymmetric?" do + it "returns true for an antisymmetric Matrix" do + Matrix[[0, -2, Complex(1, 3)], [2, 0, 5], [-Complex(1, 3), -5, 0]].antisymmetric?.should be_true + end - it "returns true for a 0x0 empty matrix" do - Matrix.empty.antisymmetric?.should be_true - end + it "returns true for a 0x0 empty matrix" do + Matrix.empty.antisymmetric?.should be_true + end - it "returns false for non-antisymmetric matrices" do - [ - Matrix[[1, 2, 3], [4, 5, 6], [7, 8, 9]], - Matrix[[1, -2, 3], [2, 0, 6], [-3, -6, 0]], # wrong diagonal element - Matrix[[0, 2, -3], [2, 0, 6], [-3, 6, 0]] # only signs wrong - ].each do |matrix| - matrix.antisymmetric?.should be_false - end + it "returns false for non-antisymmetric matrices" do + [ + Matrix[[1, 2, 3], [4, 5, 6], [7, 8, 9]], + Matrix[[1, -2, 3], [2, 0, 6], [-3, -6, 0]], # wrong diagonal element + Matrix[[0, 2, -3], [2, 0, 6], [-3, 6, 0]] # only signs wrong + ].each do |matrix| + matrix.antisymmetric?.should be_false 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_error(Matrix::ErrDimensionMismatch) - 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_error(Matrix::ErrDimensionMismatch) end end end diff --git a/spec/ruby/library/matrix/build_spec.rb b/spec/ruby/library/matrix/build_spec.rb index d3055a1aa7b..6d8017a3dfd 100644 --- a/spec/ruby/library/matrix/build_spec.rb +++ b/spec/ruby/library/matrix/build_spec.rb @@ -1,76 +1,73 @@ require_relative '../../spec_helper' +require_relative 'fixtures/classes' +require 'matrix' -ruby_version_is ""..."3.1" do - require_relative 'fixtures/classes' - require 'matrix' +describe "Matrix.build" do - 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.row_size.should == 3 - m.column_size.should == 4 - end + it "returns a Matrix object of the given size" do + m = Matrix.build(3, 4){1} + m.should be_an_instance_of(Matrix) + m.row_size.should == 3 + m.column_size.should == 4 + end - it "builds the Matrix using the given block" do - Matrix.build(2, 3){|col, row| 10*col - row}.should == - Matrix[[0, -1, -2], [10, 9, 8]] - end + it "builds the Matrix using the given block" do + Matrix.build(2, 3){|col, row| 10*col - row}.should == + Matrix[[0, -1, -2], [10, 9, 8]] + end - it "iterates through the first row, then the second, ..." do - acc = [] - Matrix.build(2, 3){|*args| acc << args} - acc.should == [[0, 0], [0, 1], [0, 2], [1, 0], [1, 1], [1, 2]] - end + it "iterates through the first row, then the second, ..." do + acc = [] + Matrix.build(2, 3){|*args| acc << args} + acc.should == [[0, 0], [0, 1], [0, 2], [1, 0], [1, 1], [1, 2]] + end - it "returns an Enumerator is no block is given" do - enum = Matrix.build(2, 1) - enum.should be_an_instance_of(Enumerator) - enum.each{1}.should == Matrix[[1], [1]] - end + it "returns an Enumerator is no block is given" do + enum = Matrix.build(2, 1) + enum.should be_an_instance_of(Enumerator) + enum.each{1}.should == Matrix[[1], [1]] + end - it "requires integers as parameters" do - -> { Matrix.build("1", "2"){1} }.should raise_error(TypeError) - -> { Matrix.build(nil, nil){1} }.should raise_error(TypeError) - -> { Matrix.build(1..2){1} }.should raise_error(TypeError) - end + it "requires integers as parameters" do + -> { Matrix.build("1", "2"){1} }.should raise_error(TypeError) + -> { Matrix.build(nil, nil){1} }.should raise_error(TypeError) + -> { Matrix.build(1..2){1} }.should raise_error(TypeError) + end - it "requires non-negative integers" do - -> { Matrix.build(-1, 1){1} }.should raise_error(ArgumentError) - -> { Matrix.build(+1,-1){1} }.should raise_error(ArgumentError) - end + it "requires non-negative integers" do + -> { Matrix.build(-1, 1){1} }.should raise_error(ArgumentError) + -> { Matrix.build(+1,-1){1} }.should raise_error(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.column_size.should == 3 + it "returns empty Matrix if one argument is zero" do + m = Matrix.build(0, 3){ + raise "Should not yield" + } + m.should be_empty + m.column_size.should == 3 - m = Matrix.build(3, 0){ - raise "Should not yield" - } - m.should be_empty - m.row_size.should == 3 - end + m = Matrix.build(3, 0){ + raise "Should not yield" + } + m.should be_empty + m.row_size.should == 3 + end - it "tries to calls :to_int on arguments" do - int = mock('int') - int.should_receive(:to_int).twice.and_return(2) - Matrix.build(int, int){ 1 }.should == Matrix[ [1,1], [1,1] ] - end + it "tries to calls :to_int on arguments" do + int = mock('int') + int.should_receive(:to_int).twice.and_return(2) + Matrix.build(int, int){ 1 }.should == Matrix[ [1,1], [1,1] ] + end - it "builds an nxn Matrix when given only one argument" do - m = Matrix.build(3){1} - m.row_size.should == 3 - m.column_size.should == 3 - end + it "builds an nxn Matrix when given only one argument" do + m = Matrix.build(3){1} + m.row_size.should == 3 + m.column_size.should == 3 end +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) - 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) end end diff --git a/spec/ruby/library/matrix/clone_spec.rb b/spec/ruby/library/matrix/clone_spec.rb index bde119988f1..74e5bf157e7 100644 --- a/spec/ruby/library/matrix/clone_spec.rb +++ b/spec/ruby/library/matrix/clone_spec.rb @@ -1,28 +1,25 @@ require_relative '../../spec_helper' +require_relative 'fixtures/classes' +require 'matrix' -ruby_version_is ""..."3.1" do - require_relative 'fixtures/classes' - require 'matrix' - - describe "Matrix#clone" do - before :each do - @a = Matrix[[1, 2], [3, 4], [5, 6]] - end +describe "Matrix#clone" do + before :each do + @a = Matrix[[1, 2], [3, 4], [5, 6]] + end - it "returns a shallow copy of the matrix" do - b = @a.clone - @a.should_not equal(b) - b.should be_kind_of(Matrix) - b.should == @a - 0.upto(@a.row_size - 1) do |i| - @a.row(i).should_not equal(b.row(i)) - end + it "returns a shallow copy of the matrix" do + b = @a.clone + @a.should_not equal(b) + b.should be_kind_of(Matrix) + b.should == @a + 0.upto(@a.row_size - 1) do |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) - 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) end end end diff --git a/spec/ruby/library/matrix/coerce_spec.rb b/spec/ruby/library/matrix/coerce_spec.rb index aa3a32765a1..4022f00236a 100644 --- a/spec/ruby/library/matrix/coerce_spec.rb +++ b/spec/ruby/library/matrix/coerce_spec.rb @@ -1,11 +1,8 @@ require_relative '../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Matrix#coerce" do - it "allows the division of integer by a Matrix " do - (1/Matrix[[0,1],[-1,0]]).should == Matrix[[0,-1],[1,0]] - end +describe "Matrix#coerce" 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 66ec3486c81..bba640213bd 100644 --- a/spec/ruby/library/matrix/collect_spec.rb +++ b/spec/ruby/library/matrix/collect_spec.rb @@ -1,9 +1,6 @@ require_relative '../../spec_helper' +require_relative 'shared/collect' -ruby_version_is ""..."3.1" do - require_relative 'shared/collect' - - describe "Matrix#collect" do - it_behaves_like :collect, :collect - end +describe "Matrix#collect" do + it_behaves_like :collect, :collect end diff --git a/spec/ruby/library/matrix/column_size_spec.rb b/spec/ruby/library/matrix/column_size_spec.rb index e7b42b101ee..041914e5b9c 100644 --- a/spec/ruby/library/matrix/column_size_spec.rb +++ b/spec/ruby/library/matrix/column_size_spec.rb @@ -1,16 +1,13 @@ require_relative '../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Matrix#column_size" do - it "returns the number of columns" do - Matrix[ [1,2], [3,4] ].column_size.should == 2 - end +describe "Matrix#column_size" do + it "returns the number of columns" do + Matrix[ [1,2], [3,4] ].column_size.should == 2 + end - it "returns 0 for empty matrices" do - Matrix[ [], [] ].column_size.should == 0 - Matrix[ ].column_size.should == 0 - end + it "returns 0 for empty matrices" do + Matrix[ [], [] ].column_size.should == 0 + Matrix[ ].column_size.should == 0 end end diff --git a/spec/ruby/library/matrix/column_spec.rb b/spec/ruby/library/matrix/column_spec.rb index 98a767ad08c..1f3c80964a6 100644 --- a/spec/ruby/library/matrix/column_spec.rb +++ b/spec/ruby/library/matrix/column_spec.rb @@ -1,38 +1,35 @@ require_relative '../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Matrix#column" do - before :all do - @m = Matrix[[1,2,3], [2,3,4]] - end +describe "Matrix#column" do + before :all do + @m = Matrix[[1,2,3], [2,3,4]] + end - it "returns a Vector when called without a block" do - @m.column(1).should == Vector[2,3] - end + it "returns a Vector when called without a block" do + @m.column(1).should == Vector[2,3] + end - it "yields each element in the column to the block" do - a = [] - @m.column(1) {|n| a << n } - a.should == [2,3] - end + it "yields each element in the column to the block" do + a = [] + @m.column(1) {|n| a << n } + a.should == [2,3] + end - it "counts backwards for negative argument" do - @m.column(-1).should == Vector[3, 4] - end + it "counts backwards for negative argument" do + @m.column(-1).should == Vector[3, 4] + end - it "returns self when called with a block" do - @m.column(0) { |x| x }.should equal(@m) - end + it "returns self when called with a block" do + @m.column(0) { |x| x }.should equal(@m) + end - it "returns nil when out of bounds" do - @m.column(3).should == nil - end + it "returns nil when out of bounds" do + @m.column(3).should == nil + end - it "never yields when out of bounds" do - -> { @m.column(3){ raise } }.should_not raise_error - -> { @m.column(-4){ raise } }.should_not raise_error - end + it "never yields when out of bounds" do + -> { @m.column(3){ raise } }.should_not raise_error + -> { @m.column(-4){ raise } }.should_not raise_error end end diff --git a/spec/ruby/library/matrix/column_vector_spec.rb b/spec/ruby/library/matrix/column_vector_spec.rb index afdeaced475..47e866a8d55 100644 --- a/spec/ruby/library/matrix/column_vector_spec.rb +++ b/spec/ruby/library/matrix/column_vector_spec.rb @@ -1,28 +1,25 @@ require_relative '../../spec_helper' +require_relative 'fixtures/classes' +require 'matrix' -ruby_version_is ""..."3.1" do - require_relative 'fixtures/classes' - require 'matrix' +describe "Matrix.column_vector" do - 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 == Matrix[ [4],[5],[6] ] - end + 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 == 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.row_size.should == 0 - m.column_size.should == 1 - 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.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) - 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) end end end diff --git a/spec/ruby/library/matrix/column_vectors_spec.rb b/spec/ruby/library/matrix/column_vectors_spec.rb index 7bec095b9ad..b0cb6f914cc 100644 --- a/spec/ruby/library/matrix/column_vectors_spec.rb +++ b/spec/ruby/library/matrix/column_vectors_spec.rb @@ -1,29 +1,26 @@ require_relative '../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' +describe "Matrix#column_vectors" do - describe "Matrix#column_vectors" do - - before :each do - @vectors = Matrix[ [1,2], [3,4] ].column_vectors - end - - it "returns an Array" do - Matrix[ [1,2], [3,4] ].column_vectors.should be_an_instance_of(Array) - end + before :each do + @vectors = Matrix[ [1,2], [3,4] ].column_vectors + end - it "returns an Array of Vectors" do - @vectors.all? {|v| v.should be_an_instance_of(Vector)} - end + it "returns an Array" do + Matrix[ [1,2], [3,4] ].column_vectors.should be_an_instance_of(Array) + end - it "returns each column as a Vector" do - @vectors.should == [Vector[1,3], Vector[2,4]] - end + it "returns an Array of Vectors" do + @vectors.all? {|v| v.should be_an_instance_of(Vector)} + end - it "returns an empty Array for empty matrices" do - Matrix[ [] ].column_vectors.should == [] - end + it "returns each column as a Vector" do + @vectors.should == [Vector[1,3], Vector[2,4]] + end + it "returns an empty Array for empty matrices" do + Matrix[ [] ].column_vectors.should == [] end + end diff --git a/spec/ruby/library/matrix/columns_spec.rb b/spec/ruby/library/matrix/columns_spec.rb index 757086c14b7..3095fdd7afb 100644 --- a/spec/ruby/library/matrix/columns_spec.rb +++ b/spec/ruby/library/matrix/columns_spec.rb @@ -1,45 +1,42 @@ require_relative '../../spec_helper' +require_relative 'fixtures/classes' +require 'matrix' -ruby_version_is ""..."3.1" do - require_relative 'fixtures/classes' - require 'matrix' - - describe "Matrix.columns" do - before :each do - @a = [1, 2] - @b = [3, 4] - @m = Matrix.columns([@a, @b]) - end +describe "Matrix.columns" do + before :each do + @a = [1, 2] + @b = [3, 4] + @m = Matrix.columns([@a, @b]) + end - it "creates a Matrix from argument columns" do - @m.should be_an_instance_of(Matrix) - @m.column(0).to_a.should == @a - @m.column(1).to_a.should == @b - end + it "creates a Matrix from argument columns" do + @m.should be_an_instance_of(Matrix) + @m.column(0).to_a.should == @a + @m.column(1).to_a.should == @b + end - it "accepts Vectors as argument columns" do - m = Matrix.columns([Vector[*@a], Vector[*@b]]) - m.should == @m - m.column(0).to_a.should == @a - m.column(1).to_a.should == @b - end + it "accepts Vectors as argument columns" do + m = Matrix.columns([Vector[*@a], Vector[*@b]]) + m.should == @m + m.column(0).to_a.should == @a + m.column(1).to_a.should == @b + end - it "handles empty matrices" do - e = Matrix.columns([]) - e.row_size.should == 0 - e.column_size.should == 0 - e.should == Matrix[] + it "handles empty matrices" do + e = Matrix.columns([]) + e.row_size.should == 0 + e.column_size.should == 0 + e.should == Matrix[] - v = Matrix.columns([[],[],[]]) - v.row_size.should == 0 - v.column_size.should == 3 - v.should == Matrix[[], [], []].transpose - end + v = Matrix.columns([[],[],[]]) + v.row_size.should == 0 + v.column_size.should == 3 + v.should == Matrix[[], [], []].transpose + end - describe "for a subclass of Matrix" do - it "returns an instance of that subclass" do - MatrixSub.columns([[1]]).should be_an_instance_of(MatrixSub) - end + describe "for a subclass of Matrix" do + it "returns an instance of that subclass" do + MatrixSub.columns([[1]]).should be_an_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 a9225803994..ecee95c255b 100644 --- a/spec/ruby/library/matrix/conj_spec.rb +++ b/spec/ruby/library/matrix/conj_spec.rb @@ -1,9 +1,6 @@ require_relative '../../spec_helper' +require_relative 'shared/conjugate' -ruby_version_is ""..."3.1" do - require_relative 'shared/conjugate' - - describe "Matrix#conj" do - it_behaves_like :matrix_conjugate, :conj - end +describe "Matrix#conj" do + it_behaves_like :matrix_conjugate, :conj end diff --git a/spec/ruby/library/matrix/conjugate_spec.rb b/spec/ruby/library/matrix/conjugate_spec.rb index b99792a24b9..682bd41d944 100644 --- a/spec/ruby/library/matrix/conjugate_spec.rb +++ b/spec/ruby/library/matrix/conjugate_spec.rb @@ -1,9 +1,6 @@ require_relative '../../spec_helper' +require_relative 'shared/conjugate' -ruby_version_is ""..."3.1" do - require_relative 'shared/conjugate' - - describe "Matrix#conjugate" do - it_behaves_like :matrix_conjugate, :conjugate - end +describe "Matrix#conjugate" do + it_behaves_like :matrix_conjugate, :conjugate end diff --git a/spec/ruby/library/matrix/constructor_spec.rb b/spec/ruby/library/matrix/constructor_spec.rb index d8224b44300..70d77babbb9 100644 --- a/spec/ruby/library/matrix/constructor_spec.rb +++ b/spec/ruby/library/matrix/constructor_spec.rb @@ -1,68 +1,65 @@ require_relative '../../spec_helper' +require_relative 'fixtures/classes' +require 'matrix' -ruby_version_is ""..."3.1" do - require_relative 'fixtures/classes' - require 'matrix' +describe "Matrix.[]" do - describe "Matrix.[]" do - - it "requires arrays as parameters" do - -> { Matrix[5] }.should raise_error(TypeError) - -> { Matrix[nil] }.should raise_error(TypeError) - -> { Matrix[1..2] }.should raise_error(TypeError) - -> { Matrix[[1, 2], 3] }.should raise_error(TypeError) - end + it "requires arrays as parameters" do + -> { Matrix[5] }.should raise_error(TypeError) + -> { Matrix[nil] }.should raise_error(TypeError) + -> { Matrix[1..2] }.should raise_error(TypeError) + -> { Matrix[[1, 2], 3] }.should raise_error(TypeError) + end - it "creates an empty Matrix with no arguments" do - m = Matrix[] - m.column_size.should == 0 - m.row_size.should == 0 - end + it "creates an empty Matrix with no arguments" do + m = Matrix[] + m.column_size.should == 0 + m.row_size.should == 0 + end - it "raises for non-rectangular matrices" do - ->{ Matrix[ [0], [0,1] ] }.should \ - raise_error(Matrix::ErrDimensionMismatch) - ->{ Matrix[ [0,1], [0,1,2], [0,1] ]}.should \ - raise_error(Matrix::ErrDimensionMismatch) - end + it "raises for non-rectangular matrices" do + ->{ Matrix[ [0], [0,1] ] }.should \ + raise_error(Matrix::ErrDimensionMismatch) + ->{ Matrix[ [0,1], [0,1,2], [0,1] ]}.should \ + raise_error(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 == Matrix[ [1, 2], [3, 4] ] - end + it "accepts vector arguments" do + a = Matrix[Vector[1, 2], Vector[3, 4]] + a.should be_an_instance_of(Matrix) + a.should == Matrix[ [1, 2], [3, 4] ] + end - it "tries to calls :to_ary on arguments" do - array = mock('ary') - array.should_receive(:to_ary).and_return([1,2]) - Matrix[array, [3,4] ].should == Matrix[ [1,2], [3,4] ] - end + it "tries to calls :to_ary on arguments" do + array = mock('ary') + array.should_receive(:to_ary).and_return([1,2]) + Matrix[array, [3,4] ].should == Matrix[ [1,2], [3,4] ] + end - it "returns a Matrix object" do - Matrix[ [1] ].should be_an_instance_of(Matrix) - end + it "returns a Matrix object" do + Matrix[ [1] ].should be_an_instance_of(Matrix) + end - it "can create an nxn Matrix" do - m = Matrix[ [20,30], [40.5, 9] ] - m.row_size.should == 2 - m.column_size.should == 2 - m.column(0).should == Vector[20, 40.5] - m.column(1).should == Vector[30, 9] - m.row(0).should == Vector[20, 30] - m.row(1).should == Vector[40.5, 9] - end + it "can create an nxn Matrix" do + m = Matrix[ [20,30], [40.5, 9] ] + m.row_size.should == 2 + m.column_size.should == 2 + m.column(0).should == Vector[20, 40.5] + m.column(1).should == Vector[30, 9] + m.row(0).should == Vector[20, 30] + m.row(1).should == Vector[40.5, 9] + end - it "can create a 0xn Matrix" do - m = Matrix[ [], [], [] ] - m.row_size.should == 3 - m.column_size.should == 0 - end + it "can create a 0xn Matrix" do + m = Matrix[ [], [], [] ] + m.row_size.should == 3 + m.column_size.should == 0 + end - 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) - end + 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) end end end diff --git a/spec/ruby/library/matrix/det_spec.rb b/spec/ruby/library/matrix/det_spec.rb index 7d3d5477357..aa7086cacf2 100644 --- a/spec/ruby/library/matrix/det_spec.rb +++ b/spec/ruby/library/matrix/det_spec.rb @@ -1,10 +1,7 @@ require_relative '../../spec_helper' +require_relative 'shared/determinant' +require 'matrix' -ruby_version_is ""..."3.1" do - require_relative 'shared/determinant' - require 'matrix' - - describe "Matrix#det" do - it_behaves_like :determinant, :det - end +describe "Matrix#det" do + it_behaves_like :determinant, :det end diff --git a/spec/ruby/library/matrix/determinant_spec.rb b/spec/ruby/library/matrix/determinant_spec.rb index bfd91fcf684..825c9907b11 100644 --- a/spec/ruby/library/matrix/determinant_spec.rb +++ b/spec/ruby/library/matrix/determinant_spec.rb @@ -1,10 +1,7 @@ require_relative '../../spec_helper' +require_relative 'shared/determinant' +require 'matrix' -ruby_version_is ""..."3.1" do - require_relative 'shared/determinant' - require 'matrix' - - describe "Matrix#determinant" do - it_behaves_like :determinant, :determinant - end +describe "Matrix#determinant" do + it_behaves_like :determinant, :determinant end diff --git a/spec/ruby/library/matrix/diagonal_spec.rb b/spec/ruby/library/matrix/diagonal_spec.rb index 8c82433fde9..ef9738e73e3 100644 --- a/spec/ruby/library/matrix/diagonal_spec.rb +++ b/spec/ruby/library/matrix/diagonal_spec.rb @@ -1,75 +1,72 @@ require_relative '../../spec_helper' +require_relative 'fixtures/classes' +require 'matrix' -ruby_version_is ""..."3.1" do - require_relative 'fixtures/classes' - require 'matrix' - - describe "Matrix.diagonal" do - before :each do - @m = Matrix.diagonal(10, 11, 12, 13, 14) - end +describe "Matrix.diagonal" do + before :each do + @m = Matrix.diagonal(10, 11, 12, 13, 14) + end - it "returns an object of type Matrix" do - @m.should be_kind_of(Matrix) - end + it "returns an object of type Matrix" do + @m.should be_kind_of(Matrix) + end - it "returns a square Matrix of the right size" do - @m.column_size.should == 5 - @m.row_size.should == 5 - end + it "returns a square Matrix of the right size" do + @m.column_size.should == 5 + @m.row_size.should == 5 + end - it "sets the diagonal to the arguments" do - (0..4).each do |i| - @m[i, i].should == i + 10 - end + it "sets the diagonal to the arguments" do + (0..4).each do |i| + @m[i, i].should == i + 10 end + end - it "fills all non-diagonal cells with 0" do - (0..4).each do |i| - (0..4).each do |j| - if i != j - @m[i, j].should == 0 - end + it "fills all non-diagonal cells with 0" do + (0..4).each do |i| + (0..4).each do |j| + if i != j + @m[i, j].should == 0 end end end + end - describe "for a subclass of Matrix" do - it "returns an instance of that subclass" do - MatrixSub.diagonal(1).should be_an_instance_of(MatrixSub) - end + describe "for a subclass of Matrix" do + it "returns an instance of that subclass" do + MatrixSub.diagonal(1).should be_an_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 - end +describe "Matrix.diagonal?" do + it "returns true for a diagonal Matrix" do + Matrix.diagonal([1, 2, 3]).diagonal?.should be_true + end - it "returns true for a zero square Matrix" do - Matrix.zero(3).diagonal?.should be_true - end + it "returns true for a zero square Matrix" do + Matrix.zero(3).diagonal?.should be_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 - 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 + end - it "returns true for an empty 0x0 matrix" do - Matrix.empty(0,0).diagonal?.should be_true - end + it "returns true for an empty 0x0 matrix" do + Matrix.empty(0,0).diagonal?.should be_true + 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.diagonal? - }.should raise_error(Matrix::ErrDimensionMismatch) - 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.diagonal? + }.should raise_error(Matrix::ErrDimensionMismatch) end end end diff --git a/spec/ruby/library/matrix/divide_spec.rb b/spec/ruby/library/matrix/divide_spec.rb index 68e6f1fde50..2e3bb85bf65 100644 --- a/spec/ruby/library/matrix/divide_spec.rb +++ b/spec/ruby/library/matrix/divide_spec.rb @@ -1,57 +1,54 @@ require_relative '../../spec_helper' +require_relative 'spec_helper' +require_relative 'fixtures/classes' +require 'matrix' + +describe "Matrix#/" do + before :each do + @a = Matrix[ [1, 2], [3, 4] ] + @b = Matrix[ [4, 5], [6, 7] ] + @c = Matrix[ [1.2, 2.4], [3.6, 4.8] ] + end -ruby_version_is ""..."3.1" do - require_relative 'spec_helper' - require_relative 'fixtures/classes' - require 'matrix' + it "returns the result of dividing self by another Matrix" do + (@a / @b).should be_close_to_matrix([[2.5, -1.5], [1.5, -0.5]]) + end - describe "Matrix#/" do - before :each do - @a = Matrix[ [1, 2], [3, 4] ] - @b = Matrix[ [4, 5], [6, 7] ] - @c = Matrix[ [1.2, 2.4], [3.6, 4.8] ] + # 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 - it "returns the result of dividing self by another Matrix" do - (@a / @b).should be_close_to_matrix([[2.5, -1.5], [1.5, -0.5]]) - end - - # 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 - - it "returns the result of dividing self by a Bignum" do - (@a / bignum_value).should == Matrix[ [0, 0], [0, 0] ] - end + it "returns the result of dividing self by a Bignum" do + (@a / bignum_value).should == Matrix[ [0, 0], [0, 0] ] end + end - it "returns the result of dividing self by a Float" do - (@c / 1.2).should == Matrix[ [1, 2], [3, 4] ] - end + it "returns the result of dividing self by a Float" do + (@c / 1.2).should == Matrix[ [1, 2], [3, 4] ] + end - it "raises a Matrix::ErrDimensionMismatch if the matrices are different sizes" do - -> { @a / Matrix[ [1] ] }.should raise_error(Matrix::ErrDimensionMismatch) - end + it "raises a Matrix::ErrDimensionMismatch if the matrices are different sizes" do + -> { @a / Matrix[ [1] ] }.should raise_error(Matrix::ErrDimensionMismatch) + end - it "returns an instance of Matrix" do - (@a / @b).should be_kind_of(Matrix) - end + it "returns an instance of Matrix" do + (@a / @b).should be_kind_of(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) - 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) end + end - it "raises a TypeError if other is of wrong type" do - -> { @a / nil }.should raise_error(TypeError) - -> { @a / "a" }.should raise_error(TypeError) - -> { @a / [ [1, 2] ] }.should raise_error(TypeError) - -> { @a / Object.new }.should raise_error(TypeError) - end + it "raises a TypeError if other is of wrong type" do + -> { @a / nil }.should raise_error(TypeError) + -> { @a / "a" }.should raise_error(TypeError) + -> { @a / [ [1, 2] ] }.should raise_error(TypeError) + -> { @a / Object.new }.should raise_error(TypeError) end end diff --git a/spec/ruby/library/matrix/each_spec.rb b/spec/ruby/library/matrix/each_spec.rb index d2b13c80b60..f3b0f018678 100644 --- a/spec/ruby/library/matrix/each_spec.rb +++ b/spec/ruby/library/matrix/each_spec.rb @@ -1,77 +1,74 @@ require_relative '../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Matrix#each" do - before :all do - @m = Matrix[ [1, 2, 3], [4, 5, 6] ] - @result = (1..6).to_a - end +describe "Matrix#each" do + before :all do + @m = Matrix[ [1, 2, 3], [4, 5, 6] ] + @result = (1..6).to_a + end - it "returns an Enumerator when called without a block" do - enum = @m.each - enum.should be_an_instance_of(Enumerator) - enum.to_a.should == @result - end + it "returns an Enumerator when called without a block" do + enum = @m.each + enum.should be_an_instance_of(Enumerator) + enum.to_a.should == @result + end - it "returns self" do - @m.each{}.should equal(@m) - end + it "returns self" do + @m.each{}.should equal(@m) + end - it "yields the elements starting with the those of the first row" do - a = [] - @m.each {|x| a << x} - a.should == @result - end + it "yields the elements starting with the those of the first row" do + a = [] + @m.each {|x| a << x} + a.should == @result end +end - describe "Matrix#each with an argument" do - before :all do - @m = Matrix[ [1, 2, 3, 4], [5, 6, 7, 8] ] - @t = Matrix[ [1, 2], [3, 4], [5, 6], [7, 8] ] - end +describe "Matrix#each with an argument" do + before :all do + @m = Matrix[ [1, 2, 3, 4], [5, 6, 7, 8] ] + @t = Matrix[ [1, 2], [3, 4], [5, 6], [7, 8] ] + end - it "raises an ArgumentError for unrecognized argument" do - -> { - @m.each("all"){} - }.should raise_error(ArgumentError) - -> { - @m.each(nil){} - }.should raise_error(ArgumentError) - -> { - @m.each(:left){} - }.should raise_error(ArgumentError) - end + it "raises an ArgumentError for unrecognized argument" do + -> { + @m.each("all"){} + }.should raise_error(ArgumentError) + -> { + @m.each(nil){} + }.should raise_error(ArgumentError) + -> { + @m.each(:left){} + }.should raise_error(ArgumentError) + end - it "yields the rights elements when passed :diagonal" do - @m.each(:diagonal).to_a.should == [1, 6] - @t.each(:diagonal).to_a.should == [1, 4] - end + it "yields the rights elements when passed :diagonal" do + @m.each(:diagonal).to_a.should == [1, 6] + @t.each(:diagonal).to_a.should == [1, 4] + end - it "yields the rights elements when passed :off_diagonal" do - @m.each(:off_diagonal).to_a.should == [2, 3, 4, 5, 7, 8] - @t.each(:off_diagonal).to_a.should == [2, 3, 5, 6, 7, 8] - end + it "yields the rights elements when passed :off_diagonal" do + @m.each(:off_diagonal).to_a.should == [2, 3, 4, 5, 7, 8] + @t.each(:off_diagonal).to_a.should == [2, 3, 5, 6, 7, 8] + end - it "yields the rights elements when passed :lower" do - @m.each(:lower).to_a.should == [1, 5, 6] - @t.each(:lower).to_a.should == [1, 3, 4, 5, 6, 7, 8] - end + it "yields the rights elements when passed :lower" do + @m.each(:lower).to_a.should == [1, 5, 6] + @t.each(:lower).to_a.should == [1, 3, 4, 5, 6, 7, 8] + end - it "yields the rights elements when passed :strict_lower" do - @m.each(:strict_lower).to_a.should == [5] - @t.each(:strict_lower).to_a.should == [3, 5, 6, 7, 8] - end + it "yields the rights elements when passed :strict_lower" do + @m.each(:strict_lower).to_a.should == [5] + @t.each(:strict_lower).to_a.should == [3, 5, 6, 7, 8] + end - it "yields the rights elements when passed :strict_upper" do - @m.each(:strict_upper).to_a.should == [2, 3, 4, 7, 8] - @t.each(:strict_upper).to_a.should == [2] - end + it "yields the rights elements when passed :strict_upper" do + @m.each(:strict_upper).to_a.should == [2, 3, 4, 7, 8] + @t.each(:strict_upper).to_a.should == [2] + end - it "yields the rights elements when passed :upper" do - @m.each(:upper).to_a.should == [1, 2, 3, 4, 6, 7, 8] - @t.each(:upper).to_a.should == [1, 2, 4] - end + it "yields the rights elements when passed :upper" do + @m.each(:upper).to_a.should == [1, 2, 3, 4, 6, 7, 8] + @t.each(:upper).to_a.should == [1, 2, 4] end end diff --git a/spec/ruby/library/matrix/each_with_index_spec.rb b/spec/ruby/library/matrix/each_with_index_spec.rb index 59549f77b72..a005b886216 100644 --- a/spec/ruby/library/matrix/each_with_index_spec.rb +++ b/spec/ruby/library/matrix/each_with_index_spec.rb @@ -1,84 +1,81 @@ require_relative '../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Matrix#each_with_index" do - before :all do - @m = Matrix[ [1, 2, 3], [4, 5, 6] ] - @result = [ - [1, 0, 0], - [2, 0, 1], - [3, 0, 2], - [4, 1, 0], - [5, 1, 1], - [6, 1, 2] - ] - end +describe "Matrix#each_with_index" do + before :all do + @m = Matrix[ [1, 2, 3], [4, 5, 6] ] + @result = [ + [1, 0, 0], + [2, 0, 1], + [3, 0, 2], + [4, 1, 0], + [5, 1, 1], + [6, 1, 2] + ] + end - it "returns an Enumerator when called without a block" do - enum = @m.each_with_index - enum.should be_an_instance_of(Enumerator) - enum.to_a.should == @result - end + it "returns an Enumerator when called without a block" do + enum = @m.each_with_index + enum.should be_an_instance_of(Enumerator) + enum.to_a.should == @result + end - it "returns self" do - @m.each_with_index{}.should equal(@m) - end + it "returns self" do + @m.each_with_index{}.should equal(@m) + end - it "yields the elements starting with the those of the first row" do - a = [] - @m.each_with_index {|x, r, c| a << [x, r, c]} - a.should == @result - end + it "yields the elements starting with the those of the first row" do + a = [] + @m.each_with_index {|x, r, c| a << [x, r, c]} + a.should == @result end +end - describe "Matrix#each_with_index with an argument" do - before :all do - @m = Matrix[ [1, 2, 3, 4], [5, 6, 7, 8] ] - @t = Matrix[ [1, 2], [3, 4], [5, 6], [7, 8] ] - end +describe "Matrix#each_with_index with an argument" do + before :all do + @m = Matrix[ [1, 2, 3, 4], [5, 6, 7, 8] ] + @t = Matrix[ [1, 2], [3, 4], [5, 6], [7, 8] ] + end - it "raises an ArgumentError for unrecognized argument" do - -> { - @m.each_with_index("all"){} - }.should raise_error(ArgumentError) - -> { - @m.each_with_index(nil){} - }.should raise_error(ArgumentError) - -> { - @m.each_with_index(:left){} - }.should raise_error(ArgumentError) - end + it "raises an ArgumentError for unrecognized argument" do + -> { + @m.each_with_index("all"){} + }.should raise_error(ArgumentError) + -> { + @m.each_with_index(nil){} + }.should raise_error(ArgumentError) + -> { + @m.each_with_index(:left){} + }.should raise_error(ArgumentError) + end - it "yields the rights elements when passed :diagonal" do - @m.each_with_index(:diagonal).to_a.should == [[1, 0, 0], [6, 1, 1]] - @t.each_with_index(:diagonal).to_a.should == [[1, 0, 0], [4, 1, 1]] - end + it "yields the rights elements when passed :diagonal" do + @m.each_with_index(:diagonal).to_a.should == [[1, 0, 0], [6, 1, 1]] + @t.each_with_index(:diagonal).to_a.should == [[1, 0, 0], [4, 1, 1]] + end - it "yields the rights elements when passed :off_diagonal" do - @m.each_with_index(:off_diagonal).to_a.should == [[2, 0, 1], [3, 0, 2], [4, 0, 3], [5, 1, 0], [7, 1, 2], [8, 1, 3]] - @t.each_with_index(:off_diagonal).to_a.should == [[2, 0, 1], [3, 1, 0], [5, 2, 0], [6, 2, 1], [7, 3, 0], [8, 3, 1]] - end + it "yields the rights elements when passed :off_diagonal" do + @m.each_with_index(:off_diagonal).to_a.should == [[2, 0, 1], [3, 0, 2], [4, 0, 3], [5, 1, 0], [7, 1, 2], [8, 1, 3]] + @t.each_with_index(:off_diagonal).to_a.should == [[2, 0, 1], [3, 1, 0], [5, 2, 0], [6, 2, 1], [7, 3, 0], [8, 3, 1]] + end - it "yields the rights elements when passed :lower" do - @m.each_with_index(:lower).to_a.should == [[1, 0, 0], [5, 1, 0], [6, 1, 1]] - @t.each_with_index(:lower).to_a.should == [[1, 0, 0], [3, 1, 0], [4, 1, 1], [5, 2, 0], [6, 2, 1], [7, 3, 0], [8, 3, 1]] - end + it "yields the rights elements when passed :lower" do + @m.each_with_index(:lower).to_a.should == [[1, 0, 0], [5, 1, 0], [6, 1, 1]] + @t.each_with_index(:lower).to_a.should == [[1, 0, 0], [3, 1, 0], [4, 1, 1], [5, 2, 0], [6, 2, 1], [7, 3, 0], [8, 3, 1]] + end - it "yields the rights elements when passed :strict_lower" do - @m.each_with_index(:strict_lower).to_a.should == [[5, 1, 0]] - @t.each_with_index(:strict_lower).to_a.should == [[3, 1, 0], [5, 2, 0], [6, 2, 1], [7, 3, 0], [8, 3, 1]] - end + it "yields the rights elements when passed :strict_lower" do + @m.each_with_index(:strict_lower).to_a.should == [[5, 1, 0]] + @t.each_with_index(:strict_lower).to_a.should == [[3, 1, 0], [5, 2, 0], [6, 2, 1], [7, 3, 0], [8, 3, 1]] + end - it "yields the rights elements when passed :strict_upper" do - @m.each_with_index(:strict_upper).to_a.should == [[2, 0, 1], [3, 0, 2], [4, 0, 3], [7, 1, 2], [8, 1, 3]] - @t.each_with_index(:strict_upper).to_a.should == [[2, 0, 1]] - end + it "yields the rights elements when passed :strict_upper" do + @m.each_with_index(:strict_upper).to_a.should == [[2, 0, 1], [3, 0, 2], [4, 0, 3], [7, 1, 2], [8, 1, 3]] + @t.each_with_index(:strict_upper).to_a.should == [[2, 0, 1]] + end - it "yields the rights elements when passed :upper" do - @m.each_with_index(:upper).to_a.should == [[1, 0, 0], [2, 0, 1], [3, 0, 2], [4, 0, 3], [6, 1, 1], [7, 1, 2], [8, 1, 3]] - @t.each_with_index(:upper).to_a.should == [[1, 0, 0], [2, 0, 1], [4, 1, 1]] - end + it "yields the rights elements when passed :upper" do + @m.each_with_index(:upper).to_a.should == [[1, 0, 0], [2, 0, 1], [3, 0, 2], [4, 0, 3], [6, 1, 1], [7, 1, 2], [8, 1, 3]] + @t.each_with_index(:upper).to_a.should == [[1, 0, 0], [2, 0, 1], [4, 1, 1]] end end 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 f9ffca01232..67f9dd1c19a 100644 --- a/spec/ruby/library/matrix/eigenvalue_decomposition/eigenvalue_matrix_spec.rb +++ b/spec/ruby/library/matrix/eigenvalue_decomposition/eigenvalue_matrix_spec.rb @@ -1,12 +1,9 @@ require_relative '../../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Matrix::EigenvalueDecomposition#eigenvalue_matrix" do - it "returns a diagonal matrix with the eigenvalues on the diagonal" do - Matrix[[14, 16], [-6, -6]].eigensystem.eigenvalue_matrix.should == Matrix[[6, 0],[0, 2]] - Matrix[[1, 1], [-1, 1]].eigensystem.eigenvalue_matrix.should == Matrix[[Complex(1,1), 0],[0, Complex(1,-1)]] - end +describe "Matrix::EigenvalueDecomposition#eigenvalue_matrix" do + it "returns a diagonal matrix with the eigenvalues on the diagonal" do + Matrix[[14, 16], [-6, -6]].eigensystem.eigenvalue_matrix.should == Matrix[[6, 0],[0, 2]] + Matrix[[1, 1], [-1, 1]].eigensystem.eigenvalue_matrix.should == Matrix[[Complex(1,1), 0],[0, Complex(1,-1)]] end end diff --git a/spec/ruby/library/matrix/eigenvalue_decomposition/eigenvalues_spec.rb b/spec/ruby/library/matrix/eigenvalue_decomposition/eigenvalues_spec.rb index 650d43d90f2..7552b7616c5 100644 --- a/spec/ruby/library/matrix/eigenvalue_decomposition/eigenvalues_spec.rb +++ b/spec/ruby/library/matrix/eigenvalue_decomposition/eigenvalues_spec.rb @@ -1,25 +1,22 @@ require_relative '../../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Matrix::EigenvalueDecomposition#eigenvalues" do - it "returns an array of complex eigenvalues for a rotation matrix" do - Matrix[[ 1, 1], - [-1, 1]].eigensystem.eigenvalues.sort_by{|v| v.imag}.should == - [ Complex(1, -1), Complex(1, 1)] - end +describe "Matrix::EigenvalueDecomposition#eigenvalues" do + it "returns an array of complex eigenvalues for a rotation matrix" do + Matrix[[ 1, 1], + [-1, 1]].eigensystem.eigenvalues.sort_by{|v| v.imag}.should == + [ Complex(1, -1), Complex(1, 1)] + end - 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 ] - end + 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 ] + end - it "returns an array of real eigenvalues for a matrix" do - Matrix[[14, 16], - [-6, -6]].eigensystem.eigenvalues.sort.map!{|x| x.round(10)}.should == - [ 2, 6 ] - end + it "returns an array of real eigenvalues for a matrix" do + Matrix[[14, 16], + [-6, -6]].eigensystem.eigenvalues.sort.map!{|x| x.round(10)}.should == + [ 2, 6 ] end end 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 57299ce69ea..09f229ee15c 100644 --- a/spec/ruby/library/matrix/eigenvalue_decomposition/eigenvector_matrix_spec.rb +++ b/spec/ruby/library/matrix/eigenvalue_decomposition/eigenvector_matrix_spec.rb @@ -1,23 +1,20 @@ require_relative '../../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Matrix::EigenvalueDecomposition#eigenvector_matrix" do - it "returns a complex eigenvector matrix given a rotation matrix" do - # Fix me: should test for linearity, not for equality - Matrix[[ 1, 1], - [-1, 1]].eigensystem.eigenvector_matrix.should == - Matrix[[1, 1], - [Complex(0, 1), Complex(0, -1)]] - end +describe "Matrix::EigenvalueDecomposition#eigenvector_matrix" do + it "returns a complex eigenvector matrix given a rotation matrix" do + # Fix me: should test for linearity, not for equality + Matrix[[ 1, 1], + [-1, 1]].eigensystem.eigenvector_matrix.should == + Matrix[[1, 1], + [Complex(0, 1), Complex(0, -1)]] + end - 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 == - Matrix[[0.7071067811865475, 0.7071067811865475], - [-0.7071067811865475, 0.7071067811865475]] - end + 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 == + Matrix[[0.7071067811865475, 0.7071067811865475], + [-0.7071067811865475, 0.7071067811865475]] end end diff --git a/spec/ruby/library/matrix/eigenvalue_decomposition/eigenvectors_spec.rb b/spec/ruby/library/matrix/eigenvalue_decomposition/eigenvectors_spec.rb index 54e6857bf32..2b6ce74ea83 100644 --- a/spec/ruby/library/matrix/eigenvalue_decomposition/eigenvectors_spec.rb +++ b/spec/ruby/library/matrix/eigenvalue_decomposition/eigenvectors_spec.rb @@ -1,25 +1,22 @@ require_relative '../../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Matrix::EigenvalueDecomposition#eigenvectors" do - it "returns an array of complex eigenvectors for a rotation matrix" do - # Fix me: should test for linearity, not for equality - Matrix[[ 1, 1], - [-1, 1]].eigensystem.eigenvectors.should == - [ Vector[1, Complex(0, 1)], - Vector[1, Complex(0, -1)] - ] - end +describe "Matrix::EigenvalueDecomposition#eigenvectors" do + it "returns an array of complex eigenvectors for a rotation matrix" do + # Fix me: should test for linearity, not for equality + Matrix[[ 1, 1], + [-1, 1]].eigensystem.eigenvectors.should == + [ Vector[1, Complex(0, 1)], + Vector[1, Complex(0, -1)] + ] + end - 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 == - [ Vector[0.7071067811865475, -0.7071067811865475], - Vector[0.7071067811865475, 0.7071067811865475] - ] - end + 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 == + [ Vector[0.7071067811865475, -0.7071067811865475], + Vector[0.7071067811865475, 0.7071067811865475] + ] end end diff --git a/spec/ruby/library/matrix/eigenvalue_decomposition/initialize_spec.rb b/spec/ruby/library/matrix/eigenvalue_decomposition/initialize_spec.rb index 02aad65c4b0..8438f63133e 100644 --- a/spec/ruby/library/matrix/eigenvalue_decomposition/initialize_spec.rb +++ b/spec/ruby/library/matrix/eigenvalue_decomposition/initialize_spec.rb @@ -1,27 +1,24 @@ require_relative '../../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Matrix::EigenvalueDecomposition#initialize" do - it "raises an error if argument is not a matrix" do - -> { - Matrix::EigenvalueDecomposition.new([[]]) - }.should raise_error(TypeError) - -> { - Matrix::EigenvalueDecomposition.new(42) - }.should raise_error(TypeError) - end +describe "Matrix::EigenvalueDecomposition#initialize" do + it "raises an error if argument is not a matrix" do + -> { + Matrix::EigenvalueDecomposition.new([[]]) + }.should raise_error(TypeError) + -> { + Matrix::EigenvalueDecomposition.new(42) + }.should raise_error(TypeError) + end - it "raises an error if matrix is not square" do - -> { - Matrix::EigenvalueDecomposition.new(Matrix[[1, 2]]) - }.should raise_error(Matrix::ErrDimensionMismatch) - end + it "raises an error if matrix is not square" do + -> { + Matrix::EigenvalueDecomposition.new(Matrix[[1, 2]]) + }.should raise_error(Matrix::ErrDimensionMismatch) + end - it "never hangs" do - m = Matrix[ [0,0,0,0,0], [0,0,0,0,1], [0,0,0,1,0], [1,1,0,0,1], [1,0,1,0,1] ] - Matrix::EigenvalueDecomposition.new(m).should_not == "infinite loop" - end + it "never hangs" do + m = Matrix[ [0,0,0,0,0], [0,0,0,0,1], [0,0,0,1,0], [1,1,0,0,1], [1,0,1,0,1] ] + Matrix::EigenvalueDecomposition.new(m).should_not == "infinite loop" end end 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 352ae274b48..8be41a57206 100644 --- a/spec/ruby/library/matrix/eigenvalue_decomposition/to_a_spec.rb +++ b/spec/ruby/library/matrix/eigenvalue_decomposition/to_a_spec.rb @@ -1,21 +1,18 @@ require_relative '../../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Matrix::EigenvalueDecomposition#to_a" do - before :each do - @a = Matrix[[14, 16], [-6, -6]] - @e = Matrix::EigenvalueDecomposition.new(@a) - end +describe "Matrix::EigenvalueDecomposition#to_a" do + before :each do + @a = Matrix[[14, 16], [-6, -6]] + @e = Matrix::EigenvalueDecomposition.new(@a) + end - it "returns an array of with [V, D, V.inv]" do - @e.to_a.should == [@e.v, @e.d, @e.v_inv] - end + it "returns an array of with [V, D, V.inv]" do + @e.to_a.should == [@e.v, @e.d, @e.v_inv] + end - it "returns a factorization" do - v, d, v_inv = @e.to_a - (v * d * v_inv).map{|e| e.round(10)}.should == @a - end + it "returns a factorization" do + v, d, v_inv = @e.to_a + (v * d * v_inv).map{|e| e.round(10)}.should == @a end end diff --git a/spec/ruby/library/matrix/element_reference_spec.rb b/spec/ruby/library/matrix/element_reference_spec.rb index 286ab851bd0..b950d1c391f 100644 --- a/spec/ruby/library/matrix/element_reference_spec.rb +++ b/spec/ruby/library/matrix/element_reference_spec.rb @@ -1,26 +1,23 @@ require_relative '../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' +describe "Matrix#[]" do - describe "Matrix#[]" do - - before :all do - @m = Matrix[[0, 1, 2], [3, 4, 5], [6, 7, 8], [9, 10, 11]] - end + before :all do + @m = Matrix[[0, 1, 2], [3, 4, 5], [6, 7, 8], [9, 10, 11]] + end - it "returns element at (i, j)" do - (0..3).each do |i| - (0..2).each do |j| - @m[i, j].should == (i * 3) + j - end + it "returns element at (i, j)" do + (0..3).each do |i| + (0..2).each do |j| + @m[i, j].should == (i * 3) + j end end + end - it "returns nil for an invalid index pair" do - @m[8,1].should be_nil - @m[1,8].should be_nil - end - + it "returns nil for an invalid index pair" do + @m[8,1].should be_nil + @m[1,8].should be_nil end + end diff --git a/spec/ruby/library/matrix/empty_spec.rb b/spec/ruby/library/matrix/empty_spec.rb index 0b5d5ffe0f0..5f294711db1 100644 --- a/spec/ruby/library/matrix/empty_spec.rb +++ b/spec/ruby/library/matrix/empty_spec.rb @@ -1,71 +1,68 @@ require_relative '../../spec_helper' +require_relative 'fixtures/classes' +require 'matrix' -ruby_version_is ""..."3.1" do - 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 - end - - it "returns false when the Matrix has elements" do - Matrix[ [1, 2] ].empty?.should be_false - Matrix[ [1], [2] ].empty?.should be_false - end +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 + end - it "doesn't accept any parameter" do - ->{ - Matrix[ [1, 2] ].empty?(42) - }.should raise_error(ArgumentError) - end + it "returns false when the Matrix has elements" do + Matrix[ [1, 2] ].empty?.should be_false + Matrix[ [1], [2] ].empty?.should be_false end - describe "Matrix.empty" do - it "returns an empty matrix of the requested size" do - m = Matrix.empty(3, 0) - m.row_size.should == 3 - m.column_size.should == 0 + it "doesn't accept any parameter" do + ->{ + Matrix[ [1, 2] ].empty?(42) + }.should raise_error(ArgumentError) + end +end - m = Matrix.empty(0, 3) - m.row_size.should == 0 - m.column_size.should == 3 - end +describe "Matrix.empty" do + it "returns an empty matrix of the requested size" do + m = Matrix.empty(3, 0) + m.row_size.should == 3 + m.column_size.should == 0 - it "has arguments defaulting to 0" do - Matrix.empty.should == Matrix.empty(0, 0) - Matrix.empty(42).should == Matrix.empty(42, 0) - end + m = Matrix.empty(0, 3) + m.row_size.should == 0 + m.column_size.should == 3 + end - it "does not accept more than two parameters" do - ->{ - Matrix.empty(1, 2, 3) - }.should raise_error(ArgumentError) - end + it "has arguments defaulting to 0" do + Matrix.empty.should == Matrix.empty(0, 0) + Matrix.empty(42).should == Matrix.empty(42, 0) + end - it "raises an error if both dimensions are > 0" do - ->{ - Matrix.empty(1, 2) - }.should raise_error(ArgumentError) - end + it "does not accept more than two parameters" do + ->{ + Matrix.empty(1, 2, 3) + }.should raise_error(ArgumentError) + end - it "raises an error if any dimension is < 0" do - ->{ - Matrix.empty(-2, 0) - }.should raise_error(ArgumentError) + it "raises an error if both dimensions are > 0" do + ->{ + Matrix.empty(1, 2) + }.should raise_error(ArgumentError) + end - ->{ - Matrix.empty(0, -2) - }.should raise_error(ArgumentError) - end + it "raises an error if any dimension is < 0" do + ->{ + Matrix.empty(-2, 0) + }.should raise_error(ArgumentError) + ->{ + Matrix.empty(0, -2) + }.should raise_error(ArgumentError) 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) - 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) end end diff --git a/spec/ruby/library/matrix/eql_spec.rb b/spec/ruby/library/matrix/eql_spec.rb index d3f03dd6f3f..ea26c3320d2 100644 --- a/spec/ruby/library/matrix/eql_spec.rb +++ b/spec/ruby/library/matrix/eql_spec.rb @@ -1,14 +1,11 @@ require_relative '../../spec_helper' +require_relative 'shared/equal_value' +require 'matrix' -ruby_version_is ""..."3.1" do - require_relative 'shared/equal_value' - require 'matrix' +describe "Matrix#eql?" do + it_behaves_like :equal, :eql? - describe "Matrix#eql?" do - 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 - end + 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 end end diff --git a/spec/ruby/library/matrix/equal_value_spec.rb b/spec/ruby/library/matrix/equal_value_spec.rb index 0408a8ef3ea..10cf1e6c291 100644 --- a/spec/ruby/library/matrix/equal_value_spec.rb +++ b/spec/ruby/library/matrix/equal_value_spec.rb @@ -1,14 +1,11 @@ require_relative '../../spec_helper' +require_relative 'shared/equal_value' +require 'matrix' -ruby_version_is ""..."3.1" do - require_relative 'shared/equal_value' - require 'matrix' +describe "Matrix#==" do + it_behaves_like :equal, :== - describe "Matrix#==" do - 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]] - end + it "returns true if some elements are == but not eql?" do + Matrix[[1, 2],[3, 4]].should == Matrix[[1, 2],[3, 4.0]] end end diff --git a/spec/ruby/library/matrix/exponent_spec.rb b/spec/ruby/library/matrix/exponent_spec.rb index 5262627fd54..b76e18b4cdd 100644 --- a/spec/ruby/library/matrix/exponent_spec.rb +++ b/spec/ruby/library/matrix/exponent_spec.rb @@ -1,67 +1,64 @@ require_relative '../../spec_helper' +require_relative 'fixtures/classes' +require 'matrix' -ruby_version_is ""..."3.1" do - require_relative 'fixtures/classes' - require 'matrix' +describe "Matrix#**" do - describe "Matrix#**" do + describe "given an integer _n_" do + it "multiples the Matrix by itself _n_ times" do + m = Matrix[ [7,6], [3,9] ] + (m ** 1).should == m + (m ** 2).should == Matrix[ [67, 96], [48,99] ] + (m ** 2).should == m * m + (m ** 3).should == m * m * m + (m ** 4).should == m * m * m * m + (m ** 5).should == m * m * m * m * m + end - describe "given an integer _n_" do - it "multiples the Matrix by itself _n_ times" do - m = Matrix[ [7,6], [3,9] ] - (m ** 1).should == m - (m ** 2).should == Matrix[ [67, 96], [48,99] ] - (m ** 2).should == m * m - (m ** 3).should == m * m * m - (m ** 4).should == m * m * m * m - (m ** 5).should == m * m * m * m * m - end + it "raises a ErrDimensionMismatch for non square matrices" do + m = Matrix[ [1, 1], [1, 2], [2, 3]] + -> { m ** 3 }.should raise_error(Matrix::ErrDimensionMismatch) + -> { m ** 0 }.should raise_error(Matrix::ErrDimensionMismatch) + end - it "raises a ErrDimensionMismatch for non square matrices" do - m = Matrix[ [1, 1], [1, 2], [2, 3]] - -> { m ** 3 }.should raise_error(Matrix::ErrDimensionMismatch) - -> { m ** 0 }.should raise_error(Matrix::ErrDimensionMismatch) + 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 - 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 ErrNotRegular for irregular matrices" do + m = Matrix[ [1, 1], [1, 1] ] + -> { m ** -2 }.should raise_error(Matrix::ErrNotRegular) + end + end - it "raises a ErrNotRegular for irregular matrices" do + ruby_version_is '3.1.0' do # https://bugs.ruby-lang.org/issues/17521 + describe "that is 0" do + it "returns the identity for square matrices" do m = Matrix[ [1, 1], [1, 1] ] - -> { m ** -2 }.should raise_error(Matrix::ErrNotRegular) + (m ** 0).should == Matrix.identity(2) end - end - - ruby_version_is '3.1.0' do # https://bugs.ruby-lang.org/issues/17521 - 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_error(Matrix::ErrDimensionMismatch) - end + it "raises an ErrDimensionMismatch for non-square matrices" do + m = Matrix[ [1, 1] ] + -> { m ** 0 }.should raise_error(Matrix::ErrDimensionMismatch) end end end + end - it "returns the power for non integer powers" do - a = Matrix[[5, 4], [4, 5]] - ((a ** 0.5) ** 2).round(8).should == a - a = Matrix[[7, 10], [15, 22]] - ((a ** 0.25) ** 4).round(8).should == a - end + it "returns the power for non integer powers" do + a = Matrix[[5, 4], [4, 5]] + ((a ** 0.5) ** 2).round(8).should == a + a = Matrix[[7, 10], [15, 22]] + ((a ** 0.25) ** 4).round(8).should == a + end - describe "for a subclass of Matrix" do - it "returns an instance of that subclass" do - (MatrixSub.ins ** 1).should be_an_instance_of(MatrixSub) - end + describe "for a subclass of Matrix" do + it "returns an instance of that subclass" do + (MatrixSub.ins ** 1).should be_an_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 a0e3679aef4..c2bfa6d61ab 100644 --- a/spec/ruby/library/matrix/find_index_spec.rb +++ b/spec/ruby/library/matrix/find_index_spec.rb @@ -1,149 +1,146 @@ require_relative '../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Matrix#find_index without any argument" do - before :all do - @m = Matrix[ [1, 2, 3, 4], [5, 6, 7, 8] ] - end +describe "Matrix#find_index without any argument" do + before :all do + @m = Matrix[ [1, 2, 3, 4], [5, 6, 7, 8] ] + end - it "returns an Enumerator when called without a block" do - enum = @m.find_index - enum.should be_an_instance_of(Enumerator) - enum.to_a.should == [1, 2, 3, 4, 5, 6, 7, 8] - end + it "returns an Enumerator when called without a block" do + enum = @m.find_index + enum.should be_an_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 - end + it "returns nil if the block is always false" do + @m.find_index{false}.should be_nil + end - it "returns the first index for which the block is true" do - @m.find_index{|x| x >= 3}.should == [0, 2] - end + it "returns the first index for which the block is true" do + @m.find_index{|x| x >= 3}.should == [0, 2] end +end - describe "Matrix#find_index with a subselection argument" do - before :all do - @tests = [ - [ Matrix[ [1, 2, 3, 4], [5, 6, 7, 8] ], { - diagonal: [1, 6] , - off_diagonal: [2, 3, 4, 5, 7, 8], - lower: [1, 5, 6] , - strict_lower: [5] , - strict_upper: [2, 3, 4, 7, 8] , - upper: [1, 2, 3, 4, 6, 7, 8] , - } - ], - [ Matrix[ [1, 2], [3, 4], [5, 6], [7, 8] ], { - diagonal: [1, 4] , - off_diagonal: [2, 3, 5, 6, 7, 8], - lower: [1, 3, 4, 5, 6, 7, 8] , - strict_lower: [3, 5, 6, 7, 8] , - strict_upper: [2] , - upper: [1, 2, 4] , - } - ]] - end +describe "Matrix#find_index with a subselection argument" do + before :all do + @tests = [ + [ Matrix[ [1, 2, 3, 4], [5, 6, 7, 8] ], { + diagonal: [1, 6] , + off_diagonal: [2, 3, 4, 5, 7, 8], + lower: [1, 5, 6] , + strict_lower: [5] , + strict_upper: [2, 3, 4, 7, 8] , + upper: [1, 2, 3, 4, 6, 7, 8] , + } + ], + [ Matrix[ [1, 2], [3, 4], [5, 6], [7, 8] ], { + diagonal: [1, 4] , + off_diagonal: [2, 3, 5, 6, 7, 8], + lower: [1, 3, 4, 5, 6, 7, 8] , + strict_lower: [3, 5, 6, 7, 8] , + strict_upper: [2] , + upper: [1, 2, 4] , + } + ]] + end - describe "and no generic 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) - end + describe "and no generic 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) end end + end - it "yields the rights elements" do - @tests.each do |matrix, h| - h.each do |selector, result| - matrix.find_index(selector).to_a.should == result - end + it "yields the rights elements" do + @tests.each do |matrix, h| + h.each do |selector, result| + matrix.find_index(selector).to_a.should == result end end + end - it "returns the first index for which the block returns true" do - @tests.each do |matrix, h| - h.each do |selector, result| - cnt = result.size.div 2 - which = result[cnt] - idx = matrix.find_index(selector){|x| cnt -= 1; x == which} - matrix[*idx].should == which - cnt.should == -1 - end + it "returns the first index for which the block returns true" do + @tests.each do |matrix, h| + h.each do |selector, result| + cnt = result.size.div 2 + which = result[cnt] + idx = matrix.find_index(selector){|x| cnt -= 1; x == which} + matrix[*idx].should == which + cnt.should == -1 end end + end - it "returns nil if the block is always false" do - @tests.each do |matrix, h| - h.each do |selector, result| - matrix.find_index(selector){ nil }.should == nil - end + it "returns nil if the block is always false" do + @tests.each do |matrix, h| + h.each do |selector, result| + matrix.find_index(selector){ nil }.should == nil end end - end - describe "and a generic argument" do - it "ignores a block" do - @m.find_index(42, :diagonal){raise "oups"}.should == nil - end + end + + describe "and a generic argument" do + it "ignores a block" do + @m.find_index(42, :diagonal){raise "oups"}.should == nil + end - it "returns the index of the requested value" do - @tests.each do |matrix, h| - h.each do |selector, result| - cnt = result.size / 2 - which = result[cnt] - idx = matrix.find_index(which, selector) - matrix[*idx].should == which - end + it "returns the index of the requested value" do + @tests.each do |matrix, h| + h.each do |selector, result| + cnt = result.size / 2 + which = result[cnt] + idx = matrix.find_index(which, selector) + matrix[*idx].should == which end end + end - it "returns nil if the requested value is not found" do - @tests.each do |matrix, h| - h.each do |selector, result| - matrix.find_index(42, selector).should == nil - end + it "returns nil if the requested value is not found" do + @tests.each do |matrix, h| + h.each do |selector, result| + matrix.find_index(42, selector).should == nil end end end - end - describe "Matrix#find_index with only a generic argument" do - before :all do - @m = Matrix[ [1, 2, 3, 4], [1, 2, 3, 4] ] - end +end - it "returns nil if the value is not found" do - @m.find_index(42).should be_nil - end +describe "Matrix#find_index with only a generic argument" do + before :all do + @m = Matrix[ [1, 2, 3, 4], [1, 2, 3, 4] ] + end - it "returns the first index for of the requested value" do - @m.find_index(3).should == [0, 2] - end + it "returns nil if the value is not found" do + @m.find_index(42).should be_nil + end - it "ignores a block" do - @m.find_index(4){raise "oups"}.should == [0, 3] - end + it "returns the first index for of the requested value" do + @m.find_index(3).should == [0, 2] end - describe "Matrix#find_index with two arguments" do - it "raises an ArgumentError for an unrecognized last argument" do - -> { - @m.find_index(1, "all"){} - }.should raise_error(ArgumentError) - -> { - @m.find_index(1, nil){} - }.should raise_error(ArgumentError) - -> { - @m.find_index(1, :left){} - }.should raise_error(ArgumentError) - -> { - @m.find_index(:diagonal, 1){} - }.should raise_error(ArgumentError) - end + it "ignores a block" do + @m.find_index(4){raise "oups"}.should == [0, 3] + end +end + +describe "Matrix#find_index with two arguments" do + it "raises an ArgumentError for an unrecognized last argument" do + -> { + @m.find_index(1, "all"){} + }.should raise_error(ArgumentError) + -> { + @m.find_index(1, nil){} + }.should raise_error(ArgumentError) + -> { + @m.find_index(1, :left){} + }.should raise_error(ArgumentError) + -> { + @m.find_index(:diagonal, 1){} + }.should raise_error(ArgumentError) end end diff --git a/spec/ruby/library/matrix/hash_spec.rb b/spec/ruby/library/matrix/hash_spec.rb index 7c1970511bd..7dabcd3737c 100644 --- a/spec/ruby/library/matrix/hash_spec.rb +++ b/spec/ruby/library/matrix/hash_spec.rb @@ -1,18 +1,15 @@ require_relative '../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' +describe "Matrix#hash" do - describe "Matrix#hash" do - - it "returns an Integer" do - Matrix[ [1,2] ].hash.should be_an_instance_of(Integer) - end - - it "returns the same value for the same matrix" do - data = [ [40,5], [2,7] ] - Matrix[ *data ].hash.should == Matrix[ *data ].hash - end + it "returns an Integer" do + Matrix[ [1,2] ].hash.should be_an_instance_of(Integer) + end + it "returns the same value for the same matrix" do + data = [ [40,5], [2,7] ] + Matrix[ *data ].hash.should == Matrix[ *data ].hash end + end diff --git a/spec/ruby/library/matrix/hermitian_spec.rb b/spec/ruby/library/matrix/hermitian_spec.rb index 4038ee3fa9f..177ca64d839 100644 --- a/spec/ruby/library/matrix/hermitian_spec.rb +++ b/spec/ruby/library/matrix/hermitian_spec.rb @@ -1,37 +1,34 @@ require_relative '../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - 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 - end +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 + end - it "returns true for a 0x0 empty matrix" do - Matrix.empty.hermitian?.should be_true - end + it "returns true for a 0x0 empty matrix" do + Matrix.empty.hermitian?.should be_true + end - it "returns false for an asymmetric Matrix" do - Matrix[[1, 2],[-2, 1]].hermitian?.should be_false - end + it "returns false for an asymmetric Matrix" do + Matrix[[1, 2],[-2, 1]].hermitian?.should be_false + 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.hermitian? - }.should raise_error(Matrix::ErrDimensionMismatch) - 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.hermitian? + }.should raise_error(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 - 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 end end diff --git a/spec/ruby/library/matrix/identity_spec.rb b/spec/ruby/library/matrix/identity_spec.rb index 14f51c402e5..646462bc477 100644 --- a/spec/ruby/library/matrix/identity_spec.rb +++ b/spec/ruby/library/matrix/identity_spec.rb @@ -1,9 +1,6 @@ require_relative '../../spec_helper' +require_relative 'shared/identity' -ruby_version_is ""..."3.1" do - require_relative 'shared/identity' - - describe "Matrix.identity" do - it_behaves_like :matrix_identity, :identity - end +describe "Matrix.identity" do + it_behaves_like :matrix_identity, :identity end diff --git a/spec/ruby/library/matrix/imag_spec.rb b/spec/ruby/library/matrix/imag_spec.rb index a89186ec029..1c988753d87 100644 --- a/spec/ruby/library/matrix/imag_spec.rb +++ b/spec/ruby/library/matrix/imag_spec.rb @@ -1,9 +1,6 @@ require_relative '../../spec_helper' +require_relative 'shared/imaginary' -ruby_version_is ""..."3.1" do - require_relative 'shared/imaginary' - - describe "Matrix#imag" do - it_behaves_like :matrix_imaginary, :imag - end +describe "Matrix#imag" do + it_behaves_like :matrix_imaginary, :imag end diff --git a/spec/ruby/library/matrix/imaginary_spec.rb b/spec/ruby/library/matrix/imaginary_spec.rb index e7f0e49d319..ceae4bbe8d0 100644 --- a/spec/ruby/library/matrix/imaginary_spec.rb +++ b/spec/ruby/library/matrix/imaginary_spec.rb @@ -1,9 +1,6 @@ require_relative '../../spec_helper' +require_relative 'shared/imaginary' -ruby_version_is ""..."3.1" do - require_relative 'shared/imaginary' - - describe "Matrix#imaginary" do - it_behaves_like :matrix_imaginary, :imaginary - end +describe "Matrix#imaginary" do + it_behaves_like :matrix_imaginary, :imaginary end diff --git a/spec/ruby/library/matrix/inspect_spec.rb b/spec/ruby/library/matrix/inspect_spec.rb index d754c0fe7fc..508f478252a 100644 --- a/spec/ruby/library/matrix/inspect_spec.rb +++ b/spec/ruby/library/matrix/inspect_spec.rb @@ -1,30 +1,27 @@ require_relative '../../spec_helper' +require_relative 'fixtures/classes' +require 'matrix' -ruby_version_is ""..."3.1" do - require_relative 'fixtures/classes' - require 'matrix' +describe "Matrix#inspect" do - describe "Matrix#inspect" do - - it "returns a stringified representation of the Matrix" do - Matrix[ [1,2], [2,1] ].inspect.should == "Matrix[[1, 2], [2, 1]]" - end + it "returns a stringified representation of the Matrix" do + Matrix[ [1,2], [2,1] ].inspect.should == "Matrix[[1, 2], [2, 1]]" + end - it "returns 'Matrix.empty(...)' for empty matrices" do - Matrix[ [], [], [] ].inspect.should == "Matrix.empty(3, 0)" - Matrix.columns([ [], [], [] ]).inspect.should == "Matrix.empty(0, 3)" - end + it "returns 'Matrix.empty(...)' for empty matrices" do + Matrix[ [], [], [] ].inspect.should == "Matrix.empty(3, 0)" + Matrix.columns([ [], [], [] ]).inspect.should == "Matrix.empty(0, 3)" + end - it "calls inspect on its contents" do - obj = mock("some_value") - obj.should_receive(:inspect).and_return("some_value") - Matrix[ [1, 2], [3, obj] ].inspect.should == "Matrix[[1, 2], [3, some_value]]" - end + it "calls inspect on its contents" do + obj = mock("some_value") + obj.should_receive(:inspect).and_return("some_value") + Matrix[ [1, 2], [3, obj] ].inspect.should == "Matrix[[1, 2], [3, some_value]]" + end - describe "for a subclass of Matrix" do - it "returns a string using the subclass' name" do - MatrixSub.ins.inspect.should == "MatrixSub[[1, 0], [0, 1]]" - end + describe "for a subclass of Matrix" do + it "returns a string using the subclass' name" do + MatrixSub.ins.inspect.should == "MatrixSub[[1, 0], [0, 1]]" end end end diff --git a/spec/ruby/library/matrix/inv_spec.rb b/spec/ruby/library/matrix/inv_spec.rb index 0ad817a2538..82879a6d82d 100644 --- a/spec/ruby/library/matrix/inv_spec.rb +++ b/spec/ruby/library/matrix/inv_spec.rb @@ -1,10 +1,7 @@ require_relative '../../spec_helper' +require_relative 'spec_helper' +require_relative 'shared/inverse' -ruby_version_is ""..."3.1" do - require_relative 'spec_helper' - require_relative 'shared/inverse' - - describe "Matrix#inv" do - it_behaves_like :inverse, :inv - end +describe "Matrix#inv" do + it_behaves_like :inverse, :inv end diff --git a/spec/ruby/library/matrix/inverse_from_spec.rb b/spec/ruby/library/matrix/inverse_from_spec.rb index bca40542f63..651d56a2440 100644 --- a/spec/ruby/library/matrix/inverse_from_spec.rb +++ b/spec/ruby/library/matrix/inverse_from_spec.rb @@ -1,9 +1,6 @@ require_relative '../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Matrix#inverse_from" do - it "needs to be reviewed for spec completeness" - end +describe "Matrix#inverse_from" do + it "needs to be reviewed for spec completeness" end diff --git a/spec/ruby/library/matrix/inverse_spec.rb b/spec/ruby/library/matrix/inverse_spec.rb index dd9099bec57..fa3fa7de8a7 100644 --- a/spec/ruby/library/matrix/inverse_spec.rb +++ b/spec/ruby/library/matrix/inverse_spec.rb @@ -1,10 +1,7 @@ require_relative '../../spec_helper' +require_relative 'spec_helper' +require_relative 'shared/inverse' -ruby_version_is ""..."3.1" do - require_relative 'spec_helper' - require_relative 'shared/inverse' - - describe "Matrix#inverse" do - it_behaves_like :inverse, :inverse - end +describe "Matrix#inverse" do + it_behaves_like :inverse, :inverse end diff --git a/spec/ruby/library/matrix/lower_triangular_spec.rb b/spec/ruby/library/matrix/lower_triangular_spec.rb index 0223b8b6199..f3aa4501f4f 100644 --- a/spec/ruby/library/matrix/lower_triangular_spec.rb +++ b/spec/ruby/library/matrix/lower_triangular_spec.rb @@ -1,27 +1,24 @@ require_relative '../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - 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 - end +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 + 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 - 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 + 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 - 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 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 1ac4bc971e2..9d733066c17 100644 --- a/spec/ruby/library/matrix/lup_decomposition/determinant_spec.rb +++ b/spec/ruby/library/matrix/lup_decomposition/determinant_spec.rb @@ -1,24 +1,21 @@ require_relative '../../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Matrix::LUPDecomposition#determinant" do - it "returns the determinant when the matrix is square" do - a = Matrix[[7, 8, 9], [14, 46, 51], [28, 82, 163]] - a.lup.determinant.should == 15120 # == a.determinant - end +describe "Matrix::LUPDecomposition#determinant" do + it "returns the determinant when the matrix is square" do + a = Matrix[[7, 8, 9], [14, 46, 51], [28, 82, 163]] + a.lup.determinant.should == 15120 # == a.determinant + end - it "raises an error for rectangular matrices" do - [ - Matrix[[7, 8, 9], [14, 46, 51]], - Matrix[[7, 8], [14, 46], [28, 82]], - ].each do |m| - lup = m.lup - -> { - lup.determinant - }.should raise_error(Matrix::ErrDimensionMismatch) - end + it "raises an error for rectangular matrices" do + [ + Matrix[[7, 8, 9], [14, 46, 51]], + Matrix[[7, 8], [14, 46], [28, 82]], + ].each do |m| + lup = m.lup + -> { + lup.determinant + }.should raise_error(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 42f78c75400..36afb349e60 100644 --- a/spec/ruby/library/matrix/lup_decomposition/initialize_spec.rb +++ b/spec/ruby/library/matrix/lup_decomposition/initialize_spec.rb @@ -1,16 +1,13 @@ require_relative '../../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Matrix::LUPDecomposition#initialize" do - it "raises an error if argument is not a matrix" do - -> { - Matrix::LUPDecomposition.new([[]]) - }.should raise_error(TypeError) - -> { - Matrix::LUPDecomposition.new(42) - }.should raise_error(TypeError) - end +describe "Matrix::LUPDecomposition#initialize" do + it "raises an error if argument is not a matrix" do + -> { + Matrix::LUPDecomposition.new([[]]) + }.should raise_error(TypeError) + -> { + Matrix::LUPDecomposition.new(42) + }.should raise_error(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 6c751f12b71..9514ab5d063 100644 --- a/spec/ruby/library/matrix/lup_decomposition/l_spec.rb +++ b/spec/ruby/library/matrix/lup_decomposition/l_spec.rb @@ -1,21 +1,18 @@ require_relative '../../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Matrix::LUPDecomposition#l" do - before :each do - @a = Matrix[[7, 8, 9], [14, 46, 51], [28, 82, 163]] - @lu = Matrix::LUPDecomposition.new(@a) - @l = @lu.l - end +describe "Matrix::LUPDecomposition#l" do + before :each do + @a = Matrix[[7, 8, 9], [14, 46, 51], [28, 82, 163]] + @lu = Matrix::LUPDecomposition.new(@a) + @l = @lu.l + end - it "returns the first element of to_a" do - @l.should == @lu.to_a[0] - end + it "returns the first element of to_a" do + @l.should == @lu.to_a[0] + end - it "returns a lower triangular matrix" do - @l.lower_triangular?.should be_true - end + it "returns a lower triangular matrix" do + @l.lower_triangular?.should be_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 481f8a17d55..c7b5e9196e9 100644 --- a/spec/ruby/library/matrix/lup_decomposition/p_spec.rb +++ b/spec/ruby/library/matrix/lup_decomposition/p_spec.rb @@ -1,21 +1,18 @@ require_relative '../../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Matrix::LUPDecomposition#p" do - before :each do - @a = Matrix[[7, 8, 9], [14, 46, 51], [28, 82, 163]] - @lu = Matrix::LUPDecomposition.new(@a) - @p = @lu.p - end +describe "Matrix::LUPDecomposition#p" do + before :each do + @a = Matrix[[7, 8, 9], [14, 46, 51], [28, 82, 163]] + @lu = Matrix::LUPDecomposition.new(@a) + @p = @lu.p + end - it "returns the third element of to_a" do - @p.should == @lu.to_a[2] - end + it "returns the third element of to_a" do + @p.should == @lu.to_a[2] + end - it "returns a permutation matrix" do - @p.permutation?.should be_true - end + it "returns a permutation matrix" do + @p.permutation?.should be_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 773fcb3e652..66242627e96 100644 --- a/spec/ruby/library/matrix/lup_decomposition/solve_spec.rb +++ b/spec/ruby/library/matrix/lup_decomposition/solve_spec.rb @@ -1,55 +1,52 @@ require_relative '../../../spec_helper' +require 'matrix' + +describe "Matrix::LUPDecomposition#solve" do + describe "for rectangular matrices" 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) + -> { + lu.solve(a) + }.should raise_error(Matrix::ErrNotRegular) + end -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Matrix::LUPDecomposition#solve" do - describe "for rectangular matrices" 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) - -> { - lu.solve(a) - }.should raise_error(Matrix::ErrNotRegular) + describe "for non singular matrices" do + before :each do + @a = Matrix[[7, 8, 9], [14, 46, 51], [28, 82, 163]] + @lu = Matrix::LUPDecomposition.new(@a) end - describe "for non singular matrices" do - before :each do - @a = Matrix[[7, 8, 9], [14, 46, 51], [28, 82, 163]] - @lu = Matrix::LUPDecomposition.new(@a) - end - - it "returns the appropriate empty matrix when given an empty matrix" do - @lu.solve(Matrix.empty(3,0)).should == Matrix.empty(3,0) - empty = Matrix::LUPDecomposition.new(Matrix.empty(0, 0)) - empty.solve(Matrix.empty(0,3)).should == Matrix.empty(0,3) - end + it "returns the appropriate empty matrix when given an empty matrix" do + @lu.solve(Matrix.empty(3,0)).should == Matrix.empty(3,0) + empty = Matrix::LUPDecomposition.new(Matrix.empty(0, 0)) + empty.solve(Matrix.empty(0,3)).should == Matrix.empty(0,3) + end - it "returns the right matrix when given a matrix of the appropriate size" do - solution = Matrix[[1, 2, 3, 4], [0, 1, 2, 3], [-1, -2, -3, -4]] - values = Matrix[[-2, 4, 10, 16], [-37, -28, -19, -10], [-135, -188, -241, -294]] # == @a * solution - @lu.solve(values).should == solution - end + it "returns the right matrix when given a matrix of the appropriate size" do + solution = Matrix[[1, 2, 3, 4], [0, 1, 2, 3], [-1, -2, -3, -4]] + values = Matrix[[-2, 4, 10, 16], [-37, -28, -19, -10], [-135, -188, -241, -294]] # == @a * solution + @lu.solve(values).should == solution + end - it "raises an error when given a matrix of the wrong size" do - values = Matrix[[1, 2, 3, 4], [0, 1, 2, 3]] - -> { - @lu.solve(values) - }.should raise_error(Matrix::ErrDimensionMismatch) - end + it "raises an error when given a matrix of the wrong size" do + values = Matrix[[1, 2, 3, 4], [0, 1, 2, 3]] + -> { + @lu.solve(values) + }.should raise_error(Matrix::ErrDimensionMismatch) + end - it "returns the right vector when given a vector of the appropriate size" do - solution = Vector[1, 2, -1] - values = Vector[14, 55, 29] # == @a * solution - @lu.solve(values).should == solution - end + it "returns the right vector when given a vector of the appropriate size" do + solution = Vector[1, 2, -1] + values = Vector[14, 55, 29] # == @a * solution + @lu.solve(values).should == solution + end - it "raises an error when given a vector of the wrong size" do - values = Vector[14, 55] - -> { - @lu.solve(values) - }.should raise_error(Matrix::ErrDimensionMismatch) - end + it "raises an error when given a vector of the wrong size" do + values = Vector[14, 55] + -> { + @lu.solve(values) + }.should raise_error(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 87022928659..9b1dccbbace 100644 --- a/spec/ruby/library/matrix/lup_decomposition/to_a_spec.rb +++ b/spec/ruby/library/matrix/lup_decomposition/to_a_spec.rb @@ -1,36 +1,33 @@ require_relative '../../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Matrix::LUPDecomposition#to_a" do - before :each do - @a = Matrix[[7, 8, 9], [14, 46, 51], [28, 82, 163]] - @lu = Matrix::LUPDecomposition.new(@a) - @to_a = @lu.to_a - @l, @u, @p = @to_a - end +describe "Matrix::LUPDecomposition#to_a" do + before :each do + @a = Matrix[[7, 8, 9], [14, 46, 51], [28, 82, 163]] + @lu = Matrix::LUPDecomposition.new(@a) + @to_a = @lu.to_a + @l, @u, @p = @to_a + end - it "returns an array of three matrices" do - @to_a.should be_kind_of(Array) - @to_a.length.should == 3 - @to_a.each{|m| m.should be_kind_of(Matrix)} - end + it "returns an array of three matrices" do + @to_a.should be_kind_of(Array) + @to_a.length.should == 3 + @to_a.each{|m| m.should be_kind_of(Matrix)} + end - it "returns [l, u, p] such that l*u == a*p" do - (@l * @u).should == (@p * @a) - end + it "returns [l, u, p] such that l*u == a*p" do + (@l * @u).should == (@p * @a) + end - it "returns the right values for rectangular matrices" do - [ - Matrix[[7, 8, 9], [14, 46, 51]], - Matrix[[4, 11], [5, 8], [3, 4]], - ].each do |a| - l, u, p = Matrix::LUPDecomposition.new(a).to_a - (l * u).should == (p * a) - end + it "returns the right values for rectangular matrices" do + [ + Matrix[[7, 8, 9], [14, 46, 51]], + Matrix[[4, 11], [5, 8], [3, 4]], + ].each do |a| + l, u, p = Matrix::LUPDecomposition.new(a).to_a + (l * u).should == (p * a) end - - it "has other properties implied by the specs of #l, #u and #p" end + + it "has other properties implied by the specs of #l, #u and #p" end diff --git a/spec/ruby/library/matrix/lup_decomposition/u_spec.rb b/spec/ruby/library/matrix/lup_decomposition/u_spec.rb index cd884b88ec2..ca3dfc1f00e 100644 --- a/spec/ruby/library/matrix/lup_decomposition/u_spec.rb +++ b/spec/ruby/library/matrix/lup_decomposition/u_spec.rb @@ -1,21 +1,18 @@ require_relative '../../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Matrix::LUPDecomposition#u" do - before :each do - @a = Matrix[[7, 8, 9], [14, 46, 51], [28, 82, 163]] - @lu = Matrix::LUPDecomposition.new(@a) - @u = @lu.u - end +describe "Matrix::LUPDecomposition#u" do + before :each do + @a = Matrix[[7, 8, 9], [14, 46, 51], [28, 82, 163]] + @lu = Matrix::LUPDecomposition.new(@a) + @u = @lu.u + end - it "returns the second element of to_a" do - @u.should == @lu.to_a[1] - end + it "returns the second element of to_a" do + @u.should == @lu.to_a[1] + end - it "returns an upper triangular matrix" do - @u.upper_triangular?.should be_true - end + it "returns an upper triangular matrix" do + @u.upper_triangular?.should be_true end end diff --git a/spec/ruby/library/matrix/map_spec.rb b/spec/ruby/library/matrix/map_spec.rb index cde0df54411..bc07c48cda9 100644 --- a/spec/ruby/library/matrix/map_spec.rb +++ b/spec/ruby/library/matrix/map_spec.rb @@ -1,9 +1,6 @@ require_relative '../../spec_helper' +require_relative 'shared/collect' -ruby_version_is ""..."3.1" do - require_relative 'shared/collect' - - describe "Matrix#map" do - it_behaves_like :collect, :map - end +describe "Matrix#map" do + it_behaves_like :collect, :map end diff --git a/spec/ruby/library/matrix/minor_spec.rb b/spec/ruby/library/matrix/minor_spec.rb index 0a6b0823c89..009826c3d66 100644 --- a/spec/ruby/library/matrix/minor_spec.rb +++ b/spec/ruby/library/matrix/minor_spec.rb @@ -1,88 +1,85 @@ require_relative '../../spec_helper' +require_relative 'fixtures/classes' +require 'matrix' -ruby_version_is ""..."3.1" do - require_relative 'fixtures/classes' - require 'matrix' +describe "Matrix#minor" do + before :each do + @matrix = Matrix[ [1,2], [3,4], [5,6] ] + end - describe "Matrix#minor" do - before :each do - @matrix = Matrix[ [1,2], [3,4], [5,6] ] + describe "with start_row, nrows, start_col, ncols" do + it "returns the given portion of the Matrix" do + @matrix.minor(0,1,0,2).should == Matrix[ [1, 2] ] + @matrix.minor(1,2,1,1).should == Matrix[ [4], [6] ] end - describe "with start_row, nrows, start_col, ncols" do - it "returns the given portion of the Matrix" do - @matrix.minor(0,1,0,2).should == Matrix[ [1, 2] ] - @matrix.minor(1,2,1,1).should == Matrix[ [4], [6] ] - end - - it "returns an empty Matrix if nrows or ncols is 0" do - @matrix.minor(0,0,0,0).should == Matrix[] - @matrix.minor(1,0,1,0).should == Matrix[] - @matrix.minor(1,0,1,1).should == Matrix.columns([[]]) - @matrix.minor(1,1,1,0).should == Matrix[[]] - end + it "returns an empty Matrix if nrows or ncols is 0" do + @matrix.minor(0,0,0,0).should == Matrix[] + @matrix.minor(1,0,1,0).should == Matrix[] + @matrix.minor(1,0,1,1).should == Matrix.columns([[]]) + @matrix.minor(1,1,1,0).should == Matrix[[]] + end - it "returns nil for out-of-bounds start_row/col" do - r = @matrix.row_size + 1 - c = @matrix.column_size + 1 - @matrix.minor(r,0,0,10).should == nil - @matrix.minor(0,10,c,9).should == nil - @matrix.minor(-r,0,0,10).should == nil - @matrix.minor(0,10,-c,9).should == nil - end + it "returns nil for out-of-bounds start_row/col" do + r = @matrix.row_size + 1 + c = @matrix.column_size + 1 + @matrix.minor(r,0,0,10).should == nil + @matrix.minor(0,10,c,9).should == nil + @matrix.minor(-r,0,0,10).should == nil + @matrix.minor(0,10,-c,9).should == nil + end - it "returns nil for negative nrows or ncols" do - @matrix.minor(0,1,0,-1).should == nil - @matrix.minor(0,-1,0,1).should == nil - end + it "returns nil for negative nrows or ncols" do + @matrix.minor(0,1,0,-1).should == nil + @matrix.minor(0,-1,0,1).should == nil + end - it "start counting backwards for start_row or start_col below zero" do - @matrix.minor(0, 1, -1, 1).should == @matrix.minor(0, 1, 1, 1) - @matrix.minor(-1, 1, 0, 1).should == @matrix.minor(2, 1, 0, 1) - end + it "start counting backwards for start_row or start_col below zero" do + @matrix.minor(0, 1, -1, 1).should == @matrix.minor(0, 1, 1, 1) + @matrix.minor(-1, 1, 0, 1).should == @matrix.minor(2, 1, 0, 1) + end - it "returns empty matrices for extreme start_row/col" do - @matrix.minor(3,10,1,10).should == Matrix.columns([[]]) - @matrix.minor(1,10,2,10).should == Matrix[[], []] - @matrix.minor(3,0,0,10).should == Matrix.columns([[], []]) - end + it "returns empty matrices for extreme start_row/col" do + @matrix.minor(3,10,1,10).should == Matrix.columns([[]]) + @matrix.minor(1,10,2,10).should == Matrix[[], []] + @matrix.minor(3,0,0,10).should == Matrix.columns([[], []]) + end - it "ignores big nrows or ncols" do - @matrix.minor(0,1,0,20).should == Matrix[ [1, 2] ] - @matrix.minor(1,20,1,1).should == Matrix[ [4], [6] ] - end + it "ignores big nrows or ncols" do + @matrix.minor(0,1,0,20).should == Matrix[ [1, 2] ] + @matrix.minor(1,20,1,1).should == Matrix[ [4], [6] ] end + end - describe "with col_range, row_range" do - it "returns the given portion of the Matrix" do - @matrix.minor(0..0, 0..1).should == Matrix[ [1, 2] ] - @matrix.minor(1..2, 1..2).should == Matrix[ [4], [6] ] - @matrix.minor(1...3, 1...3).should == Matrix[ [4], [6] ] - end + describe "with col_range, row_range" do + it "returns the given portion of the Matrix" do + @matrix.minor(0..0, 0..1).should == Matrix[ [1, 2] ] + @matrix.minor(1..2, 1..2).should == Matrix[ [4], [6] ] + @matrix.minor(1...3, 1...3).should == Matrix[ [4], [6] ] + end - it "returns nil if col_range or row_range is out of range" do - r = @matrix.row_size + 1 - c = @matrix.column_size + 1 - @matrix.minor(r..6, c..6).should == nil - @matrix.minor(0..1, c..6).should == nil - @matrix.minor(r..6, 0..1).should == nil - @matrix.minor(-r..6, -c..6).should == nil - @matrix.minor(0..1, -c..6).should == nil - @matrix.minor(-r..6, 0..1).should == nil - end + it "returns nil if col_range or row_range is out of range" do + r = @matrix.row_size + 1 + c = @matrix.column_size + 1 + @matrix.minor(r..6, c..6).should == nil + @matrix.minor(0..1, c..6).should == nil + @matrix.minor(r..6, 0..1).should == nil + @matrix.minor(-r..6, -c..6).should == nil + @matrix.minor(0..1, -c..6).should == nil + @matrix.minor(-r..6, 0..1).should == nil + end - it "start counting backwards for col_range or row_range below zero" do - @matrix.minor(0..1, -2..-1).should == @matrix.minor(0..1, 0..1) - @matrix.minor(0..1, -2..1).should == @matrix.minor(0..1, 0..1) - @matrix.minor(-2..-1, 0..1).should == @matrix.minor(1..2, 0..1) - @matrix.minor(-2..2, 0..1).should == @matrix.minor(1..2, 0..1) - end + it "start counting backwards for col_range or row_range below zero" do + @matrix.minor(0..1, -2..-1).should == @matrix.minor(0..1, 0..1) + @matrix.minor(0..1, -2..1).should == @matrix.minor(0..1, 0..1) + @matrix.minor(-2..-1, 0..1).should == @matrix.minor(1..2, 0..1) + @matrix.minor(-2..2, 0..1).should == @matrix.minor(1..2, 0..1) end + end - 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) - end + 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) end end end diff --git a/spec/ruby/library/matrix/minus_spec.rb b/spec/ruby/library/matrix/minus_spec.rb index 27dfbeaea55..95cf4a60722 100644 --- a/spec/ruby/library/matrix/minus_spec.rb +++ b/spec/ruby/library/matrix/minus_spec.rb @@ -1,45 +1,42 @@ require_relative '../../spec_helper' +require_relative 'fixtures/classes' +require 'matrix' -ruby_version_is ""..."3.1" do - require_relative 'fixtures/classes' - require 'matrix' - - describe "Matrix#-" do - before :each do - @a = Matrix[ [1, 2], [3, 4] ] - @b = Matrix[ [4, 5], [6, 7] ] - end +describe "Matrix#-" do + before :each do + @a = Matrix[ [1, 2], [3, 4] ] + @b = Matrix[ [4, 5], [6, 7] ] + end - it "returns the result of subtracting the corresponding elements of other from self" do - (@a - @b).should == Matrix[ [-3,-3], [-3,-3] ] - end + it "returns the result of subtracting the corresponding elements of other from self" do + (@a - @b).should == Matrix[ [-3,-3], [-3,-3] ] + end - it "returns an instance of Matrix" do - (@a - @b).should be_kind_of(Matrix) - end + it "returns an instance of Matrix" do + (@a - @b).should be_kind_of(Matrix) + end - it "raises a Matrix::ErrDimensionMismatch if the matrices are different sizes" do - -> { @a - Matrix[ [1] ] }.should raise_error(Matrix::ErrDimensionMismatch) - end + it "raises a Matrix::ErrDimensionMismatch if the matrices are different sizes" do + -> { @a - Matrix[ [1] ] }.should raise_error(Matrix::ErrDimensionMismatch) + end - it "raises a ExceptionForMatrix::ErrOperationNotDefined if other is a Numeric Type" do - -> { @a - 2 }.should raise_error(Matrix::ErrOperationNotDefined) - -> { @a - 1.2 }.should raise_error(Matrix::ErrOperationNotDefined) - -> { @a - bignum_value }.should raise_error(Matrix::ErrOperationNotDefined) - end + it "raises a ExceptionForMatrix::ErrOperationNotDefined if other is a Numeric Type" do + -> { @a - 2 }.should raise_error(Matrix::ErrOperationNotDefined) + -> { @a - 1.2 }.should raise_error(Matrix::ErrOperationNotDefined) + -> { @a - bignum_value }.should raise_error(Matrix::ErrOperationNotDefined) + end - it "raises a TypeError if other is of wrong type" do - -> { @a - nil }.should raise_error(TypeError) - -> { @a - "a" }.should raise_error(TypeError) - -> { @a - [ [1, 2] ] }.should raise_error(TypeError) - -> { @a - Object.new }.should raise_error(TypeError) - end + it "raises a TypeError if other is of wrong type" do + -> { @a - nil }.should raise_error(TypeError) + -> { @a - "a" }.should raise_error(TypeError) + -> { @a - [ [1, 2] ] }.should raise_error(TypeError) + -> { @a - Object.new }.should raise_error(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) - 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) end end end diff --git a/spec/ruby/library/matrix/multiply_spec.rb b/spec/ruby/library/matrix/multiply_spec.rb index a63fcf4020f..206868af929 100644 --- a/spec/ruby/library/matrix/multiply_spec.rb +++ b/spec/ruby/library/matrix/multiply_spec.rb @@ -1,71 +1,69 @@ require_relative '../../spec_helper' -ruby_version_is ""..."3.1" do - require_relative 'fixtures/classes' - require 'matrix' +require_relative 'fixtures/classes' +require 'matrix' - describe "Matrix#*" do - before :each do - @a = Matrix[ [1, 2], [3, 4] ] - @b = Matrix[ [4, 5], [6, 7] ] - end +describe "Matrix#*" do + before :each do + @a = Matrix[ [1, 2], [3, 4] ] + @b = Matrix[ [4, 5], [6, 7] ] + end - it "returns the result of multiplying the corresponding elements of self and a Matrix" do - (@a * @b).should == Matrix[ [16,19], [36,43] ] - end + it "returns the result of multiplying the corresponding elements of self and a Matrix" do + (@a * @b).should == Matrix[ [16,19], [36,43] ] + end - it "returns the result of multiplying the corresponding elements of self and a Vector" do - (@a * Vector[1,2]).should == Vector[5, 11] - end + it "returns the result of multiplying the corresponding elements of self and a Vector" do + (@a * Vector[1,2]).should == Vector[5, 11] + end - it "returns the result of multiplying the elements of self and a Fixnum" do - (@a * 2).should == Matrix[ [2, 4], [6, 8] ] - end + it "returns the result of multiplying the elements of self and a Fixnum" do + (@a * 2).should == Matrix[ [2, 4], [6, 8] ] + end - it "returns the result of multiplying the elements of self and a Bignum" do - (@a * bignum_value).should == Matrix[ - [18446744073709551616, 36893488147419103232], - [55340232221128654848, 73786976294838206464] - ] - end + it "returns the result of multiplying the elements of self and a Bignum" do + (@a * bignum_value).should == Matrix[ + [18446744073709551616, 36893488147419103232], + [55340232221128654848, 73786976294838206464] + ] + end - it "returns the result of multiplying the elements of self and a Float" do - (@a * 2.0).should == Matrix[ [2.0, 4.0], [6.0, 8.0] ] - end + it "returns the result of multiplying the elements of self and a Float" do + (@a * 2.0).should == Matrix[ [2.0, 4.0], [6.0, 8.0] ] + end - it "raises a Matrix::ErrDimensionMismatch if the matrices are different sizes" do - -> { @a * Matrix[ [1] ] }.should raise_error(Matrix::ErrDimensionMismatch) - end + it "raises a Matrix::ErrDimensionMismatch if the matrices are different sizes" do + -> { @a * Matrix[ [1] ] }.should raise_error(Matrix::ErrDimensionMismatch) + end - it "returns a zero matrix if (nx0) * (0xn)" do - (Matrix[[],[],[]] * Matrix.columns([[],[],[]])).should == Matrix.zero(3) - end + it "returns a zero matrix if (nx0) * (0xn)" do + (Matrix[[],[],[]] * Matrix.columns([[],[],[]])).should == Matrix.zero(3) + end - it "returns an empty matrix if (0xn) * (nx0)" do - (Matrix.columns([[],[],[]]) * Matrix[[],[],[]]).should == Matrix[] - end + it "returns an empty matrix if (0xn) * (nx0)" do + (Matrix.columns([[],[],[]]) * Matrix[[],[],[]]).should == Matrix[] + end - it "returns a mx0 matrix if (mxn) * (nx0)" do - (Matrix[[1,2],[3,4],[5,6]] * Matrix[[],[]]).should == Matrix[[],[],[]] - end + it "returns a mx0 matrix if (mxn) * (nx0)" do + (Matrix[[1,2],[3,4],[5,6]] * Matrix[[],[]]).should == Matrix[[],[],[]] + end - it "returns a 0xm matrix if (0xm) * (mxn)" do - (Matrix.columns([[], [], []]) * Matrix[[1,2],[3,4],[5,6]]).should == Matrix.columns([[],[]]) - end + it "returns a 0xm matrix if (0xm) * (mxn)" do + (Matrix.columns([[], [], []]) * Matrix[[1,2],[3,4],[5,6]]).should == Matrix.columns([[],[]]) + end - it "raises a TypeError if other is of wrong type" do - -> { @a * nil }.should raise_error(TypeError) - -> { @a * "a" }.should raise_error(TypeError) - -> { @a * [ [1, 2] ] }.should raise_error(TypeError) - -> { @a * Object.new }.should raise_error(TypeError) - end + it "raises a TypeError if other is of wrong type" do + -> { @a * nil }.should raise_error(TypeError) + -> { @a * "a" }.should raise_error(TypeError) + -> { @a * [ [1, 2] ] }.should raise_error(TypeError) + -> { @a * Object.new }.should raise_error(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) - 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) end end end diff --git a/spec/ruby/library/matrix/new_spec.rb b/spec/ruby/library/matrix/new_spec.rb index 4be2e17116e..30050668460 100644 --- a/spec/ruby/library/matrix/new_spec.rb +++ b/spec/ruby/library/matrix/new_spec.rb @@ -1,11 +1,8 @@ require_relative '../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Matrix.new" do - it "is private" do - Matrix.should have_private_method(:new) - end +describe "Matrix.new" do + it "is private" do + Matrix.should have_private_method(:new) end end diff --git a/spec/ruby/library/matrix/normal_spec.rb b/spec/ruby/library/matrix/normal_spec.rb index 2f2e138c1be..a9e6c645faf 100644 --- a/spec/ruby/library/matrix/normal_spec.rb +++ b/spec/ruby/library/matrix/normal_spec.rb @@ -1,29 +1,26 @@ require_relative '../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' +describe "Matrix.normal?" do + # it "returns false for non normal matrices" do + # Matrix[[0, 1], [1, 2]].should_not.normal? + # end - describe "Matrix.normal?" do - # it "returns false for non normal matrices" do - # 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]].should.normal? - Matrix[[0, Complex(0, 2)], [Complex(0, -2), 0]].should.normal? - end + it "returns true for normal matrices" do + 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 - [ - Matrix[[0], [0]], - Matrix[[0, 0]], - Matrix.empty(0, 2), - Matrix.empty(2, 0), - ].each do |rectangular_matrix| - -> { - rectangular_matrix.normal? - }.should raise_error(Matrix::ErrDimensionMismatch) - 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.normal? + }.should raise_error(Matrix::ErrDimensionMismatch) end end end diff --git a/spec/ruby/library/matrix/orthogonal_spec.rb b/spec/ruby/library/matrix/orthogonal_spec.rb index eb06305040e..26afe89ff08 100644 --- a/spec/ruby/library/matrix/orthogonal_spec.rb +++ b/spec/ruby/library/matrix/orthogonal_spec.rb @@ -1,29 +1,26 @@ require_relative '../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Matrix.orthogonal?" do - it "returns false for non orthogonal matrices" do - Matrix[[0, 1], [1, 2]].should_not.orthogonal? - Matrix[[1, 1, 0], [0, 1, 1], [1, 0, 1]].should_not.orthogonal? - end +describe "Matrix.orthogonal?" do + it "returns false for non orthogonal matrices" do + 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]].should.orthogonal? - end + it "returns true for orthogonal matrices" do + Matrix[[0, 1], [1, 0]].should.orthogonal? + 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.orthogonal? - }.should raise_error(Matrix::ErrDimensionMismatch) - 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.orthogonal? + }.should raise_error(Matrix::ErrDimensionMismatch) end end end diff --git a/spec/ruby/library/matrix/permutation_spec.rb b/spec/ruby/library/matrix/permutation_spec.rb index ed8edad7555..825a9d982c5 100644 --- a/spec/ruby/library/matrix/permutation_spec.rb +++ b/spec/ruby/library/matrix/permutation_spec.rb @@ -1,35 +1,32 @@ require_relative '../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - 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 - end +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 + 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 - 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 + end - it "returns true for an empty 0x0 matrix" do - Matrix.empty(0,0).permutation?.should be_true - end + it "returns true for an empty 0x0 matrix" do + Matrix.empty(0,0).permutation?.should be_true + 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.permutation? - }.should raise_error(Matrix::ErrDimensionMismatch) - 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.permutation? + }.should raise_error(Matrix::ErrDimensionMismatch) end end end diff --git a/spec/ruby/library/matrix/plus_spec.rb b/spec/ruby/library/matrix/plus_spec.rb index 99e6615778d..2706bad060e 100644 --- a/spec/ruby/library/matrix/plus_spec.rb +++ b/spec/ruby/library/matrix/plus_spec.rb @@ -1,45 +1,42 @@ require_relative '../../spec_helper' +require_relative 'fixtures/classes' +require 'matrix' -ruby_version_is ""..."3.1" do - require_relative 'fixtures/classes' - require 'matrix' - - describe "Matrix#+" do - before :each do - @a = Matrix[ [1,2], [3,4] ] - @b = Matrix[ [4,5], [6,7] ] - end +describe "Matrix#+" do + before :each do + @a = Matrix[ [1,2], [3,4] ] + @b = Matrix[ [4,5], [6,7] ] + end - it "returns the result of adding the corresponding elements of self and other" do - (@a + @b).should == Matrix[ [5,7], [9,11] ] - end + it "returns the result of adding the corresponding elements of self and other" do + (@a + @b).should == Matrix[ [5,7], [9,11] ] + end - it "returns an instance of Matrix" do - (@a + @b).should be_kind_of(Matrix) - end + it "returns an instance of Matrix" do + (@a + @b).should be_kind_of(Matrix) + end - it "raises a Matrix::ErrDimensionMismatch if the matrices are different sizes" do - -> { @a + Matrix[ [1] ] }.should raise_error(Matrix::ErrDimensionMismatch) - end + it "raises a Matrix::ErrDimensionMismatch if the matrices are different sizes" do + -> { @a + Matrix[ [1] ] }.should raise_error(Matrix::ErrDimensionMismatch) + end - it "raises a ExceptionForMatrix::ErrOperationNotDefined if other is a Numeric Type" do - -> { @a + 2 }.should raise_error(ExceptionForMatrix::ErrOperationNotDefined) - -> { @a + 1.2 }.should raise_error(ExceptionForMatrix::ErrOperationNotDefined) - -> { @a + bignum_value }.should raise_error(ExceptionForMatrix::ErrOperationNotDefined) - end + it "raises a ExceptionForMatrix::ErrOperationNotDefined if other is a Numeric Type" do + -> { @a + 2 }.should raise_error(ExceptionForMatrix::ErrOperationNotDefined) + -> { @a + 1.2 }.should raise_error(ExceptionForMatrix::ErrOperationNotDefined) + -> { @a + bignum_value }.should raise_error(ExceptionForMatrix::ErrOperationNotDefined) + end - it "raises a TypeError if other is of wrong type" do - -> { @a + nil }.should raise_error(TypeError) - -> { @a + "a" }.should raise_error(TypeError) - -> { @a + [ [1, 2] ] }.should raise_error(TypeError) - -> { @a + Object.new }.should raise_error(TypeError) - end + it "raises a TypeError if other is of wrong type" do + -> { @a + nil }.should raise_error(TypeError) + -> { @a + "a" }.should raise_error(TypeError) + -> { @a + [ [1, 2] ] }.should raise_error(TypeError) + -> { @a + Object.new }.should raise_error(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) - 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) end end end diff --git a/spec/ruby/library/matrix/rank_spec.rb b/spec/ruby/library/matrix/rank_spec.rb index fc795b58c16..d4403d23ed0 100644 --- a/spec/ruby/library/matrix/rank_spec.rb +++ b/spec/ruby/library/matrix/rank_spec.rb @@ -1,22 +1,19 @@ require_relative '../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Matrix#rank" do - it "returns the rank of the Matrix" do - Matrix[ [7,6], [3,9] ].rank.should == 2 - end +describe "Matrix#rank" do + it "returns the rank of the Matrix" do + Matrix[ [7,6], [3,9] ].rank.should == 2 + end - it "doesn't loop forever" do - Matrix[ [1,2,3], [4,5,6], [7,8,9] ].rank.should == 2 - Matrix[ [1, 2, 0, 3], [1, -2, 3, 0], [0, 0, 4, 8], [2, 4, 0, 6] ].rank. - should == 3 - end + it "doesn't loop forever" do + Matrix[ [1,2,3], [4,5,6], [7,8,9] ].rank.should == 2 + Matrix[ [1, 2, 0, 3], [1, -2, 3, 0], [0, 0, 4, 8], [2, 4, 0, 6] ].rank. + should == 3 + end - it "works for some easy rectangular matrices" do - Matrix[[0,0],[0,0],[1,0]].rank.should == 1 - Matrix[[0,1],[0,0],[1,0]].rank.should == 2 - end + it "works for some easy rectangular matrices" do + Matrix[[0,0],[0,0],[1,0]].rank.should == 1 + Matrix[[0,1],[0,0],[1,0]].rank.should == 2 end end diff --git a/spec/ruby/library/matrix/real_spec.rb b/spec/ruby/library/matrix/real_spec.rb index 63a6bde923b..38033c63c8f 100644 --- a/spec/ruby/library/matrix/real_spec.rb +++ b/spec/ruby/library/matrix/real_spec.rb @@ -1,46 +1,43 @@ require_relative '../../spec_helper' +require_relative 'fixtures/classes' +require 'matrix' -ruby_version_is ""..."3.1" do - 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 - end +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 + end - it "returns true for empty matrices" do - Matrix.empty.real?.should be_true - end + it "returns true for empty matrices" do + Matrix.empty.real?.should be_true + end - it "returns false if one element is a Complex" do - Matrix[ [Complex(1,1), 2], [3, 4] ].real?.should be_false - end + it "returns false if one element is a Complex" do + Matrix[ [Complex(1,1), 2], [3, 4] ].real?.should be_false + end - # 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 - end + # 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 end end +end - describe "Matrix#real" do - it "returns a matrix with the real part of the elements of the receiver" do - Matrix[ [1, 2], [3, 4] ].real.should == Matrix[ [1, 2], [3, 4] ] - Matrix[ [1.9, Complex(1,1)], [Complex(-0.42, 0), 4] ].real.should == Matrix[ [1.9, 1], [-0.42, 4] ] - end +describe "Matrix#real" do + it "returns a matrix with the real part of the elements of the receiver" do + Matrix[ [1, 2], [3, 4] ].real.should == Matrix[ [1, 2], [3, 4] ] + Matrix[ [1.9, Complex(1,1)], [Complex(-0.42, 0), 4] ].real.should == Matrix[ [1.9, 1], [-0.42, 4] ] + end - it "returns empty matrices on the same size if empty" do - Matrix.empty(0, 3).real.should == Matrix.empty(0, 3) - Matrix.empty(3, 0).real.should == Matrix.empty(3, 0) - end + it "returns empty matrices on the same size if empty" do + Matrix.empty(0, 3).real.should == Matrix.empty(0, 3) + Matrix.empty(3, 0).real.should == Matrix.empty(3, 0) + end - describe "for a subclass of Matrix" do - it "returns an instance of that subclass" do - MatrixSub.ins.real.should be_an_instance_of(MatrixSub) - end + describe "for a subclass of Matrix" do + it "returns an instance of that subclass" do + MatrixSub.ins.real.should be_an_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 b3b7ac05c99..83a0404e47d 100644 --- a/spec/ruby/library/matrix/rect_spec.rb +++ b/spec/ruby/library/matrix/rect_spec.rb @@ -1,9 +1,6 @@ require_relative '../../spec_helper' +require_relative 'shared/rectangular' -ruby_version_is ""..."3.1" do - require_relative 'shared/rectangular' - - describe "Matrix#rect" do - it_behaves_like :matrix_rectangular, :rect - end +describe "Matrix#rect" do + it_behaves_like :matrix_rectangular, :rect end diff --git a/spec/ruby/library/matrix/rectangular_spec.rb b/spec/ruby/library/matrix/rectangular_spec.rb index 1fc2e0e60db..a235fac640c 100644 --- a/spec/ruby/library/matrix/rectangular_spec.rb +++ b/spec/ruby/library/matrix/rectangular_spec.rb @@ -1,9 +1,6 @@ require_relative '../../spec_helper' +require_relative 'shared/rectangular' -ruby_version_is ""..."3.1" do - require_relative 'shared/rectangular' - - describe "Matrix#rectangular" do - it_behaves_like :matrix_rectangular, :rectangular - end +describe "Matrix#rectangular" do + it_behaves_like :matrix_rectangular, :rectangular end diff --git a/spec/ruby/library/matrix/regular_spec.rb b/spec/ruby/library/matrix/regular_spec.rb index f6688bba302..3699d0ef8bd 100644 --- a/spec/ruby/library/matrix/regular_spec.rb +++ b/spec/ruby/library/matrix/regular_spec.rb @@ -1,34 +1,31 @@ require_relative '../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' +describe "Matrix#regular?" do - 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 - it "returns false for singular matrices" do - m = Matrix[ [1,2,3], [3,4,3], [0,0,0] ] - m.regular?.should be_false - - m = Matrix[ [1,2,9], [3,4,9], [1,2,9] ] - m.regular?.should be_false - end + m = Matrix[ [1,2,9], [3,4,9], [1,2,9] ] + m.regular?.should be_false + end - it "returns true if the Matrix is regular" do - Matrix[ [0,1], [1,0] ].regular?.should be_true - end + it "returns true if the Matrix is regular" do + Matrix[ [0,1], [1,0] ].regular?.should be_true + end - it "returns true for an empty 0x0 matrix" do - Matrix.empty(0,0).regular?.should be_true - end + it "returns true for an empty 0x0 matrix" do + Matrix.empty(0,0).regular?.should be_true + end - it "raises an error for rectangular matrices" do - -> { - Matrix[[1], [2], [3]].regular? - }.should raise_error(Matrix::ErrDimensionMismatch) + it "raises an error for rectangular matrices" do + -> { + Matrix[[1], [2], [3]].regular? + }.should raise_error(Matrix::ErrDimensionMismatch) - -> { - Matrix.empty(3,0).regular? - }.should raise_error(Matrix::ErrDimensionMismatch) - end + -> { + Matrix.empty(3,0).regular? + }.should raise_error(Matrix::ErrDimensionMismatch) end end diff --git a/spec/ruby/library/matrix/round_spec.rb b/spec/ruby/library/matrix/round_spec.rb index db33268414a..1dc29df890b 100644 --- a/spec/ruby/library/matrix/round_spec.rb +++ b/spec/ruby/library/matrix/round_spec.rb @@ -1,24 +1,21 @@ require_relative '../../spec_helper' +require_relative 'fixtures/classes' +require 'matrix' -ruby_version_is ""..."3.1" do - require_relative 'fixtures/classes' - require 'matrix' - - describe "Matrix#round" do - it "returns a matrix with all entries rounded" do - Matrix[ [1, 2.34], [5.67, 8] ].round.should == Matrix[ [1, 2], [6, 8] ] - Matrix[ [1, 2.34], [5.67, 8] ].round(1).should == Matrix[ [1, 2.3], [5.7, 8] ] - end +describe "Matrix#round" do + it "returns a matrix with all entries rounded" do + Matrix[ [1, 2.34], [5.67, 8] ].round.should == Matrix[ [1, 2], [6, 8] ] + Matrix[ [1, 2.34], [5.67, 8] ].round(1).should == Matrix[ [1, 2.3], [5.7, 8] ] + end - it "returns empty matrices on the same size if empty" do - Matrix.empty(0, 3).round.should == Matrix.empty(0, 3) - Matrix.empty(3, 0).round(42).should == Matrix.empty(3, 0) - end + it "returns empty matrices on the same size if empty" do + Matrix.empty(0, 3).round.should == Matrix.empty(0, 3) + Matrix.empty(3, 0).round(42).should == Matrix.empty(3, 0) + end - describe "for a subclass of Matrix" do - it "returns an instance of that subclass" do - MatrixSub.ins.round.should be_an_instance_of(MatrixSub) - end + describe "for a subclass of Matrix" do + it "returns an instance of that subclass" do + MatrixSub.ins.round.should be_an_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 fca5a846ab9..eb3aef2e2fd 100644 --- a/spec/ruby/library/matrix/row_size_spec.rb +++ b/spec/ruby/library/matrix/row_size_spec.rb @@ -1,16 +1,13 @@ require_relative '../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Matrix#row_size" do - it "returns the number rows" do - Matrix[ [1,2], [3, 4], [5, 6] ].row_size.should == 3 - end - - it "returns the number rows even for some empty matrices" do - Matrix[ [], [], [] ].row_size.should == 3 - end +describe "Matrix#row_size" do + it "returns the number rows" do + Matrix[ [1,2], [3, 4], [5, 6] ].row_size.should == 3 + end + it "returns the number rows even for some empty matrices" do + Matrix[ [], [], [] ].row_size.should == 3 end + end diff --git a/spec/ruby/library/matrix/row_spec.rb b/spec/ruby/library/matrix/row_spec.rb index eb05cd92730..00b1f02a8e0 100644 --- a/spec/ruby/library/matrix/row_spec.rb +++ b/spec/ruby/library/matrix/row_spec.rb @@ -1,39 +1,36 @@ require_relative '../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Matrix#row" do - before :all do - @m = Matrix[ [1, 2], [2, 3], [3, 4] ] - end +describe "Matrix#row" do + before :all do + @m = Matrix[ [1, 2], [2, 3], [3, 4] ] + end - it "returns a Vector when called without a block" do - @m.row(0).should == Vector[1,2] - end + it "returns a Vector when called without a block" do + @m.row(0).should == Vector[1,2] + end - it "yields the elements of the row when called with a block" do - a = [] - @m.row(0) {|x| a << x} - a.should == [1,2] - end + it "yields the elements of the row when called with a block" do + a = [] + @m.row(0) {|x| a << x} + a.should == [1,2] + end - it "counts backwards for negative argument" do - @m.row(-1).should == Vector[3, 4] - end + it "counts backwards for negative argument" do + @m.row(-1).should == Vector[3, 4] + end - it "returns self when called with a block" do - @m.row(0) { |x| x }.should equal(@m) - end + it "returns self when called with a block" do + @m.row(0) { |x| x }.should equal(@m) + end - it "returns nil when out of bounds" do - @m.row(3).should == nil - @m.row(-4).should == nil - end + it "returns nil when out of bounds" do + @m.row(3).should == nil + @m.row(-4).should == nil + end - it "never yields when out of bounds" do - -> { @m.row(3){ raise } }.should_not raise_error - -> { @m.row(-4){ raise } }.should_not raise_error - end + it "never yields when out of bounds" do + -> { @m.row(3){ raise } }.should_not raise_error + -> { @m.row(-4){ raise } }.should_not raise_error end end diff --git a/spec/ruby/library/matrix/row_vector_spec.rb b/spec/ruby/library/matrix/row_vector_spec.rb index 4c97d6013ad..341437ee05c 100644 --- a/spec/ruby/library/matrix/row_vector_spec.rb +++ b/spec/ruby/library/matrix/row_vector_spec.rb @@ -1,27 +1,24 @@ require_relative '../../spec_helper' +require_relative 'fixtures/classes' +require 'matrix' -ruby_version_is ""..."3.1" do - require_relative 'fixtures/classes' - require 'matrix' +describe "Matrix.row_vector" do - describe "Matrix.row_vector" do - - it "returns a Matrix" do - Matrix.row_vector([]).should be_an_instance_of(Matrix) - end + it "returns a Matrix" do + Matrix.row_vector([]).should be_an_instance_of(Matrix) + end - it "returns a single-row Matrix with the specified values" do - Matrix.row_vector([1,2]).should == Matrix[ [1,2] ] - end + it "returns a single-row Matrix with the specified values" do + Matrix.row_vector([1,2]).should == Matrix[ [1,2] ] + end - it "returns a 1x0 matrix when called with an empty Array" do - Matrix.row_vector([]).should == Matrix[ [] ] - end + it "returns a 1x0 matrix when called with an empty Array" do + Matrix.row_vector([]).should == Matrix[ [] ] + end - 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) - end + 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) end end end diff --git a/spec/ruby/library/matrix/row_vectors_spec.rb b/spec/ruby/library/matrix/row_vectors_spec.rb index d01a4ca10dd..6f99c439a67 100644 --- a/spec/ruby/library/matrix/row_vectors_spec.rb +++ b/spec/ruby/library/matrix/row_vectors_spec.rb @@ -1,29 +1,26 @@ require_relative '../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' +describe "Matrix#row_vectors" do - describe "Matrix#row_vectors" do - - before :each do - @vectors = Matrix[ [1,2], [3,4] ].row_vectors - end + before :each do + @vectors = Matrix[ [1,2], [3,4] ].row_vectors + end - it "returns an Array" do - Matrix[ [1,2], [3,4] ].row_vectors.should be_an_instance_of(Array) - end + it "returns an Array" do + Matrix[ [1,2], [3,4] ].row_vectors.should be_an_instance_of(Array) + end - it "returns an Array of Vectors" do - @vectors.all? {|v| v.should be_an_instance_of(Vector)} - end + it "returns an Array of Vectors" do + @vectors.all? {|v| v.should be_an_instance_of(Vector)} + end - it "returns each row as a Vector" do - @vectors.should == [Vector[1,2], Vector[3,4]] - end + it "returns each row as a Vector" do + @vectors.should == [Vector[1,2], Vector[3,4]] + end - it "returns an empty Array for empty matrices" do - Matrix[].row_vectors.should == [] - Matrix[ [] ].row_vectors.should == [ Vector[] ] - end + it "returns an empty Array for empty matrices" do + Matrix[].row_vectors.should == [] + Matrix[ [] ].row_vectors.should == [ Vector[] ] end end diff --git a/spec/ruby/library/matrix/rows_spec.rb b/spec/ruby/library/matrix/rows_spec.rb index 5f0515a37bd..41ba6357757 100644 --- a/spec/ruby/library/matrix/rows_spec.rb +++ b/spec/ruby/library/matrix/rows_spec.rb @@ -1,44 +1,41 @@ require_relative '../../spec_helper' +require_relative 'fixtures/classes' +require 'matrix' -ruby_version_is ""..."3.1" do - require_relative 'fixtures/classes' - require 'matrix' - - describe "Matrix.rows" do - before :each do - @a = [1, 2] - @b = [3, 4] - @m = Matrix.rows([@a, @b]) - end +describe "Matrix.rows" do + before :each do + @a = [1, 2] + @b = [3, 4] + @m = Matrix.rows([@a, @b]) + end - it "returns a Matrix" do - @m.should be_kind_of(Matrix) - end + it "returns a Matrix" do + @m.should be_kind_of(Matrix) + end - it "creates a matrix from argument rows" do - @m.row(0).to_a.should == @a - @m.row(1).to_a.should == @b - end + it "creates a matrix from argument rows" do + @m.row(0).to_a.should == @a + @m.row(1).to_a.should == @b + end - 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) - end + 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) + end - it "references the original rows if copy is false" do - @m_ref = Matrix.rows([@a, @b], false) - @a << 3 - @b << 6 - @m_ref.row(0).to_a.should == @a - @m_ref.row(1).to_a.should == @b - end + it "references the original rows if copy is false" do + @m_ref = Matrix.rows([@a, @b], false) + @a << 3 + @b << 6 + @m_ref.row(0).to_a.should == @a + @m_ref.row(1).to_a.should == @b + end - 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) - end + 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) end end end diff --git a/spec/ruby/library/matrix/scalar/Fail_spec.rb b/spec/ruby/library/matrix/scalar/Fail_spec.rb index 4f774eda285..9d8f9bd5e87 100644 --- a/spec/ruby/library/matrix/scalar/Fail_spec.rb +++ b/spec/ruby/library/matrix/scalar/Fail_spec.rb @@ -1,9 +1,6 @@ require_relative '../../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Matrix::Scalar#Fail" do - it "needs to be reviewed for spec completeness" - end +describe "Matrix::Scalar#Fail" do + it "needs to be reviewed for spec completeness" end diff --git a/spec/ruby/library/matrix/scalar/Raise_spec.rb b/spec/ruby/library/matrix/scalar/Raise_spec.rb index b405b6d6c55..27e11c1f77b 100644 --- a/spec/ruby/library/matrix/scalar/Raise_spec.rb +++ b/spec/ruby/library/matrix/scalar/Raise_spec.rb @@ -1,9 +1,6 @@ require_relative '../../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Matrix::Scalar#Raise" do - it "needs to be reviewed for spec completeness" - end +describe "Matrix::Scalar#Raise" do + it "needs to be reviewed for spec completeness" end diff --git a/spec/ruby/library/matrix/scalar/divide_spec.rb b/spec/ruby/library/matrix/scalar/divide_spec.rb index 0ef2206bf6d..5d726943fe4 100644 --- a/spec/ruby/library/matrix/scalar/divide_spec.rb +++ b/spec/ruby/library/matrix/scalar/divide_spec.rb @@ -1,9 +1,6 @@ require_relative '../../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Matrix::Scalar#/" do - it "needs to be reviewed for spec completeness" - end +describe "Matrix::Scalar#/" do + it "needs to be reviewed for spec completeness" end diff --git a/spec/ruby/library/matrix/scalar/exponent_spec.rb b/spec/ruby/library/matrix/scalar/exponent_spec.rb index 87eea283d16..8e9ef52ff2e 100644 --- a/spec/ruby/library/matrix/scalar/exponent_spec.rb +++ b/spec/ruby/library/matrix/scalar/exponent_spec.rb @@ -1,9 +1,6 @@ require_relative '../../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Matrix::Scalar#**" do - it "needs to be reviewed for spec completeness" - end +describe "Matrix::Scalar#**" do + it "needs to be reviewed for spec completeness" end diff --git a/spec/ruby/library/matrix/scalar/included_spec.rb b/spec/ruby/library/matrix/scalar/included_spec.rb index bab80e51202..cb3beb2ecd6 100644 --- a/spec/ruby/library/matrix/scalar/included_spec.rb +++ b/spec/ruby/library/matrix/scalar/included_spec.rb @@ -1,9 +1,6 @@ require_relative '../../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Matrix::Scalar.included" do - it "needs to be reviewed for spec completeness" - end +describe "Matrix::Scalar.included" do + it "needs to be reviewed for spec completeness" end diff --git a/spec/ruby/library/matrix/scalar/initialize_spec.rb b/spec/ruby/library/matrix/scalar/initialize_spec.rb index af51562b431..23145ad0de8 100644 --- a/spec/ruby/library/matrix/scalar/initialize_spec.rb +++ b/spec/ruby/library/matrix/scalar/initialize_spec.rb @@ -1,9 +1,6 @@ require_relative '../../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Matrix::Scalar#initialize" do - it "needs to be reviewed for spec completeness" - end +describe "Matrix::Scalar#initialize" do + it "needs to be reviewed for spec completeness" end diff --git a/spec/ruby/library/matrix/scalar/minus_spec.rb b/spec/ruby/library/matrix/scalar/minus_spec.rb index 966db1d75b5..c727ea16595 100644 --- a/spec/ruby/library/matrix/scalar/minus_spec.rb +++ b/spec/ruby/library/matrix/scalar/minus_spec.rb @@ -1,9 +1,6 @@ require_relative '../../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Matrix::Scalar#-" do - it "needs to be reviewed for spec completeness" - end +describe "Matrix::Scalar#-" do + it "needs to be reviewed for spec completeness" end diff --git a/spec/ruby/library/matrix/scalar/multiply_spec.rb b/spec/ruby/library/matrix/scalar/multiply_spec.rb index 21caac478b0..1a2a83d83e6 100644 --- a/spec/ruby/library/matrix/scalar/multiply_spec.rb +++ b/spec/ruby/library/matrix/scalar/multiply_spec.rb @@ -1,9 +1,6 @@ require_relative '../../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Matrix::Scalar#*" do - it "needs to be reviewed for spec completeness" - end +describe "Matrix::Scalar#*" do + it "needs to be reviewed for spec completeness" end diff --git a/spec/ruby/library/matrix/scalar/plus_spec.rb b/spec/ruby/library/matrix/scalar/plus_spec.rb index 78cdf9367f8..c94689a7025 100644 --- a/spec/ruby/library/matrix/scalar/plus_spec.rb +++ b/spec/ruby/library/matrix/scalar/plus_spec.rb @@ -1,9 +1,6 @@ require_relative '../../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Matrix::Scalar#+" do - it "needs to be reviewed for spec completeness" - end +describe "Matrix::Scalar#+" do + it "needs to be reviewed for spec completeness" end diff --git a/spec/ruby/library/matrix/scalar_spec.rb b/spec/ruby/library/matrix/scalar_spec.rb index 1ec64d2d782..7fdd64c9d95 100644 --- a/spec/ruby/library/matrix/scalar_spec.rb +++ b/spec/ruby/library/matrix/scalar_spec.rb @@ -1,68 +1,65 @@ require_relative '../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' +describe "Matrix.scalar" do - describe "Matrix.scalar" do - - before :each do - @side = 3 - @value = 8 - @a = Matrix.scalar(@side, @value) - end + before :each do + @side = 3 + @value = 8 + @a = Matrix.scalar(@side, @value) + end - it "returns a Matrix" do - @a.should be_kind_of(Matrix) - end + it "returns a Matrix" do + @a.should be_kind_of(Matrix) + end - it "returns a n x n matrix" do - @a.row_size.should == @side - @a.column_size.should == @side - end + it "returns a n x n matrix" do + @a.row_size.should == @side + @a.column_size.should == @side + end - it "initializes diagonal to value" do - (0...@a.row_size).each do |i| - @a[i, i].should == @value - end + it "initializes diagonal to value" do + (0...@a.row_size).each do |i| + @a[i, i].should == @value end + end - it "initializes all non-diagonal values to 0" do - (0...@a.row_size).each do |i| - (0...@a.column_size).each do |j| - if i != j - @a[i, j].should == 0 - end + it "initializes all non-diagonal values to 0" do + (0...@a.row_size).each do |i| + (0...@a.column_size).each do |j| + if i != j + @a[i, j].should == 0 end end end + end - before :each do - @side = 3 - @value = 8 - @a = Matrix.scalar(@side, @value) - end + before :each do + @side = 3 + @value = 8 + @a = Matrix.scalar(@side, @value) + end - it "returns a Matrix" do - @a.should be_kind_of(Matrix) - end + it "returns a Matrix" do + @a.should be_kind_of(Matrix) + end - it "returns a square matrix, where the first argument specifies the side of the square" do - @a.row_size.should == @side - @a.column_size.should == @side - end + it "returns a square matrix, where the first argument specifies the side of the square" do + @a.row_size.should == @side + @a.column_size.should == @side + end - it "puts the second argument in all diagonal values" do - (0...@a.row_size).each do |i| - @a[i, i].should == @value - end + it "puts the second argument in all diagonal values" do + (0...@a.row_size).each do |i| + @a[i, i].should == @value end + end - it "fills all values not on the main diagonal with 0" do - (0...@a.row_size).each do |i| - (0...@a.column_size).each do |j| - if i != j - @a[i, j].should == 0 - end + it "fills all values not on the main diagonal with 0" do + (0...@a.row_size).each do |i| + (0...@a.column_size).each do |j| + if i != j + @a[i, j].should == 0 end end end diff --git a/spec/ruby/library/matrix/singular_spec.rb b/spec/ruby/library/matrix/singular_spec.rb index 341c2675a81..7bba36a54ac 100644 --- a/spec/ruby/library/matrix/singular_spec.rb +++ b/spec/ruby/library/matrix/singular_spec.rb @@ -1,34 +1,31 @@ require_relative '../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - 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 - 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 = Matrix[ [1,2,9], [3,4,9], [1,2,9] ] - m.singular?.should be_true - end - - it "returns false if the Matrix is regular" do - Matrix[ [0,1], [1,0] ].singular?.should be_false - end + m = Matrix[ [1,2,9], [3,4,9], [1,2,9] ] + m.singular?.should be_true + end - it "returns false for an empty 0x0 matrix" do - Matrix.empty(0,0).singular?.should be_false - end + it "returns false if the Matrix is regular" do + Matrix[ [0,1], [1,0] ].singular?.should be_false + end - it "raises an error for rectangular matrices" do - -> { - Matrix[[1], [2], [3]].singular? - }.should raise_error(Matrix::ErrDimensionMismatch) + it "returns false for an empty 0x0 matrix" do + Matrix.empty(0,0).singular?.should be_false + end - -> { - Matrix.empty(3,0).singular? - }.should raise_error(Matrix::ErrDimensionMismatch) - end + it "raises an error for rectangular matrices" do + -> { + Matrix[[1], [2], [3]].singular? + }.should raise_error(Matrix::ErrDimensionMismatch) + -> { + Matrix.empty(3,0).singular? + }.should raise_error(Matrix::ErrDimensionMismatch) end + end diff --git a/spec/ruby/library/matrix/square_spec.rb b/spec/ruby/library/matrix/square_spec.rb index e678f1c7021..25d2d1ad9c2 100644 --- a/spec/ruby/library/matrix/square_spec.rb +++ b/spec/ruby/library/matrix/square_spec.rb @@ -1,31 +1,28 @@ require_relative '../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' +describe "Matrix#square?" do - 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 - end + 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 + end - it "returns true when the Matrix has only one element" do - Matrix[ [9] ].square?.should be_true - end + it "returns true when the Matrix has only one element" do + Matrix[ [9] ].square?.should be_true + end - it "returns false when the Matrix is rectangular" do - Matrix[ [1, 2] ].square?.should be_false - end + it "returns false when the Matrix is rectangular" do + Matrix[ [1, 2] ].square?.should be_false + end - it "returns false when the Matrix is rectangular" do - Matrix[ [1], [2] ].square?.should be_false - end + it "returns false when the Matrix is rectangular" do + Matrix[ [1], [2] ].square?.should be_false + end - it "returns handles empty matrices" do - Matrix[].square?.should be_true - Matrix[[]].square?.should be_false - Matrix.columns([[]]).square?.should be_false - end + it "returns handles empty matrices" do + Matrix[].square?.should be_true + Matrix[[]].square?.should be_false + Matrix.columns([[]]).square?.should be_false end end diff --git a/spec/ruby/library/matrix/symmetric_spec.rb b/spec/ruby/library/matrix/symmetric_spec.rb index 9eed28ac0d3..6f2a99276ab 100644 --- a/spec/ruby/library/matrix/symmetric_spec.rb +++ b/spec/ruby/library/matrix/symmetric_spec.rb @@ -1,32 +1,29 @@ require_relative '../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - 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 - end +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 + end - it "returns true for a 0x0 empty matrix" do - Matrix.empty.symmetric?.should be_true - end + it "returns true for a 0x0 empty matrix" do + Matrix.empty.symmetric?.should be_true + end - it "returns false for an asymmetric Matrix" do - Matrix[[1, 2],[-2, 1]].symmetric?.should be_false - end + it "returns false for an asymmetric Matrix" do + Matrix[[1, 2],[-2, 1]].symmetric?.should be_false + 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.symmetric? - }.should raise_error(Matrix::ErrDimensionMismatch) - 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.symmetric? + }.should raise_error(Matrix::ErrDimensionMismatch) end end end diff --git a/spec/ruby/library/matrix/t_spec.rb b/spec/ruby/library/matrix/t_spec.rb index 6eb54371ee8..6f1a5178e0a 100644 --- a/spec/ruby/library/matrix/t_spec.rb +++ b/spec/ruby/library/matrix/t_spec.rb @@ -1,9 +1,6 @@ require_relative '../../spec_helper' +require_relative 'shared/transpose' -ruby_version_is ""..."3.1" do - require_relative 'shared/transpose' - - describe "Matrix#transpose" do - it_behaves_like :matrix_transpose, :t - end +describe "Matrix#transpose" do + it_behaves_like :matrix_transpose, :t end diff --git a/spec/ruby/library/matrix/to_a_spec.rb b/spec/ruby/library/matrix/to_a_spec.rb index 0222a663ac2..b5d55c5d675 100644 --- a/spec/ruby/library/matrix/to_a_spec.rb +++ b/spec/ruby/library/matrix/to_a_spec.rb @@ -1,14 +1,11 @@ require_relative '../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Matrix#to_a" do - it "returns the array of arrays that describe the rows of the matrix" do - Matrix[].to_a.should == [] - Matrix[[]].to_a.should == [[]] - Matrix[[1]].to_a.should == [[1]] - Matrix[[1, 2], [3, 4]].to_a.should == [[1, 2],[3, 4]] - end +describe "Matrix#to_a" do + it "returns the array of arrays that describe the rows of the matrix" do + Matrix[].to_a.should == [] + Matrix[[]].to_a.should == [[]] + Matrix[[1]].to_a.should == [[1]] + Matrix[[1, 2], [3, 4]].to_a.should == [[1, 2],[3, 4]] end end diff --git a/spec/ruby/library/matrix/to_s_spec.rb b/spec/ruby/library/matrix/to_s_spec.rb index 7d38655e0de..f529fe3bcd3 100644 --- a/spec/ruby/library/matrix/to_s_spec.rb +++ b/spec/ruby/library/matrix/to_s_spec.rb @@ -1,9 +1,6 @@ require_relative '../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Matrix#to_s" do - it "needs to be reviewed for spec completeness" - end +describe "Matrix#to_s" do + it "needs to be reviewed for spec completeness" end diff --git a/spec/ruby/library/matrix/tr_spec.rb b/spec/ruby/library/matrix/tr_spec.rb index bbf274bb5ef..e17bd790d74 100644 --- a/spec/ruby/library/matrix/tr_spec.rb +++ b/spec/ruby/library/matrix/tr_spec.rb @@ -1,10 +1,7 @@ require_relative '../../spec_helper' +require_relative 'shared/trace' +require 'matrix' -ruby_version_is ""..."3.1" do - require_relative 'shared/trace' - require 'matrix' - - describe "Matrix#tr" do - it_behaves_like :trace, :tr - end +describe "Matrix#tr" do + it_behaves_like :trace, :tr end diff --git a/spec/ruby/library/matrix/trace_spec.rb b/spec/ruby/library/matrix/trace_spec.rb index ac6ce7927d4..290e7cb1f71 100644 --- a/spec/ruby/library/matrix/trace_spec.rb +++ b/spec/ruby/library/matrix/trace_spec.rb @@ -1,10 +1,7 @@ require_relative '../../spec_helper' +require_relative 'shared/trace' +require 'matrix' -ruby_version_is ""..."3.1" do - require_relative 'shared/trace' - require 'matrix' - - describe "Matrix#trace" do - it_behaves_like :trace, :trace - end +describe "Matrix#trace" do + it_behaves_like :trace, :trace end diff --git a/spec/ruby/library/matrix/transpose_spec.rb b/spec/ruby/library/matrix/transpose_spec.rb index d7f495b946f..79600dd439e 100644 --- a/spec/ruby/library/matrix/transpose_spec.rb +++ b/spec/ruby/library/matrix/transpose_spec.rb @@ -1,9 +1,6 @@ require_relative '../../spec_helper' +require_relative 'shared/transpose' -ruby_version_is ""..."3.1" do - require_relative 'shared/transpose' - - describe "Matrix#transpose" do - it_behaves_like :matrix_transpose, :transpose - end +describe "Matrix#transpose" do + it_behaves_like :matrix_transpose, :transpose end diff --git a/spec/ruby/library/matrix/unit_spec.rb b/spec/ruby/library/matrix/unit_spec.rb index 439e0d616be..6a41d729c72 100644 --- a/spec/ruby/library/matrix/unit_spec.rb +++ b/spec/ruby/library/matrix/unit_spec.rb @@ -1,9 +1,6 @@ require_relative '../../spec_helper' +require_relative 'shared/identity' -ruby_version_is ""..."3.1" do - require_relative 'shared/identity' - - describe "Matrix.unit" do - it_behaves_like :matrix_identity, :unit - end +describe "Matrix.unit" do + it_behaves_like :matrix_identity, :unit end diff --git a/spec/ruby/library/matrix/unitary_spec.rb b/spec/ruby/library/matrix/unitary_spec.rb index 04e6df8be09..c214ee9b2f6 100644 --- a/spec/ruby/library/matrix/unitary_spec.rb +++ b/spec/ruby/library/matrix/unitary_spec.rb @@ -1,34 +1,32 @@ require_relative '../../spec_helper' -ruby_version_is ""..."3.1" do - require 'matrix' +require 'matrix' - describe "Matrix.unitary?" do - it "returns false for non unitary matrices" do - 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 +describe "Matrix.unitary?" do + it "returns false for non unitary matrices" do + 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]].should.unitary? - end + it "returns true for unitary matrices" do + 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 "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 - [ - Matrix[[0], [0]], - Matrix[[0, 0]], - Matrix.empty(0, 2), - Matrix.empty(2, 0), - ].each do |rectangular_matrix| - -> { - rectangular_matrix.unitary? - }.should raise_error(Matrix::ErrDimensionMismatch) - 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.unitary? + }.should raise_error(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 cc2aeb72333..2514294a804 100644 --- a/spec/ruby/library/matrix/upper_triangular_spec.rb +++ b/spec/ruby/library/matrix/upper_triangular_spec.rb @@ -1,27 +1,24 @@ require_relative '../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - 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 - end +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 + 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 - 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 + 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 - 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 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 88523824cd9..c2698ade4c7 100644 --- a/spec/ruby/library/matrix/vector/cross_product_spec.rb +++ b/spec/ruby/library/matrix/vector/cross_product_spec.rb @@ -1,17 +1,14 @@ require_relative '../../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Vector#cross_product" do - it "returns the cross product of a vector" do - Vector[1, 2, 3].cross_product(Vector[0, -4, 5]).should == Vector[22, -5, -4] - end +describe "Vector#cross_product" do + it "returns the cross product of a vector" do + Vector[1, 2, 3].cross_product(Vector[0, -4, 5]).should == Vector[22, -5, -4] + end - it "raises an error unless both vectors have dimension 3" do - -> { - Vector[1, 2, 3].cross_product(Vector[0, -4]) - }.should raise_error(Vector::ErrDimensionMismatch) - end + it "raises an error unless both vectors have dimension 3" do + -> { + Vector[1, 2, 3].cross_product(Vector[0, -4]) + }.should raise_error(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 bdd6966472e..10d2fc404d4 100644 --- a/spec/ruby/library/matrix/vector/each2_spec.rb +++ b/spec/ruby/library/matrix/vector/each2_spec.rb @@ -1,52 +1,49 @@ require_relative '../../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' +describe "Vector.each2" do + before :all do + @v = Vector[1, 2, 3] + @v2 = Vector[4, 5, 6] + end + + it "requires one argument" do + -> { @v.each2(@v2, @v2){} }.should raise_error(ArgumentError) + -> { @v.each2(){} }.should raise_error(ArgumentError) + end + + describe "given one argument" do + it "accepts an Array argument" do + a = [] + @v.each2([7, 8, 9]){|x, y| a << x << y} + a.should == [1, 7, 2, 8, 3, 9] + end + + it "raises a DimensionMismatch error if the Vector size is different" do + -> { @v.each2(Vector[1,2]){} }.should raise_error(Vector::ErrDimensionMismatch) + -> { @v.each2(Vector[1,2,3,4]){} }.should raise_error(Vector::ErrDimensionMismatch) + end + + it "yields arguments in sequence" do + a = [] + @v.each2(@v2){|first, second| a << [first, second]} + a.should == [[1, 4], [2, 5], [3, 6]] + end - describe "Vector.each2" do - before :all do - @v = Vector[1, 2, 3] - @v2 = Vector[4, 5, 6] + it "yield arguments in pairs" do + a = [] + @v.each2(@v2){|*pair| a << pair} + a.should == [[1, 4], [2, 5], [3, 6]] end - it "requires one argument" do - -> { @v.each2(@v2, @v2){} }.should raise_error(ArgumentError) - -> { @v.each2(){} }.should raise_error(ArgumentError) + it "returns self when given a block" do + @v.each2(@v2){}.should equal(@v) end - describe "given one argument" do - it "accepts an Array argument" do - a = [] - @v.each2([7, 8, 9]){|x, y| a << x << y} - a.should == [1, 7, 2, 8, 3, 9] - end - - it "raises a DimensionMismatch error if the Vector size is different" do - -> { @v.each2(Vector[1,2]){} }.should raise_error(Vector::ErrDimensionMismatch) - -> { @v.each2(Vector[1,2,3,4]){} }.should raise_error(Vector::ErrDimensionMismatch) - end - - it "yields arguments in sequence" do - a = [] - @v.each2(@v2){|first, second| a << [first, second]} - a.should == [[1, 4], [2, 5], [3, 6]] - end - - it "yield arguments in pairs" do - a = [] - @v.each2(@v2){|*pair| a << pair} - a.should == [[1, 4], [2, 5], [3, 6]] - end - - it "returns self when given a block" do - @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.to_a.should == [[1, 4], [2, 5], [3, 6]] - end + it "returns an enumerator if no block given" do + enum = @v.each2(@v2) + enum.should be_an_instance_of(Enumerator) + enum.to_a.should == [[1, 4], [2, 5], [3, 6]] end end end diff --git a/spec/ruby/library/matrix/vector/eql_spec.rb b/spec/ruby/library/matrix/vector/eql_spec.rb index fa086bd33af..eb2451b550d 100644 --- a/spec/ruby/library/matrix/vector/eql_spec.rb +++ b/spec/ruby/library/matrix/vector/eql_spec.rb @@ -1,19 +1,16 @@ require_relative '../../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Vector#eql?" do - before do - @vector = Vector[1, 2, 3, 4, 5] - end +describe "Vector#eql?" do + before do + @vector = Vector[1, 2, 3, 4, 5] + end - it "returns true for self" do - @vector.eql?(@vector).should be_true - end + it "returns true for self" do + @vector.eql?(@vector).should be_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 - 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 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 95dc4806b50..1cf8771e045 100644 --- a/spec/ruby/library/matrix/vector/inner_product_spec.rb +++ b/spec/ruby/library/matrix/vector/inner_product_spec.rb @@ -1,25 +1,22 @@ require_relative '../../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Vector#inner_product" do - it "returns the inner product of a vector" do - Vector[1, 2, 3].inner_product(Vector[0, -4, 5]).should == 7 - end +describe "Vector#inner_product" do + it "returns the inner product of a vector" do + Vector[1, 2, 3].inner_product(Vector[0, -4, 5]).should == 7 + end - it "returns 0 for empty vectors" do - Vector[].inner_product(Vector[]).should == 0 - end + it "returns 0 for empty vectors" do + Vector[].inner_product(Vector[]).should == 0 + end - it "raises an error for mismatched vectors" do - -> { - Vector[1, 2, 3].inner_product(Vector[0, -4]) - }.should raise_error(Vector::ErrDimensionMismatch) - end + it "raises an error for mismatched vectors" do + -> { + Vector[1, 2, 3].inner_product(Vector[0, -4]) + }.should raise_error(Vector::ErrDimensionMismatch) + end - it "uses the conjugate of its argument" do - Vector[Complex(1,2)].inner_product(Vector[Complex(3,4)]).should == Complex(11, 2) - end + it "uses the conjugate of its argument" do + Vector[Complex(1,2)].inner_product(Vector[Complex(3,4)]).should == Complex(11, 2) end end diff --git a/spec/ruby/library/matrix/vector/normalize_spec.rb b/spec/ruby/library/matrix/vector/normalize_spec.rb index 7345e11fa49..527c9260deb 100644 --- a/spec/ruby/library/matrix/vector/normalize_spec.rb +++ b/spec/ruby/library/matrix/vector/normalize_spec.rb @@ -1,21 +1,18 @@ require_relative '../../../spec_helper' +require 'matrix' -ruby_version_is ""..."3.1" do - require 'matrix' - - describe "Vector#normalize" do - it "returns a normalized copy of the vector" do - x = 0.2672612419124244 - Vector[1, 2, 3].normalize.should == Vector[x, x * 2, x * 3] - end +describe "Vector#normalize" do + it "returns a normalized copy of the vector" do + x = 0.2672612419124244 + Vector[1, 2, 3].normalize.should == Vector[x, x * 2, x * 3] + end - it "raises an error for zero vectors" do - -> { - Vector[].normalize - }.should raise_error(Vector::ZeroVectorError) - -> { - Vector[0, 0, 0].normalize - }.should raise_error(Vector::ZeroVectorError) - end + it "raises an error for zero vectors" do + -> { + Vector[].normalize + }.should raise_error(Vector::ZeroVectorError) + -> { + Vector[0, 0, 0].normalize + }.should raise_error(Vector::ZeroVectorError) end end diff --git a/spec/ruby/library/matrix/zero_spec.rb b/spec/ruby/library/matrix/zero_spec.rb index 80162a03d0a..68e8567c260 100644 --- a/spec/ruby/library/matrix/zero_spec.rb +++ b/spec/ruby/library/matrix/zero_spec.rb @@ -1,55 +1,52 @@ require_relative '../../spec_helper' +require_relative 'fixtures/classes' +require 'matrix' -ruby_version_is ""..."3.1" do - 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) - end +describe "Matrix.zero" do + it "returns an object of type Matrix" do + Matrix.zero(3).should be_kind_of(Matrix) + end - it "creates a n x n matrix" do - m3 = Matrix.zero(3) - m3.row_size.should == 3 - m3.column_size.should == 3 + it "creates a n x n matrix" do + m3 = Matrix.zero(3) + m3.row_size.should == 3 + m3.column_size.should == 3 - m8 = Matrix.zero(8) - m8.row_size.should == 8 - m8.column_size.should == 8 - end + m8 = Matrix.zero(8) + m8.row_size.should == 8 + m8.column_size.should == 8 + end - it "initializes all cells to 0" do - size = 10 - m = Matrix.zero(size) + it "initializes all cells to 0" do + size = 10 + m = Matrix.zero(size) - (0...size).each do |i| - (0...size).each do |j| - m[i, j].should == 0 - end + (0...size).each do |i| + (0...size).each do |j| + m[i, j].should == 0 end end + end - describe "for a subclass of Matrix" do - it "returns an instance of that subclass" do - MatrixSub.zero(3).should be_an_instance_of(MatrixSub) - end + describe "for a subclass of Matrix" do + it "returns an instance of that subclass" do + MatrixSub.zero(3).should be_an_instance_of(MatrixSub) end end +end - describe "Matrix.zero?" do - it "returns true for empty matrices" do - Matrix.empty.should.zero? - Matrix.empty(3,0).should.zero? - Matrix.empty(0,3).should.zero? - end +describe "Matrix.zero?" do + it "returns true for empty matrices" do + 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).should.zero? - end + it "returns true for matrices with zero entries" do + Matrix.zero(2,3).should.zero? + end - it "returns false for matrices with non zero entries" do - Matrix[[1]].should_not.zero? - end + it "returns false for matrices with non zero entries" do + Matrix[[1]].should_not.zero? 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 00000000000..0c31b65dcc4 --- /dev/null +++ b/spec/ruby/library/net-ftp/FTPError_spec.rb @@ -0,0 +1,8 @@ +require_relative '../../spec_helper' +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-ftp/FTPPermError_spec.rb b/spec/ruby/library/net-ftp/FTPPermError_spec.rb new file mode 100644 index 00000000000..b43e12c5035 --- /dev/null +++ b/spec/ruby/library/net-ftp/FTPPermError_spec.rb @@ -0,0 +1,12 @@ +require_relative '../../spec_helper' +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-ftp/FTPProtoError_spec.rb b/spec/ruby/library/net-ftp/FTPProtoError_spec.rb new file mode 100644 index 00000000000..e7abbc0dd81 --- /dev/null +++ b/spec/ruby/library/net-ftp/FTPProtoError_spec.rb @@ -0,0 +1,12 @@ +require_relative '../../spec_helper' +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-ftp/FTPReplyError_spec.rb b/spec/ruby/library/net-ftp/FTPReplyError_spec.rb new file mode 100644 index 00000000000..fcc7501fc11 --- /dev/null +++ b/spec/ruby/library/net-ftp/FTPReplyError_spec.rb @@ -0,0 +1,12 @@ +require_relative '../../spec_helper' +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-ftp/FTPTempError_spec.rb b/spec/ruby/library/net-ftp/FTPTempError_spec.rb new file mode 100644 index 00000000000..f4b045dfb5b --- /dev/null +++ b/spec/ruby/library/net-ftp/FTPTempError_spec.rb @@ -0,0 +1,12 @@ +require_relative '../../spec_helper' +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 new file mode 100644 index 00000000000..335d056512a --- /dev/null +++ b/spec/ruby/library/net-ftp/abort_spec.rb @@ -0,0 +1,62 @@ +require_relative '../../spec_helper' +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_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.") + -> { @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.") + -> { @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.") + -> { @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.") + -> { @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.") + -> { @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.") + -> { @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 new file mode 100644 index 00000000000..ab093448a26 --- /dev/null +++ b/spec/ruby/library/net-ftp/acct_spec.rb @@ -0,0 +1,58 @@ +require_relative '../../spec_helper' +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_error + 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_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.") + -> { @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.") + -> { @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.") + -> { @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.") + -> { @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 new file mode 100644 index 00000000000..1e0585b7954 --- /dev/null +++ b/spec/ruby/library/net-ftp/binary_spec.rb @@ -0,0 +1,24 @@ +require_relative '../../spec_helper' +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 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 new file mode 100644 index 00000000000..cc129b5e42c --- /dev/null +++ b/spec/ruby/library/net-ftp/chdir_spec.rb @@ -0,0 +1,99 @@ +require_relative '../../spec_helper' +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 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.") + -> { @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.") + -> { @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.") + -> { @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.") + -> { @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.") + -> { @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.") + -> { @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.") + -> { @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.") + -> { @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.") + -> { @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.") + -> { @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.") + -> { @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.") + -> { @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 new file mode 100644 index 00000000000..183f14a84b5 --- /dev/null +++ b/spec/ruby/library/net-ftp/close_spec.rb @@ -0,0 +1,30 @@ +require_relative '../../spec_helper' +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 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 new file mode 100644 index 00000000000..84001cdc0f5 --- /dev/null +++ b/spec/ruby/library/net-ftp/closed_spec.rb @@ -0,0 +1,21 @@ +require_relative '../../spec_helper' +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 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 new file mode 100644 index 00000000000..4330d430b47 --- /dev/null +++ b/spec/ruby/library/net-ftp/connect_spec.rb @@ -0,0 +1,51 @@ +require_relative '../../spec_helper' +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_error + end + + it "returns nil" do + @ftp.connect(@server.hostname, @server.server_port).should be_nil + end + + ruby_version_is ""..."3.1" do + it "prints a small debug line when in debug mode" do + @ftp.debug_mode = true + -> { @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 + 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_error + 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_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." + -> { @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 new file mode 100644 index 00000000000..f2ef53c0896 --- /dev/null +++ b/spec/ruby/library/net-ftp/debug_mode_spec.rb @@ -0,0 +1,23 @@ +require_relative '../../spec_helper' +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 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 new file mode 100644 index 00000000000..3f14f6187e6 --- /dev/null +++ b/spec/ruby/library/net-ftp/default_passive_spec.rb @@ -0,0 +1,8 @@ +require_relative '../../spec_helper' +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 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 00000000000..bfb7da1ffef --- /dev/null +++ b/spec/ruby/library/net-ftp/delete_spec.rb @@ -0,0 +1,59 @@ +require_relative '../../spec_helper' +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_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.") + -> { @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.") + -> { @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.") + -> { @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.") + -> { @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.") + -> { @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.") + -> { @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 new file mode 100644 index 00000000000..894f03dd7b8 --- /dev/null +++ b/spec/ruby/library/net-ftp/dir_spec.rb @@ -0,0 +1,8 @@ +require_relative '../../spec_helper' +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 diff --git a/spec/ruby/library/net/ftp/fixtures/default_passive.rb b/spec/ruby/library/net-ftp/fixtures/default_passive.rb similarity index 100% rename from spec/ruby/library/net/ftp/fixtures/default_passive.rb rename to 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 similarity index 100% rename from spec/ruby/library/net/ftp/fixtures/passive.rb rename to 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 similarity index 100% rename from spec/ruby/library/net/ftp/fixtures/putbinaryfile rename to 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 similarity index 100% rename from spec/ruby/library/net/ftp/fixtures/puttextfile rename to 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 similarity index 100% rename from spec/ruby/library/net/ftp/fixtures/server.rb rename to spec/ruby/library/net-ftp/fixtures/server.rb 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 00000000000..1bc1bd744bb --- /dev/null +++ b/spec/ruby/library/net-ftp/get_spec.rb @@ -0,0 +1,21 @@ +require_relative '../../spec_helper' +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 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 00000000000..e9898fccc7c --- /dev/null +++ b/spec/ruby/library/net-ftp/getbinaryfile_spec.rb @@ -0,0 +1,8 @@ +require_relative '../../spec_helper' +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 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 00000000000..756d6a23af0 --- /dev/null +++ b/spec/ruby/library/net-ftp/getdir_spec.rb @@ -0,0 +1,7 @@ +require_relative '../../spec_helper' +require_relative 'spec_helper' +require_relative 'shared/pwd' + +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 new file mode 100644 index 00000000000..cdd1b4c797b --- /dev/null +++ b/spec/ruby/library/net-ftp/gettextfile_spec.rb @@ -0,0 +1,8 @@ +require_relative '../../spec_helper' +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 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 00000000000..c562be50b2b --- /dev/null +++ b/spec/ruby/library/net-ftp/help_spec.rb @@ -0,0 +1,66 @@ +require_relative '../../spec_helper' +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_error + 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_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.") + -> { @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.") + -> { @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.") + -> { @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.") + -> { @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 new file mode 100644 index 00000000000..4d775e8dc12 --- /dev/null +++ b/spec/ruby/library/net-ftp/initialize_spec.rb @@ -0,0 +1,405 @@ +require_relative '../../spec_helper' +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.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 + + before :each do + @ftp.stub!(:login) + end + + describe 'when the host' do + describe 'is set' do + describe 'and port option' do + describe 'is set' do + it 'tries to connect to the host on the specified port' do + options = mock('ftp initialize options') + options.should_receive(:to_hash).and_return({ port: 8080 }) + @ftp.should_receive(:connect).with('localhost', 8080) + + @ftp.send(:initialize, 'localhost', options) + end + end + + describe 'is not set' do + it 'tries to connect to the host without a port' do + @ftp.should_receive(:connect).with("localhost", *@port_args) + + @ftp.send(:initialize, 'localhost') + end + end + end + + describe 'when the username option' do + describe 'is set' do + describe 'and the password option' do + describe 'is set' do + describe 'and the account option' do + describe 'is set' do + it 'tries to log in with the supplied parameters' do + options = mock('ftp initialize options') + options.should_receive(:to_hash).and_return({ username: 'a', password: 'topsecret', account: 'b' }) + @ftp.should_receive(:login).with('a', 'topsecret', 'b') + + @ftp.send(:initialize, 'localhost', options) + end + end + + describe 'is unset' do + it 'tries to log in with the supplied parameters' do + options = mock('ftp initialize options') + options.should_receive(:to_hash).and_return({ username: 'a', password: 'topsecret' }) + @ftp.should_receive(:login).with('a', 'topsecret', nil) + + @ftp.send(:initialize, 'localhost', options) + end + end + end + end + + describe 'is unset' do + describe 'and the account option' do + describe 'is set' do + it 'tries to log in with the supplied parameters' do + options = mock('ftp initialize options') + options.should_receive(:to_hash).and_return({ username: 'a', account: 'b' }) + @ftp.should_receive(:login).with('a', nil, 'b') + + @ftp.send(:initialize, 'localhost', options) + end + end + + describe 'is unset' do + it 'tries to log in with the supplied parameters' do + options = mock('ftp initialize options') + options.should_receive(:to_hash).and_return({ username: 'a'}) + @ftp.should_receive(:login).with('a', nil, nil) + + @ftp.send(:initialize, 'localhost', options) + end + end + end + end + end + end + + describe 'is not set' do + it 'does not try to log in' do + options = mock('ftp initialize options') + options.should_receive(:to_hash).and_return({}) + @ftp.should_not_receive(:login) + + @ftp.send(:initialize, 'localhost', options) + end + end + end + end + + describe 'is unset' do + it 'does not try to connect' do + @ftp.should_not_receive(:connect) + + @ftp.send(:initialize) + end + + it 'does not try to log in' do + @ftp.should_not_receive(:login) + + @ftp.send(:initialize) + end + end + end + + describe 'when the passive option' do + describe 'is set' do + describe 'to true' do + it 'sets passive to true' do + options = mock('ftp initialize options') + options.should_receive(:to_hash).and_return({ passive: true }) + + @ftp.send(:initialize, nil, options) + @ftp.passive.should == true + end + end + + describe 'to false' do + it 'sets passive to false' do + options = mock('ftp initialize options') + options.should_receive(:to_hash).and_return({ passive: false }) + + @ftp.send(:initialize, nil, options) + @ftp.passive.should == false + end + end + end + + describe 'is unset' do + it 'sets passive to false' do + @ftp.send(:initialize) + @ftp.passive.should == false + end + end + end + + describe 'when the debug_mode option' do + describe 'is set' do + describe 'to true' do + it 'sets debug_mode to true' do + options = mock('ftp initialize options') + options.should_receive(:to_hash).and_return({ debug_mode: true }) + + @ftp.send(:initialize, nil, options) + @ftp.debug_mode.should == true + end + end + + describe 'to false' do + it 'sets debug_mode to false' do + options = mock('ftp initialize options') + options.should_receive(:to_hash).and_return({ debug_mode: false }) + + @ftp.send(:initialize, nil, options) + @ftp.debug_mode.should == false + end + end + end + + describe 'is unset' do + it 'sets debug_mode to false' do + @ftp.send(:initialize) + @ftp.debug_mode.should == false + end + end + end + + describe 'when the open_timeout option' do + describe 'is set' do + it 'sets open_timeout to the specified value' do + options = mock('ftp initialize options') + options.should_receive(:to_hash).and_return({ open_timeout: 42 }) + + @ftp.send(:initialize, nil, options) + @ftp.open_timeout.should == 42 + end + end + + describe 'is not set' do + it 'sets open_timeout to nil' do + @ftp.send(:initialize) + @ftp.open_timeout.should == nil + end + end + end + + describe 'when the read_timeout option' do + describe 'is set' do + it 'sets read_timeout to the specified value' do + options = mock('ftp initialize options') + options.should_receive(:to_hash).and_return({ read_timeout: 100 }) + + @ftp.send(:initialize, nil, options) + @ftp.read_timeout.should == 100 + end + end + + describe 'is not set' do + it 'sets read_timeout to the default value' do + @ftp.send(:initialize) + @ftp.read_timeout.should == 60 + end + end + end + + describe 'when the ssl_handshake_timeout option' do + describe 'is set' do + it 'sets ssl_handshake_timeout to the specified value' do + options = mock('ftp initialize options') + options.should_receive(:to_hash).and_return({ ssl_handshake_timeout: 23 }) + + @ftp.send(:initialize, nil, options) + @ftp.ssl_handshake_timeout.should == 23 + end + end + + describe 'is not set' do + it 'sets ssl_handshake_timeout to nil' do + @ftp.send(:initialize) + @ftp.ssl_handshake_timeout.should == nil + end + end + end + + describe 'when the ssl option' do + describe 'is set' do + describe "and the ssl option's value is true" do + it 'initializes ssl_context to a blank SSLContext object' do + options = mock('ftp initialize options') + options.should_receive(:to_hash).and_return({ ssl: true }) + + ssl_context = OpenSSL::SSL::SSLContext.allocate + ssl_context.stub!(:set_params) + + OpenSSL::SSL::SSLContext.should_receive(:new).and_return(ssl_context) + ssl_context.should_receive(:set_params).with({}) + + @ftp.send(:initialize, nil, options) + @ftp.instance_variable_get(:@ssl_context).should == ssl_context + end + end + + describe "and the ssl option's value is a hash" do + it 'initializes ssl_context to a configured SSLContext object' do + options = mock('ftp initialize options') + options.should_receive(:to_hash).and_return({ ssl: {key: 'value'} }) + + ssl_context = OpenSSL::SSL::SSLContext.allocate + ssl_context.stub!(:set_params) + + OpenSSL::SSL::SSLContext.should_receive(:new).and_return(ssl_context) + ssl_context.should_receive(:set_params).with({key: 'value'}) + + @ftp.send(:initialize, nil, options) + @ftp.instance_variable_get(:@ssl_context).should == ssl_context + end + end + + describe 'and private_data_connection' do + describe 'is set' do + it 'sets private_data_connection to that value' do + options = mock('ftp initialize options') + options.should_receive(:to_hash).and_return({ ssl: true, private_data_connection: 'true' }) + + @ftp.send(:initialize, nil, options) + @ftp.instance_variable_get(:@private_data_connection).should == 'true' + end + end + + describe 'is not set' do + it 'sets private_data_connection to nil' do + options = mock('ftp initialize options') + options.should_receive(:to_hash).and_return({ ssl: true }) + + @ftp.send(:initialize, nil, options) + @ftp.instance_variable_get(:@private_data_connection).should == true + end + end + end + end + + describe 'is not set' do + it 'sets ssl_context to nil' do + options = mock('ftp initialize options') + options.should_receive(:to_hash).and_return({}) + + @ftp.send(:initialize, nil, options) + @ftp.instance_variable_get(:@ssl_context).should == nil + end + + describe 'private_data_connection' do + describe 'is set' do + it 'raises an ArgumentError' do + options = mock('ftp initialize options') + options.should_receive(:to_hash).and_return({ private_data_connection: true }) + + -> { + @ftp.send(:initialize, nil, options) + }.should raise_error(ArgumentError, /private_data_connection can be set to true only when ssl is enabled/) + end + end + + describe 'is not set' do + it 'sets private_data_connection to false' do + options = mock('ftp initialize options') + options.should_receive(:to_hash).and_return({}) + + @ftp.send(:initialize, nil, options) + @ftp.instance_variable_get(:@private_data_connection).should == false + end + end + end + end + end +end 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 00000000000..c17c28f0f8d --- /dev/null +++ b/spec/ruby/library/net-ftp/last_response_code_spec.rb @@ -0,0 +1,8 @@ +require_relative '../../spec_helper' +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 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 00000000000..c9d9d70f35a --- /dev/null +++ b/spec/ruby/library/net-ftp/last_response_spec.rb @@ -0,0 +1,25 @@ +require_relative '../../spec_helper' +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 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 00000000000..e0c1b862a05 --- /dev/null +++ b/spec/ruby/library/net-ftp/lastresp_spec.rb @@ -0,0 +1,8 @@ +require_relative '../../spec_helper' +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 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 00000000000..6cb1bbc4b8e --- /dev/null +++ b/spec/ruby/library/net-ftp/list_spec.rb @@ -0,0 +1,8 @@ +require_relative '../../spec_helper' +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 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 00000000000..0de2f5cc630 --- /dev/null +++ b/spec/ruby/library/net-ftp/login_spec.rb @@ -0,0 +1,195 @@ +require_relative '../../spec_helper' +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_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.") + -> { @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.") + -> { @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.") + -> { @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.") + -> { @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.") + -> { @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.") + -> { @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.") + -> { @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.") + -> { @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.") + -> { @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.") + -> { @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.") + -> { @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.") + -> { @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.") + -> { @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.") + -> { @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.") + -> { @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.") + -> { @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.") + -> { @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.") + -> { @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.") + -> { @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.") + -> { @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 new file mode 100644 index 00000000000..acd7e9e5236 --- /dev/null +++ b/spec/ruby/library/net-ftp/ls_spec.rb @@ -0,0 +1,8 @@ +require_relative '../../spec_helper' +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 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 00000000000..a504507c84e --- /dev/null +++ b/spec/ruby/library/net-ftp/mdtm_spec.rb @@ -0,0 +1,38 @@ +require_relative '../../spec_helper' +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_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.") + -> { @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 new file mode 100644 index 00000000000..8cc6ae785e6 --- /dev/null +++ b/spec/ruby/library/net-ftp/mkdir_spec.rb @@ -0,0 +1,61 @@ +require_relative '../../spec_helper' +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_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.") + -> { @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.") + -> { @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.") + -> { @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.") + -> { @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.") + -> { @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 new file mode 100644 index 00000000000..9dde1278a84 --- /dev/null +++ b/spec/ruby/library/net-ftp/mtime_spec.rb @@ -0,0 +1,50 @@ +require_relative '../../spec_helper' +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_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.") + -> { @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 new file mode 100644 index 00000000000..2f22543af61 --- /dev/null +++ b/spec/ruby/library/net-ftp/nlst_spec.rb @@ -0,0 +1,92 @@ +require_relative '../../spec_helper' +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_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.") + -> { @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.") + -> { @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.") + -> { @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.") + -> { @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.") + -> { @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.") + -> { @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.") + -> { @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.") + -> { @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.") + -> { @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 new file mode 100644 index 00000000000..4743a39ef68 --- /dev/null +++ b/spec/ruby/library/net-ftp/noop_spec.rb @@ -0,0 +1,38 @@ +require_relative '../../spec_helper' +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 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.") + -> { @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.") + -> { @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 new file mode 100644 index 00000000000..e59496dc3cf --- /dev/null +++ b/spec/ruby/library/net-ftp/open_spec.rb @@ -0,0 +1,55 @@ +require_relative '../../spec_helper' +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 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 new file mode 100644 index 00000000000..97659f1b685 --- /dev/null +++ b/spec/ruby/library/net-ftp/passive_spec.rb @@ -0,0 +1,28 @@ +require_relative '../../spec_helper' +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 be_false + + ftp.passive = true + ftp.passive.should be_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 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 new file mode 100644 index 00000000000..6d40d3d5b99 --- /dev/null +++ b/spec/ruby/library/net-ftp/put_spec.rb @@ -0,0 +1,21 @@ +require_relative '../../spec_helper' +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 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 00000000000..d0398229e56 --- /dev/null +++ b/spec/ruby/library/net-ftp/putbinaryfile_spec.rb @@ -0,0 +1,8 @@ +require_relative '../../spec_helper' +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 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 00000000000..b8bcac33df6 --- /dev/null +++ b/spec/ruby/library/net-ftp/puttextfile_spec.rb @@ -0,0 +1,8 @@ +require_relative '../../spec_helper' +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 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 00000000000..992e2c4ed24 --- /dev/null +++ b/spec/ruby/library/net-ftp/pwd_spec.rb @@ -0,0 +1,53 @@ +require_relative '../../spec_helper' +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_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.") + -> { @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.") + -> { @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.") + -> { @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.") + -> { @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 new file mode 100644 index 00000000000..c5352ceadab --- /dev/null +++ b/spec/ruby/library/net-ftp/quit_spec.rb @@ -0,0 +1,33 @@ +require_relative '../../spec_helper' +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 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 new file mode 100644 index 00000000000..48f81b7debf --- /dev/null +++ b/spec/ruby/library/net-ftp/rename_spec.rb @@ -0,0 +1,94 @@ +require_relative '../../spec_helper' +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 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.") + -> { @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.") + -> { @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.") + -> { @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.") + -> { @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.") + -> { @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.") + -> { @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.") + -> { @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.") + -> { @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.") + -> { @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.") + -> { @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.") + -> { @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.") + -> { @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 new file mode 100644 index 00000000000..6592fc5bb03 --- /dev/null +++ b/spec/ruby/library/net-ftp/resume_spec.rb @@ -0,0 +1,23 @@ +require_relative '../../spec_helper' +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 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 new file mode 100644 index 00000000000..de024208aa4 --- /dev/null +++ b/spec/ruby/library/net-ftp/retrbinary_spec.rb @@ -0,0 +1,30 @@ +require_relative '../../spec_helper' +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 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 00000000000..866ecb5f409 --- /dev/null +++ b/spec/ruby/library/net-ftp/retrlines_spec.rb @@ -0,0 +1,34 @@ +require_relative '../../spec_helper' +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 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 00000000000..35a6232f7ee --- /dev/null +++ b/spec/ruby/library/net-ftp/return_code_spec.rb @@ -0,0 +1,24 @@ +require_relative '../../spec_helper' +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 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 00000000000..400874d60db --- /dev/null +++ b/spec/ruby/library/net-ftp/rmdir_spec.rb @@ -0,0 +1,58 @@ +require_relative '../../spec_helper' +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 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.") + -> { @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.") + -> { @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.") + -> { @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.") + -> { @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.") + -> { @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.") + -> { @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 new file mode 100644 index 00000000000..c50b373869d --- /dev/null +++ b/spec/ruby/library/net-ftp/sendcmd_spec.rb @@ -0,0 +1,54 @@ +require_relative '../../spec_helper' +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_error + + @server.should_receive(:help).and_respond("200 Command okay.") + -> { @ftp.sendcmd("HELP") }.should_not raise_error + + @server.should_receive(:help).and_respond("350 Requested file action pending further information.") + -> { @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.") + -> { @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.") + -> { @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.") + -> { @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 new file mode 100644 index 00000000000..8182dd8b338 --- /dev/null +++ b/spec/ruby/library/net-ftp/set_socket_spec.rb @@ -0,0 +1,8 @@ +require_relative '../../spec_helper' +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 diff --git a/spec/ruby/library/net/ftp/shared/getbinaryfile.rb b/spec/ruby/library/net-ftp/shared/getbinaryfile.rb similarity index 100% rename from spec/ruby/library/net/ftp/shared/getbinaryfile.rb rename to spec/ruby/library/net-ftp/shared/getbinaryfile.rb diff --git a/spec/ruby/library/net/ftp/shared/gettextfile.rb b/spec/ruby/library/net-ftp/shared/gettextfile.rb similarity index 100% rename from spec/ruby/library/net/ftp/shared/gettextfile.rb rename to spec/ruby/library/net-ftp/shared/gettextfile.rb diff --git a/spec/ruby/library/net/ftp/shared/last_response_code.rb b/spec/ruby/library/net-ftp/shared/last_response_code.rb similarity index 100% rename from spec/ruby/library/net/ftp/shared/last_response_code.rb rename to spec/ruby/library/net-ftp/shared/last_response_code.rb diff --git a/spec/ruby/library/net/ftp/shared/list.rb b/spec/ruby/library/net-ftp/shared/list.rb similarity index 100% rename from spec/ruby/library/net/ftp/shared/list.rb rename to spec/ruby/library/net-ftp/shared/list.rb diff --git a/spec/ruby/library/net/ftp/shared/putbinaryfile.rb b/spec/ruby/library/net-ftp/shared/putbinaryfile.rb similarity index 100% rename from spec/ruby/library/net/ftp/shared/putbinaryfile.rb rename to spec/ruby/library/net-ftp/shared/putbinaryfile.rb diff --git a/spec/ruby/library/net/ftp/shared/puttextfile.rb b/spec/ruby/library/net-ftp/shared/puttextfile.rb similarity index 100% rename from spec/ruby/library/net/ftp/shared/puttextfile.rb rename to spec/ruby/library/net-ftp/shared/puttextfile.rb diff --git a/spec/ruby/library/net/ftp/shared/pwd.rb b/spec/ruby/library/net-ftp/shared/pwd.rb similarity index 100% rename from spec/ruby/library/net/ftp/shared/pwd.rb rename to spec/ruby/library/net-ftp/shared/pwd.rb 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 00000000000..c3e589a9204 --- /dev/null +++ b/spec/ruby/library/net-ftp/site_spec.rb @@ -0,0 +1,53 @@ +require_relative '../../spec_helper' +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 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.") + -> { @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.") + -> { @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.") + -> { @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.") + -> { @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.") + -> { @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 new file mode 100644 index 00000000000..0cf2e244773 --- /dev/null +++ b/spec/ruby/library/net-ftp/size_spec.rb @@ -0,0 +1,48 @@ +require_relative '../../spec_helper' +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_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.") + -> { @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.") + -> { @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.") + -> { @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 similarity index 100% rename from spec/ruby/library/net/ftp/spec_helper.rb rename to spec/ruby/library/net-ftp/spec_helper.rb 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 00000000000..9d9f86c3816 --- /dev/null +++ b/spec/ruby/library/net-ftp/status_spec.rb @@ -0,0 +1,67 @@ +require_relative '../../spec_helper' +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_error + 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_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.") + -> { @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.") + -> { @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.") + -> { @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.") + -> { @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.") + -> { @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 new file mode 100644 index 00000000000..aa4c51f2e81 --- /dev/null +++ b/spec/ruby/library/net-ftp/storbinary_spec.rb @@ -0,0 +1,49 @@ +require_relative '../../spec_helper' + +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 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 00000000000..dc6830da7bd --- /dev/null +++ b/spec/ruby/library/net-ftp/storlines_spec.rb @@ -0,0 +1,44 @@ +require_relative '../../spec_helper' + +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 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 00000000000..2b7f0d2560b --- /dev/null +++ b/spec/ruby/library/net-ftp/system_spec.rb @@ -0,0 +1,48 @@ +require_relative '../../spec_helper' +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_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.") + -> { @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.") + -> { @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.") + -> { @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 new file mode 100644 index 00000000000..f2536fe697b --- /dev/null +++ b/spec/ruby/library/net-ftp/voidcmd_spec.rb @@ -0,0 +1,54 @@ +require_relative '../../spec_helper' +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_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.") + -> { @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.") + -> { @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.") + -> { @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.") + -> { @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.") + -> { @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 new file mode 100644 index 00000000000..4279127ce34 --- /dev/null +++ b/spec/ruby/library/net-ftp/welcome_spec.rb @@ -0,0 +1,25 @@ +require_relative '../../spec_helper' +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 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 similarity index 79% rename from spec/ruby/library/net/http/HTTPBadResponse_spec.rb rename to spec/ruby/library/net-http/HTTPBadResponse_spec.rb index be644968f56..8f2e8ccfafc 100644 --- a/spec/ruby/library/net/http/HTTPBadResponse_spec.rb +++ b/spec/ruby/library/net-http/HTTPBadResponse_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../spec_helper' +require_relative '../../spec_helper' require 'net/http' describe "Net::HTTPBadResponse" do diff --git a/spec/ruby/library/net/http/HTTPClientExcepton_spec.rb b/spec/ruby/library/net-http/HTTPClientExcepton_spec.rb similarity index 87% rename from spec/ruby/library/net/http/HTTPClientExcepton_spec.rb rename to spec/ruby/library/net-http/HTTPClientExcepton_spec.rb index d576349a571..2992e6596fc 100644 --- a/spec/ruby/library/net/http/HTTPClientExcepton_spec.rb +++ b/spec/ruby/library/net-http/HTTPClientExcepton_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../spec_helper' +require_relative '../../spec_helper' require 'net/http' describe "Net::HTTPClientException" do diff --git a/spec/ruby/library/net/http/HTTPError_spec.rb b/spec/ruby/library/net-http/HTTPError_spec.rb similarity index 86% rename from spec/ruby/library/net/http/HTTPError_spec.rb rename to spec/ruby/library/net-http/HTTPError_spec.rb index ab5f491bb7f..7f79eef8cf7 100644 --- a/spec/ruby/library/net/http/HTTPError_spec.rb +++ b/spec/ruby/library/net-http/HTTPError_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../spec_helper' +require_relative '../../spec_helper' require 'net/http' describe "Net::HTTPError" do diff --git a/spec/ruby/library/net/http/HTTPFatalError_spec.rb b/spec/ruby/library/net-http/HTTPFatalError_spec.rb similarity index 87% rename from spec/ruby/library/net/http/HTTPFatalError_spec.rb rename to spec/ruby/library/net-http/HTTPFatalError_spec.rb index 6ab36bff6c4..0113b9da2de 100644 --- a/spec/ruby/library/net/http/HTTPFatalError_spec.rb +++ b/spec/ruby/library/net-http/HTTPFatalError_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../spec_helper' +require_relative '../../spec_helper' require 'net/http' describe "Net::HTTPFatalError" do diff --git a/spec/ruby/library/net/http/HTTPHeaderSyntaxError_spec.rb b/spec/ruby/library/net-http/HTTPHeaderSyntaxError_spec.rb similarity index 80% rename from spec/ruby/library/net/http/HTTPHeaderSyntaxError_spec.rb rename to spec/ruby/library/net-http/HTTPHeaderSyntaxError_spec.rb index 38e9454f990..b3b73ff46f0 100644 --- a/spec/ruby/library/net/http/HTTPHeaderSyntaxError_spec.rb +++ b/spec/ruby/library/net-http/HTTPHeaderSyntaxError_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../spec_helper' +require_relative '../../spec_helper' require 'net/http' describe "Net::HTTPHeaderSyntaxError" do diff --git a/spec/ruby/library/net/http/HTTPRetriableError_spec.rb b/spec/ruby/library/net-http/HTTPRetriableError_spec.rb similarity index 88% rename from spec/ruby/library/net/http/HTTPRetriableError_spec.rb rename to spec/ruby/library/net-http/HTTPRetriableError_spec.rb index 3a4bb9146c9..677731fb683 100644 --- a/spec/ruby/library/net/http/HTTPRetriableError_spec.rb +++ b/spec/ruby/library/net-http/HTTPRetriableError_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../spec_helper' +require_relative '../../spec_helper' require 'net/http' describe "Net::HTTPRetriableError" do diff --git a/spec/ruby/library/net/http/HTTPServerException_spec.rb b/spec/ruby/library/net-http/HTTPServerException_spec.rb similarity index 92% rename from spec/ruby/library/net/http/HTTPServerException_spec.rb rename to spec/ruby/library/net-http/HTTPServerException_spec.rb index 23b06573649..5e0a833feeb 100644 --- a/spec/ruby/library/net/http/HTTPServerException_spec.rb +++ b/spec/ruby/library/net-http/HTTPServerException_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../spec_helper' +require_relative '../../spec_helper' require 'net/http' describe "Net::HTTPServerException" do diff --git a/spec/ruby/library/net/http/http/Proxy_spec.rb b/spec/ruby/library/net-http/http/Proxy_spec.rb similarity index 96% rename from spec/ruby/library/net/http/http/Proxy_spec.rb rename to spec/ruby/library/net-http/http/Proxy_spec.rb index f85ccc0ee9a..a1a04fa00ba 100644 --- a/spec/ruby/library/net/http/http/Proxy_spec.rb +++ b/spec/ruby/library/net-http/http/Proxy_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTP.Proxy" do diff --git a/spec/ruby/library/net/http/http/active_spec.rb b/spec/ruby/library/net-http/http/active_spec.rb similarity index 80% rename from spec/ruby/library/net/http/http/active_spec.rb rename to spec/ruby/library/net-http/http/active_spec.rb index ef657243bae..c2602745949 100644 --- a/spec/ruby/library/net/http/http/active_spec.rb +++ b/spec/ruby/library/net-http/http/active_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/http_server' require_relative 'shared/started' diff --git a/spec/ruby/library/net/http/http/address_spec.rb b/spec/ruby/library/net-http/http/address_spec.rb similarity index 80% rename from spec/ruby/library/net/http/http/address_spec.rb rename to spec/ruby/library/net-http/http/address_spec.rb index 5fce76d7673..7c5b82a8f96 100644 --- a/spec/ruby/library/net/http/http/address_spec.rb +++ b/spec/ruby/library/net-http/http/address_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTP#address" do 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 similarity index 84% rename from spec/ruby/library/net/http/http/close_on_empty_response_spec.rb rename to spec/ruby/library/net-http/http/close_on_empty_response_spec.rb index a97b7b6c434..9cc756befbe 100644 --- 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 @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTP#close_on_empty_response" do diff --git a/spec/ruby/library/net/http/http/copy_spec.rb b/spec/ruby/library/net-http/http/copy_spec.rb similarity index 92% rename from spec/ruby/library/net/http/http/copy_spec.rb rename to spec/ruby/library/net-http/http/copy_spec.rb index 5ebfdc334e8..fba96c0f11c 100644 --- a/spec/ruby/library/net/http/http/copy_spec.rb +++ b/spec/ruby/library/net-http/http/copy_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/http_server' diff --git a/spec/ruby/library/net/http/http/default_port_spec.rb b/spec/ruby/library/net-http/http/default_port_spec.rb similarity index 75% rename from spec/ruby/library/net/http/http/default_port_spec.rb rename to spec/ruby/library/net-http/http/default_port_spec.rb index 30db18efaee..95b7316a0cf 100644 --- a/spec/ruby/library/net/http/http/default_port_spec.rb +++ b/spec/ruby/library/net-http/http/default_port_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTP.default_port" do diff --git a/spec/ruby/library/net/http/http/delete_spec.rb b/spec/ruby/library/net-http/http/delete_spec.rb similarity index 92% rename from spec/ruby/library/net/http/http/delete_spec.rb rename to spec/ruby/library/net-http/http/delete_spec.rb index 160c6531158..d73aa5b375a 100644 --- a/spec/ruby/library/net/http/http/delete_spec.rb +++ b/spec/ruby/library/net-http/http/delete_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/http_server' diff --git a/spec/ruby/library/net/http/http/finish_spec.rb b/spec/ruby/library/net-http/http/finish_spec.rb similarity index 93% rename from spec/ruby/library/net/http/http/finish_spec.rb rename to spec/ruby/library/net-http/http/finish_spec.rb index f98bc7be138..d4aa00dffe1 100644 --- a/spec/ruby/library/net/http/http/finish_spec.rb +++ b/spec/ruby/library/net-http/http/finish_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/http_server' diff --git a/spec/ruby/library/net/http/http/fixtures/http_server.rb b/spec/ruby/library/net-http/http/fixtures/http_server.rb similarity index 100% rename from spec/ruby/library/net/http/http/fixtures/http_server.rb rename to spec/ruby/library/net-http/http/fixtures/http_server.rb diff --git a/spec/ruby/library/net/http/http/get2_spec.rb b/spec/ruby/library/net-http/http/get2_spec.rb similarity index 80% rename from spec/ruby/library/net/http/http/get2_spec.rb rename to spec/ruby/library/net-http/http/get2_spec.rb index 519e4c2599b..57c05ec64b8 100644 --- a/spec/ruby/library/net/http/http/get2_spec.rb +++ b/spec/ruby/library/net-http/http/get2_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/http_server' require_relative 'shared/request_get' diff --git a/spec/ruby/library/net/http/http/get_print_spec.rb b/spec/ruby/library/net-http/http/get_print_spec.rb similarity index 94% rename from spec/ruby/library/net/http/http/get_print_spec.rb rename to spec/ruby/library/net-http/http/get_print_spec.rb index f59dd68c818..3c24ce44ea5 100644 --- a/spec/ruby/library/net/http/http/get_print_spec.rb +++ b/spec/ruby/library/net-http/http/get_print_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/http_server' diff --git a/spec/ruby/library/net/http/http/get_response_spec.rb b/spec/ruby/library/net-http/http/get_response_spec.rb similarity index 94% rename from spec/ruby/library/net/http/http/get_response_spec.rb rename to spec/ruby/library/net-http/http/get_response_spec.rb index 941b35e773b..7133ef81014 100644 --- a/spec/ruby/library/net/http/http/get_response_spec.rb +++ b/spec/ruby/library/net-http/http/get_response_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/http_server' diff --git a/spec/ruby/library/net/http/http/get_spec.rb b/spec/ruby/library/net-http/http/get_spec.rb similarity index 98% rename from spec/ruby/library/net/http/http/get_spec.rb rename to spec/ruby/library/net-http/http/get_spec.rb index a3b62e37541..e64a61c52cf 100644 --- a/spec/ruby/library/net/http/http/get_spec.rb +++ b/spec/ruby/library/net-http/http/get_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/http_server' diff --git a/spec/ruby/library/net/http/http/head2_spec.rb b/spec/ruby/library/net-http/http/head2_spec.rb similarity index 80% rename from spec/ruby/library/net/http/http/head2_spec.rb rename to spec/ruby/library/net-http/http/head2_spec.rb index 6958204ee1c..84cfff33d7c 100644 --- a/spec/ruby/library/net/http/http/head2_spec.rb +++ b/spec/ruby/library/net-http/http/head2_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/http_server' require_relative 'shared/request_head' diff --git a/spec/ruby/library/net/http/http/head_spec.rb b/spec/ruby/library/net-http/http/head_spec.rb similarity index 93% rename from spec/ruby/library/net/http/http/head_spec.rb rename to spec/ruby/library/net-http/http/head_spec.rb index 925a8e60436..64621fa87b5 100644 --- a/spec/ruby/library/net/http/http/head_spec.rb +++ b/spec/ruby/library/net-http/http/head_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/http_server' 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 similarity index 76% rename from spec/ruby/library/net/http/http/http_default_port_spec.rb rename to spec/ruby/library/net-http/http/http_default_port_spec.rb index cf7f73e630b..3b17bcd0a5c 100644 --- a/spec/ruby/library/net/http/http/http_default_port_spec.rb +++ b/spec/ruby/library/net-http/http/http_default_port_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTP.http_default_port" do 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 similarity index 77% rename from spec/ruby/library/net/http/http/https_default_port_spec.rb rename to spec/ruby/library/net-http/http/https_default_port_spec.rb index fbf0bd1abc5..8c24e1d97cd 100644 --- a/spec/ruby/library/net/http/http/https_default_port_spec.rb +++ b/spec/ruby/library/net-http/http/https_default_port_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTP.https_default_port" do diff --git a/spec/ruby/library/net/http/http/initialize_spec.rb b/spec/ruby/library/net-http/http/initialize_spec.rb similarity index 96% rename from spec/ruby/library/net/http/http/initialize_spec.rb rename to spec/ruby/library/net-http/http/initialize_spec.rb index 7683713a0ed..78aa01e1aae 100644 --- a/spec/ruby/library/net/http/http/initialize_spec.rb +++ b/spec/ruby/library/net-http/http/initialize_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTP#initialize" do diff --git a/spec/ruby/library/net/http/http/inspect_spec.rb b/spec/ruby/library/net-http/http/inspect_spec.rb similarity index 93% rename from spec/ruby/library/net/http/http/inspect_spec.rb rename to spec/ruby/library/net-http/http/inspect_spec.rb index b1e799ca345..b8f650809e3 100644 --- a/spec/ruby/library/net/http/http/inspect_spec.rb +++ b/spec/ruby/library/net-http/http/inspect_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/http_server' 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 similarity index 79% rename from spec/ruby/library/net/http/http/is_version_1_1_spec.rb rename to spec/ruby/library/net-http/http/is_version_1_1_spec.rb index f37695b777e..bdb343f9e0e 100644 --- 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 @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'shared/version_1_1' 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 similarity index 79% rename from spec/ruby/library/net/http/http/is_version_1_2_spec.rb rename to spec/ruby/library/net-http/http/is_version_1_2_spec.rb index 82dbdc87aa5..555bb205dd8 100644 --- 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 @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'shared/version_1_2' diff --git a/spec/ruby/library/net/http/http/lock_spec.rb b/spec/ruby/library/net-http/http/lock_spec.rb similarity index 92% rename from spec/ruby/library/net/http/http/lock_spec.rb rename to spec/ruby/library/net-http/http/lock_spec.rb index bb76607a8b2..aa1f944196e 100644 --- a/spec/ruby/library/net/http/http/lock_spec.rb +++ b/spec/ruby/library/net-http/http/lock_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/http_server' diff --git a/spec/ruby/library/net/http/http/mkcol_spec.rb b/spec/ruby/library/net-http/http/mkcol_spec.rb similarity index 92% rename from spec/ruby/library/net/http/http/mkcol_spec.rb rename to spec/ruby/library/net-http/http/mkcol_spec.rb index 33017625e29..f8009f90592 100644 --- a/spec/ruby/library/net/http/http/mkcol_spec.rb +++ b/spec/ruby/library/net-http/http/mkcol_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/http_server' diff --git a/spec/ruby/library/net/http/http/move_spec.rb b/spec/ruby/library/net-http/http/move_spec.rb similarity index 93% rename from spec/ruby/library/net/http/http/move_spec.rb rename to spec/ruby/library/net-http/http/move_spec.rb index 4d6b8281506..ae43016a2cb 100644 --- a/spec/ruby/library/net/http/http/move_spec.rb +++ b/spec/ruby/library/net-http/http/move_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/http_server' diff --git a/spec/ruby/library/net/http/http/new_spec.rb b/spec/ruby/library/net-http/http/new_spec.rb similarity index 98% rename from spec/ruby/library/net/http/http/new_spec.rb rename to spec/ruby/library/net-http/http/new_spec.rb index 491d1d01fdb..1ec6bbd0c04 100644 --- a/spec/ruby/library/net/http/http/new_spec.rb +++ b/spec/ruby/library/net-http/http/new_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTP.new" do diff --git a/spec/ruby/library/net/http/http/newobj_spec.rb b/spec/ruby/library/net-http/http/newobj_spec.rb similarity index 96% rename from spec/ruby/library/net/http/http/newobj_spec.rb rename to spec/ruby/library/net-http/http/newobj_spec.rb index b261dcc5db9..e19b30fca9b 100644 --- a/spec/ruby/library/net/http/http/newobj_spec.rb +++ b/spec/ruby/library/net-http/http/newobj_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTP.newobj" do diff --git a/spec/ruby/library/net/http/http/open_timeout_spec.rb b/spec/ruby/library/net-http/http/open_timeout_spec.rb similarity index 93% rename from spec/ruby/library/net/http/http/open_timeout_spec.rb rename to spec/ruby/library/net-http/http/open_timeout_spec.rb index 44b33615e6c..0d937522718 100644 --- a/spec/ruby/library/net/http/http/open_timeout_spec.rb +++ b/spec/ruby/library/net-http/http/open_timeout_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTP#open_timeout" do diff --git a/spec/ruby/library/net/http/http/options_spec.rb b/spec/ruby/library/net-http/http/options_spec.rb similarity index 93% rename from spec/ruby/library/net/http/http/options_spec.rb rename to spec/ruby/library/net-http/http/options_spec.rb index d798e691975..3d9887a557b 100644 --- a/spec/ruby/library/net/http/http/options_spec.rb +++ b/spec/ruby/library/net-http/http/options_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/http_server' diff --git a/spec/ruby/library/net/http/http/port_spec.rb b/spec/ruby/library/net-http/http/port_spec.rb similarity index 80% rename from spec/ruby/library/net/http/http/port_spec.rb rename to spec/ruby/library/net-http/http/port_spec.rb index 7de295ca757..0984d5e6ce8 100644 --- a/spec/ruby/library/net/http/http/port_spec.rb +++ b/spec/ruby/library/net-http/http/port_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTP#port" do diff --git a/spec/ruby/library/net/http/http/post2_spec.rb b/spec/ruby/library/net-http/http/post2_spec.rb similarity index 80% rename from spec/ruby/library/net/http/http/post2_spec.rb rename to spec/ruby/library/net-http/http/post2_spec.rb index ccc95068fba..abc998709fe 100644 --- a/spec/ruby/library/net/http/http/post2_spec.rb +++ b/spec/ruby/library/net-http/http/post2_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/http_server' require_relative 'shared/request_post' diff --git a/spec/ruby/library/net/http/http/post_form_spec.rb b/spec/ruby/library/net-http/http/post_form_spec.rb similarity index 91% rename from spec/ruby/library/net/http/http/post_form_spec.rb rename to spec/ruby/library/net-http/http/post_form_spec.rb index 891e05e7af4..de64a25bae7 100644 --- a/spec/ruby/library/net/http/http/post_form_spec.rb +++ b/spec/ruby/library/net-http/http/post_form_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/http_server' diff --git a/spec/ruby/library/net/http/http/post_spec.rb b/spec/ruby/library/net-http/http/post_spec.rb similarity index 98% rename from spec/ruby/library/net/http/http/post_spec.rb rename to spec/ruby/library/net-http/http/post_spec.rb index 891e20aaca3..9e7574015c6 100644 --- a/spec/ruby/library/net/http/http/post_spec.rb +++ b/spec/ruby/library/net-http/http/post_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require 'uri' require_relative 'fixtures/http_server' diff --git a/spec/ruby/library/net/http/http/propfind_spec.rb b/spec/ruby/library/net-http/http/propfind_spec.rb similarity index 93% rename from spec/ruby/library/net/http/http/propfind_spec.rb rename to spec/ruby/library/net-http/http/propfind_spec.rb index 52401716180..f3742d1b1ae 100644 --- a/spec/ruby/library/net/http/http/propfind_spec.rb +++ b/spec/ruby/library/net-http/http/propfind_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/http_server' diff --git a/spec/ruby/library/net/http/http/proppatch_spec.rb b/spec/ruby/library/net-http/http/proppatch_spec.rb similarity index 93% rename from spec/ruby/library/net/http/http/proppatch_spec.rb rename to spec/ruby/library/net-http/http/proppatch_spec.rb index 7a761a9f234..0163d24d46a 100644 --- a/spec/ruby/library/net/http/http/proppatch_spec.rb +++ b/spec/ruby/library/net-http/http/proppatch_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/http_server' diff --git a/spec/ruby/library/net/http/http/proxy_address_spec.rb b/spec/ruby/library/net-http/http/proxy_address_spec.rb similarity index 95% rename from spec/ruby/library/net/http/http/proxy_address_spec.rb rename to spec/ruby/library/net-http/http/proxy_address_spec.rb index 8d152b8d448..5b5efb7ac00 100644 --- a/spec/ruby/library/net/http/http/proxy_address_spec.rb +++ b/spec/ruby/library/net-http/http/proxy_address_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTP.proxy_address" do diff --git a/spec/ruby/library/net/http/http/proxy_class_spec.rb b/spec/ruby/library/net-http/http/proxy_class_spec.rb similarity index 84% rename from spec/ruby/library/net/http/http/proxy_class_spec.rb rename to spec/ruby/library/net-http/http/proxy_class_spec.rb index 2d32a39f013..00975aef4ec 100644 --- a/spec/ruby/library/net/http/http/proxy_class_spec.rb +++ b/spec/ruby/library/net-http/http/proxy_class_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTP.proxy_class?" do diff --git a/spec/ruby/library/net/http/http/proxy_pass_spec.rb b/spec/ruby/library/net-http/http/proxy_pass_spec.rb similarity index 96% rename from spec/ruby/library/net/http/http/proxy_pass_spec.rb rename to spec/ruby/library/net-http/http/proxy_pass_spec.rb index 94a00345445..4e393a53ff8 100644 --- a/spec/ruby/library/net/http/http/proxy_pass_spec.rb +++ b/spec/ruby/library/net-http/http/proxy_pass_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTP.proxy_pass" do diff --git a/spec/ruby/library/net/http/http/proxy_port_spec.rb b/spec/ruby/library/net-http/http/proxy_port_spec.rb similarity index 96% rename from spec/ruby/library/net/http/http/proxy_port_spec.rb rename to spec/ruby/library/net-http/http/proxy_port_spec.rb index 339f7ee850a..d7d37f39273 100644 --- a/spec/ruby/library/net/http/http/proxy_port_spec.rb +++ b/spec/ruby/library/net-http/http/proxy_port_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTP.proxy_port" do diff --git a/spec/ruby/library/net/http/http/proxy_user_spec.rb b/spec/ruby/library/net-http/http/proxy_user_spec.rb similarity index 96% rename from spec/ruby/library/net/http/http/proxy_user_spec.rb rename to spec/ruby/library/net-http/http/proxy_user_spec.rb index 01fda400e9e..ef7654425de 100644 --- a/spec/ruby/library/net/http/http/proxy_user_spec.rb +++ b/spec/ruby/library/net-http/http/proxy_user_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTP.proxy_user" do diff --git a/spec/ruby/library/net/http/http/put2_spec.rb b/spec/ruby/library/net-http/http/put2_spec.rb similarity index 80% rename from spec/ruby/library/net/http/http/put2_spec.rb rename to spec/ruby/library/net-http/http/put2_spec.rb index 99329a5fd96..7b03a39d0b8 100644 --- a/spec/ruby/library/net/http/http/put2_spec.rb +++ b/spec/ruby/library/net-http/http/put2_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/http_server' require_relative 'shared/request_put' diff --git a/spec/ruby/library/net/http/http/put_spec.rb b/spec/ruby/library/net-http/http/put_spec.rb similarity index 93% rename from spec/ruby/library/net/http/http/put_spec.rb rename to spec/ruby/library/net-http/http/put_spec.rb index 3ca0d0963ed..75f3c243d4a 100644 --- a/spec/ruby/library/net/http/http/put_spec.rb +++ b/spec/ruby/library/net-http/http/put_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/http_server' diff --git a/spec/ruby/library/net/http/http/read_timeout_spec.rb b/spec/ruby/library/net-http/http/read_timeout_spec.rb similarity index 93% rename from spec/ruby/library/net/http/http/read_timeout_spec.rb rename to spec/ruby/library/net-http/http/read_timeout_spec.rb index e23ee760259..7a0d2f1d72a 100644 --- a/spec/ruby/library/net/http/http/read_timeout_spec.rb +++ b/spec/ruby/library/net-http/http/read_timeout_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTP#read_timeout" do diff --git a/spec/ruby/library/net/http/http/request_get_spec.rb b/spec/ruby/library/net-http/http/request_get_spec.rb similarity index 81% rename from spec/ruby/library/net/http/http/request_get_spec.rb rename to spec/ruby/library/net-http/http/request_get_spec.rb index 9932ef0beb0..98025a14a18 100644 --- a/spec/ruby/library/net/http/http/request_get_spec.rb +++ b/spec/ruby/library/net-http/http/request_get_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/http_server' require_relative 'shared/request_get' diff --git a/spec/ruby/library/net/http/http/request_head_spec.rb b/spec/ruby/library/net-http/http/request_head_spec.rb similarity index 82% rename from spec/ruby/library/net/http/http/request_head_spec.rb rename to spec/ruby/library/net-http/http/request_head_spec.rb index 788101c9510..8f514d4eeea 100644 --- a/spec/ruby/library/net/http/http/request_head_spec.rb +++ b/spec/ruby/library/net-http/http/request_head_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/http_server' require_relative 'shared/request_head' diff --git a/spec/ruby/library/net/http/http/request_post_spec.rb b/spec/ruby/library/net-http/http/request_post_spec.rb similarity index 82% rename from spec/ruby/library/net/http/http/request_post_spec.rb rename to spec/ruby/library/net-http/http/request_post_spec.rb index 7ac67cf95d4..719bd5a7eec 100644 --- a/spec/ruby/library/net/http/http/request_post_spec.rb +++ b/spec/ruby/library/net-http/http/request_post_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/http_server' require_relative 'shared/request_post' diff --git a/spec/ruby/library/net/http/http/request_put_spec.rb b/spec/ruby/library/net-http/http/request_put_spec.rb similarity index 81% rename from spec/ruby/library/net/http/http/request_put_spec.rb rename to spec/ruby/library/net-http/http/request_put_spec.rb index 110ac43ca62..9fcf3a98d68 100644 --- a/spec/ruby/library/net/http/http/request_put_spec.rb +++ b/spec/ruby/library/net-http/http/request_put_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/http_server' require_relative 'shared/request_put' diff --git a/spec/ruby/library/net/http/http/request_spec.rb b/spec/ruby/library/net-http/http/request_spec.rb similarity index 98% rename from spec/ruby/library/net/http/http/request_spec.rb rename to spec/ruby/library/net-http/http/request_spec.rb index e63dde9c8d7..356e605b3b2 100644 --- a/spec/ruby/library/net/http/http/request_spec.rb +++ b/spec/ruby/library/net-http/http/request_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/http_server' diff --git a/spec/ruby/library/net/http/http/request_types_spec.rb b/spec/ruby/library/net-http/http/request_types_spec.rb similarity index 99% rename from spec/ruby/library/net/http/http/request_types_spec.rb rename to spec/ruby/library/net-http/http/request_types_spec.rb index 99d754d3d10..53aef1ee585 100644 --- a/spec/ruby/library/net/http/http/request_types_spec.rb +++ b/spec/ruby/library/net-http/http/request_types_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTP::Get" do diff --git a/spec/ruby/library/net/http/http/send_request_spec.rb b/spec/ruby/library/net-http/http/send_request_spec.rb similarity index 97% rename from spec/ruby/library/net/http/http/send_request_spec.rb rename to spec/ruby/library/net-http/http/send_request_spec.rb index 83e9448b8b1..e82b2a96a18 100644 --- a/spec/ruby/library/net/http/http/send_request_spec.rb +++ b/spec/ruby/library/net-http/http/send_request_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/http_server' 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 similarity index 94% rename from spec/ruby/library/net/http/http/set_debug_output_spec.rb rename to spec/ruby/library/net-http/http/set_debug_output_spec.rb index 94b6f4499d7..5ceecb39fb9 100644 --- a/spec/ruby/library/net/http/http/set_debug_output_spec.rb +++ b/spec/ruby/library/net-http/http/set_debug_output_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require "stringio" require_relative 'fixtures/http_server' diff --git a/spec/ruby/library/net/http/http/shared/request_get.rb b/spec/ruby/library/net-http/http/shared/request_get.rb similarity index 100% rename from spec/ruby/library/net/http/http/shared/request_get.rb rename to spec/ruby/library/net-http/http/shared/request_get.rb diff --git a/spec/ruby/library/net/http/http/shared/request_head.rb b/spec/ruby/library/net-http/http/shared/request_head.rb similarity index 100% rename from spec/ruby/library/net/http/http/shared/request_head.rb rename to spec/ruby/library/net-http/http/shared/request_head.rb diff --git a/spec/ruby/library/net/http/http/shared/request_post.rb b/spec/ruby/library/net-http/http/shared/request_post.rb similarity index 100% rename from spec/ruby/library/net/http/http/shared/request_post.rb rename to spec/ruby/library/net-http/http/shared/request_post.rb diff --git a/spec/ruby/library/net/http/http/shared/request_put.rb b/spec/ruby/library/net-http/http/shared/request_put.rb similarity index 100% rename from spec/ruby/library/net/http/http/shared/request_put.rb rename to spec/ruby/library/net-http/http/shared/request_put.rb diff --git a/spec/ruby/library/net/http/http/shared/started.rb b/spec/ruby/library/net-http/http/shared/started.rb similarity index 100% rename from spec/ruby/library/net/http/http/shared/started.rb rename to spec/ruby/library/net-http/http/shared/started.rb 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 similarity index 100% rename from spec/ruby/library/net/http/http/shared/version_1_1.rb rename to spec/ruby/library/net-http/http/shared/version_1_1.rb 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 similarity index 100% rename from spec/ruby/library/net/http/http/shared/version_1_2.rb rename to spec/ruby/library/net-http/http/shared/version_1_2.rb diff --git a/spec/ruby/library/net/http/http/socket_type_spec.rb b/spec/ruby/library/net-http/http/socket_type_spec.rb similarity index 77% rename from spec/ruby/library/net/http/http/socket_type_spec.rb rename to spec/ruby/library/net-http/http/socket_type_spec.rb index 5c844ddf94c..f6826777b08 100644 --- a/spec/ruby/library/net/http/http/socket_type_spec.rb +++ b/spec/ruby/library/net-http/http/socket_type_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTP.socket_type" do diff --git a/spec/ruby/library/net/http/http/start_spec.rb b/spec/ruby/library/net-http/http/start_spec.rb similarity index 98% rename from spec/ruby/library/net/http/http/start_spec.rb rename to spec/ruby/library/net-http/http/start_spec.rb index a2768eed180..0ce3e792690 100644 --- a/spec/ruby/library/net/http/http/start_spec.rb +++ b/spec/ruby/library/net-http/http/start_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/http_server' diff --git a/spec/ruby/library/net/http/http/started_spec.rb b/spec/ruby/library/net-http/http/started_spec.rb similarity index 80% rename from spec/ruby/library/net/http/http/started_spec.rb rename to spec/ruby/library/net-http/http/started_spec.rb index ea441ed16ad..cbb82ceefa8 100644 --- a/spec/ruby/library/net/http/http/started_spec.rb +++ b/spec/ruby/library/net-http/http/started_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/http_server' require_relative 'shared/started' diff --git a/spec/ruby/library/net/http/http/trace_spec.rb b/spec/ruby/library/net-http/http/trace_spec.rb similarity index 93% rename from spec/ruby/library/net/http/http/trace_spec.rb rename to spec/ruby/library/net-http/http/trace_spec.rb index 94a1bf66556..9809d537c5e 100644 --- a/spec/ruby/library/net/http/http/trace_spec.rb +++ b/spec/ruby/library/net-http/http/trace_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/http_server' diff --git a/spec/ruby/library/net/http/http/unlock_spec.rb b/spec/ruby/library/net-http/http/unlock_spec.rb similarity index 93% rename from spec/ruby/library/net/http/http/unlock_spec.rb rename to spec/ruby/library/net-http/http/unlock_spec.rb index a4f1b7a1d16..adf0b49f652 100644 --- a/spec/ruby/library/net/http/http/unlock_spec.rb +++ b/spec/ruby/library/net-http/http/unlock_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/http_server' diff --git a/spec/ruby/library/net/http/http/use_ssl_spec.rb b/spec/ruby/library/net-http/http/use_ssl_spec.rb similarity index 78% rename from spec/ruby/library/net/http/http/use_ssl_spec.rb rename to spec/ruby/library/net-http/http/use_ssl_spec.rb index be1ec7fa257..912a62a8ba6 100644 --- a/spec/ruby/library/net/http/http/use_ssl_spec.rb +++ b/spec/ruby/library/net-http/http/use_ssl_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTP#use_ssl?" do 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 similarity index 78% rename from spec/ruby/library/net/http/http/version_1_1_spec.rb rename to spec/ruby/library/net-http/http/version_1_1_spec.rb index 1c069e9ea62..34a4ac8a6bb 100644 --- a/spec/ruby/library/net/http/http/version_1_1_spec.rb +++ b/spec/ruby/library/net-http/http/version_1_1_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'shared/version_1_1' 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 similarity index 90% rename from spec/ruby/library/net/http/http/version_1_2_spec.rb rename to spec/ruby/library/net-http/http/version_1_2_spec.rb index 4e601462c91..e994511aea1 100644 --- a/spec/ruby/library/net/http/http/version_1_2_spec.rb +++ b/spec/ruby/library/net-http/http/version_1_2_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'shared/version_1_2' diff --git a/spec/ruby/library/net/http/httpexceptions/fixtures/classes.rb b/spec/ruby/library/net-http/httpexceptions/fixtures/classes.rb similarity index 100% rename from spec/ruby/library/net/http/httpexceptions/fixtures/classes.rb rename to 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 similarity index 91% rename from spec/ruby/library/net/http/httpexceptions/initialize_spec.rb rename to spec/ruby/library/net-http/httpexceptions/initialize_spec.rb index 8e3fd8cc020..5316cca69dd 100644 --- a/spec/ruby/library/net/http/httpexceptions/initialize_spec.rb +++ b/spec/ruby/library/net-http/httpexceptions/initialize_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' diff --git a/spec/ruby/library/net/http/httpexceptions/response_spec.rb b/spec/ruby/library/net-http/httpexceptions/response_spec.rb similarity index 86% rename from spec/ruby/library/net/http/httpexceptions/response_spec.rb rename to spec/ruby/library/net-http/httpexceptions/response_spec.rb index 205b2bc2128..d718b1ae214 100644 --- a/spec/ruby/library/net/http/httpexceptions/response_spec.rb +++ b/spec/ruby/library/net-http/httpexceptions/response_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' diff --git a/spec/ruby/library/net/http/httpgenericrequest/body_exist_spec.rb b/spec/ruby/library/net-http/httpgenericrequest/body_exist_spec.rb similarity index 93% rename from spec/ruby/library/net/http/httpgenericrequest/body_exist_spec.rb rename to spec/ruby/library/net-http/httpgenericrequest/body_exist_spec.rb index 7d081939b87..6c886499ca7 100644 --- a/spec/ruby/library/net/http/httpgenericrequest/body_exist_spec.rb +++ b/spec/ruby/library/net-http/httpgenericrequest/body_exist_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTPGenericRequest#body_exist?" do diff --git a/spec/ruby/library/net/http/httpgenericrequest/body_spec.rb b/spec/ruby/library/net-http/httpgenericrequest/body_spec.rb similarity index 94% rename from spec/ruby/library/net/http/httpgenericrequest/body_spec.rb rename to spec/ruby/library/net-http/httpgenericrequest/body_spec.rb index a215895b575..5f7315f303b 100644 --- a/spec/ruby/library/net/http/httpgenericrequest/body_spec.rb +++ b/spec/ruby/library/net-http/httpgenericrequest/body_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require "stringio" diff --git a/spec/ruby/library/net/http/httpgenericrequest/body_stream_spec.rb b/spec/ruby/library/net-http/httpgenericrequest/body_stream_spec.rb similarity index 95% rename from spec/ruby/library/net/http/httpgenericrequest/body_stream_spec.rb rename to spec/ruby/library/net-http/httpgenericrequest/body_stream_spec.rb index c2a60e6836d..dea1c8c8834 100644 --- a/spec/ruby/library/net/http/httpgenericrequest/body_stream_spec.rb +++ b/spec/ruby/library/net-http/httpgenericrequest/body_stream_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require "stringio" diff --git a/spec/ruby/library/net/http/httpgenericrequest/exec_spec.rb b/spec/ruby/library/net-http/httpgenericrequest/exec_spec.rb similarity index 99% rename from spec/ruby/library/net/http/httpgenericrequest/exec_spec.rb rename to spec/ruby/library/net-http/httpgenericrequest/exec_spec.rb index da5b1a63be8..cf13e9dfd67 100644 --- a/spec/ruby/library/net/http/httpgenericrequest/exec_spec.rb +++ b/spec/ruby/library/net-http/httpgenericrequest/exec_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require "stringio" diff --git a/spec/ruby/library/net/http/httpgenericrequest/inspect_spec.rb b/spec/ruby/library/net-http/httpgenericrequest/inspect_spec.rb similarity index 95% rename from spec/ruby/library/net/http/httpgenericrequest/inspect_spec.rb rename to spec/ruby/library/net-http/httpgenericrequest/inspect_spec.rb index 36240949c3e..d03b6e69539 100644 --- a/spec/ruby/library/net/http/httpgenericrequest/inspect_spec.rb +++ b/spec/ruby/library/net-http/httpgenericrequest/inspect_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTPGenericRequest#inspect" do diff --git a/spec/ruby/library/net/http/httpgenericrequest/method_spec.rb b/spec/ruby/library/net-http/httpgenericrequest/method_spec.rb similarity index 91% rename from spec/ruby/library/net/http/httpgenericrequest/method_spec.rb rename to spec/ruby/library/net-http/httpgenericrequest/method_spec.rb index 3f7c2cbf2bb..794bd328cdd 100644 --- a/spec/ruby/library/net/http/httpgenericrequest/method_spec.rb +++ b/spec/ruby/library/net-http/httpgenericrequest/method_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTPGenericRequest#method" do diff --git a/spec/ruby/library/net/http/httpgenericrequest/path_spec.rb b/spec/ruby/library/net-http/httpgenericrequest/path_spec.rb similarity index 89% rename from spec/ruby/library/net/http/httpgenericrequest/path_spec.rb rename to spec/ruby/library/net-http/httpgenericrequest/path_spec.rb index fc4cf9af539..a9fac3f67ef 100644 --- a/spec/ruby/library/net/http/httpgenericrequest/path_spec.rb +++ b/spec/ruby/library/net-http/httpgenericrequest/path_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTPGenericRequest#path" do 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 similarity index 90% rename from spec/ruby/library/net/http/httpgenericrequest/request_body_permitted_spec.rb rename to spec/ruby/library/net-http/httpgenericrequest/request_body_permitted_spec.rb index 50cd1ff637b..1713b59baf5 100644 --- a/spec/ruby/library/net/http/httpgenericrequest/request_body_permitted_spec.rb +++ b/spec/ruby/library/net-http/httpgenericrequest/request_body_permitted_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTPGenericRequest#request_body_permitted?" do 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 similarity index 90% rename from spec/ruby/library/net/http/httpgenericrequest/response_body_permitted_spec.rb rename to spec/ruby/library/net-http/httpgenericrequest/response_body_permitted_spec.rb index 0c4165d0ab3..2f0751c344e 100644 --- a/spec/ruby/library/net/http/httpgenericrequest/response_body_permitted_spec.rb +++ b/spec/ruby/library/net-http/httpgenericrequest/response_body_permitted_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTPGenericRequest#response_body_permitted?" do 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 similarity index 94% rename from spec/ruby/library/net/http/httpgenericrequest/set_body_internal_spec.rb rename to spec/ruby/library/net-http/httpgenericrequest/set_body_internal_spec.rb index 7494c69173d..358aa6cde34 100644 --- a/spec/ruby/library/net/http/httpgenericrequest/set_body_internal_spec.rb +++ b/spec/ruby/library/net-http/httpgenericrequest/set_body_internal_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTPGenericRequest#set_body_internal when passed string" do diff --git a/spec/ruby/library/net/http/httpheader/add_field_spec.rb b/spec/ruby/library/net-http/httpheader/add_field_spec.rb similarity index 95% rename from spec/ruby/library/net/http/httpheader/add_field_spec.rb rename to spec/ruby/library/net-http/httpheader/add_field_spec.rb index 882d5ac5bbc..8cd3d33517f 100644 --- a/spec/ruby/library/net/http/httpheader/add_field_spec.rb +++ b/spec/ruby/library/net-http/httpheader/add_field_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' diff --git a/spec/ruby/library/net/http/httpheader/basic_auth_spec.rb b/spec/ruby/library/net-http/httpheader/basic_auth_spec.rb similarity index 90% rename from spec/ruby/library/net/http/httpheader/basic_auth_spec.rb rename to spec/ruby/library/net-http/httpheader/basic_auth_spec.rb index fa2a710fe16..db7ca84d137 100644 --- a/spec/ruby/library/net/http/httpheader/basic_auth_spec.rb +++ b/spec/ruby/library/net-http/httpheader/basic_auth_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' diff --git a/spec/ruby/library/net/http/httpheader/canonical_each_spec.rb b/spec/ruby/library/net-http/httpheader/canonical_each_spec.rb similarity index 83% rename from spec/ruby/library/net/http/httpheader/canonical_each_spec.rb rename to spec/ruby/library/net-http/httpheader/canonical_each_spec.rb index 0dddd3049b5..64a5cae89e2 100644 --- a/spec/ruby/library/net/http/httpheader/canonical_each_spec.rb +++ b/spec/ruby/library/net-http/httpheader/canonical_each_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' require_relative 'shared/each_capitalized' diff --git a/spec/ruby/library/net/http/httpheader/chunked_spec.rb b/spec/ruby/library/net-http/httpheader/chunked_spec.rb similarity index 92% rename from spec/ruby/library/net/http/httpheader/chunked_spec.rb rename to spec/ruby/library/net-http/httpheader/chunked_spec.rb index 96b758981b5..b32a0aab388 100644 --- a/spec/ruby/library/net/http/httpheader/chunked_spec.rb +++ b/spec/ruby/library/net-http/httpheader/chunked_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' diff --git a/spec/ruby/library/net/http/httpheader/content_length_spec.rb b/spec/ruby/library/net-http/httpheader/content_length_spec.rb similarity index 97% rename from spec/ruby/library/net/http/httpheader/content_length_spec.rb rename to spec/ruby/library/net-http/httpheader/content_length_spec.rb index e344817e823..f05c5f8d8b3 100644 --- a/spec/ruby/library/net/http/httpheader/content_length_spec.rb +++ b/spec/ruby/library/net-http/httpheader/content_length_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' diff --git a/spec/ruby/library/net/http/httpheader/content_range_spec.rb b/spec/ruby/library/net-http/httpheader/content_range_spec.rb similarity index 96% rename from spec/ruby/library/net/http/httpheader/content_range_spec.rb rename to spec/ruby/library/net-http/httpheader/content_range_spec.rb index ba75f9a9a13..09737141a5c 100644 --- a/spec/ruby/library/net/http/httpheader/content_range_spec.rb +++ b/spec/ruby/library/net-http/httpheader/content_range_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' diff --git a/spec/ruby/library/net/http/httpheader/content_type_spec.rb b/spec/ruby/library/net-http/httpheader/content_type_spec.rb similarity index 94% rename from spec/ruby/library/net/http/httpheader/content_type_spec.rb rename to spec/ruby/library/net-http/httpheader/content_type_spec.rb index 1f8b4ba3266..a6e1ae1093a 100644 --- a/spec/ruby/library/net/http/httpheader/content_type_spec.rb +++ b/spec/ruby/library/net-http/httpheader/content_type_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' require_relative 'shared/set_content_type' diff --git a/spec/ruby/library/net/http/httpheader/delete_spec.rb b/spec/ruby/library/net-http/httpheader/delete_spec.rb similarity index 94% rename from spec/ruby/library/net/http/httpheader/delete_spec.rb rename to spec/ruby/library/net-http/httpheader/delete_spec.rb index 603ae198ded..8d929dbd862 100644 --- a/spec/ruby/library/net/http/httpheader/delete_spec.rb +++ b/spec/ruby/library/net-http/httpheader/delete_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' 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 similarity index 95% rename from spec/ruby/library/net/http/httpheader/each_capitalized_name_spec.rb rename to spec/ruby/library/net-http/httpheader/each_capitalized_name_spec.rb index 1af2c6939cf..27713577f97 100644 --- a/spec/ruby/library/net/http/httpheader/each_capitalized_name_spec.rb +++ b/spec/ruby/library/net-http/httpheader/each_capitalized_name_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' diff --git a/spec/ruby/library/net/http/httpheader/each_capitalized_spec.rb b/spec/ruby/library/net-http/httpheader/each_capitalized_spec.rb similarity index 83% rename from spec/ruby/library/net/http/httpheader/each_capitalized_spec.rb rename to spec/ruby/library/net-http/httpheader/each_capitalized_spec.rb index 961a2d051f2..1e853995ea6 100644 --- a/spec/ruby/library/net/http/httpheader/each_capitalized_spec.rb +++ b/spec/ruby/library/net-http/httpheader/each_capitalized_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' require_relative 'shared/each_capitalized' diff --git a/spec/ruby/library/net/http/httpheader/each_header_spec.rb b/spec/ruby/library/net-http/httpheader/each_header_spec.rb similarity index 82% rename from spec/ruby/library/net/http/httpheader/each_header_spec.rb rename to spec/ruby/library/net-http/httpheader/each_header_spec.rb index 19634a001b3..869feebacfe 100644 --- a/spec/ruby/library/net/http/httpheader/each_header_spec.rb +++ b/spec/ruby/library/net-http/httpheader/each_header_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' require_relative 'shared/each_header' diff --git a/spec/ruby/library/net/http/httpheader/each_key_spec.rb b/spec/ruby/library/net-http/httpheader/each_key_spec.rb similarity index 81% rename from spec/ruby/library/net/http/httpheader/each_key_spec.rb rename to spec/ruby/library/net-http/httpheader/each_key_spec.rb index ebb17d2eac4..1ad145629fd 100644 --- a/spec/ruby/library/net/http/httpheader/each_key_spec.rb +++ b/spec/ruby/library/net-http/httpheader/each_key_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' require_relative 'shared/each_name' diff --git a/spec/ruby/library/net/http/httpheader/each_name_spec.rb b/spec/ruby/library/net-http/httpheader/each_name_spec.rb similarity index 81% rename from spec/ruby/library/net/http/httpheader/each_name_spec.rb rename to spec/ruby/library/net-http/httpheader/each_name_spec.rb index f4533ebcfb4..f819bd989d4 100644 --- a/spec/ruby/library/net/http/httpheader/each_name_spec.rb +++ b/spec/ruby/library/net-http/httpheader/each_name_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' require_relative 'shared/each_name' diff --git a/spec/ruby/library/net/http/httpheader/each_spec.rb b/spec/ruby/library/net-http/httpheader/each_spec.rb similarity index 81% rename from spec/ruby/library/net/http/httpheader/each_spec.rb rename to spec/ruby/library/net-http/httpheader/each_spec.rb index 7ba8434f751..ff37249d0ac 100644 --- a/spec/ruby/library/net/http/httpheader/each_spec.rb +++ b/spec/ruby/library/net-http/httpheader/each_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' require_relative 'shared/each_header' diff --git a/spec/ruby/library/net/http/httpheader/each_value_spec.rb b/spec/ruby/library/net-http/httpheader/each_value_spec.rb similarity index 95% rename from spec/ruby/library/net/http/httpheader/each_value_spec.rb rename to spec/ruby/library/net-http/httpheader/each_value_spec.rb index 3224de77036..b71df58c658 100644 --- a/spec/ruby/library/net/http/httpheader/each_value_spec.rb +++ b/spec/ruby/library/net-http/httpheader/each_value_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' diff --git a/spec/ruby/library/net/http/httpheader/element_reference_spec.rb b/spec/ruby/library/net-http/httpheader/element_reference_spec.rb similarity index 96% rename from spec/ruby/library/net/http/httpheader/element_reference_spec.rb rename to spec/ruby/library/net-http/httpheader/element_reference_spec.rb index 4a35e20d208..1003c41af93 100644 --- a/spec/ruby/library/net/http/httpheader/element_reference_spec.rb +++ b/spec/ruby/library/net-http/httpheader/element_reference_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' diff --git a/spec/ruby/library/net/http/httpheader/element_set_spec.rb b/spec/ruby/library/net-http/httpheader/element_set_spec.rb similarity index 96% rename from spec/ruby/library/net/http/httpheader/element_set_spec.rb rename to spec/ruby/library/net-http/httpheader/element_set_spec.rb index e9ad64fafcb..376df2f977d 100644 --- a/spec/ruby/library/net/http/httpheader/element_set_spec.rb +++ b/spec/ruby/library/net-http/httpheader/element_set_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' diff --git a/spec/ruby/library/net/http/httpheader/fetch_spec.rb b/spec/ruby/library/net-http/httpheader/fetch_spec.rb similarity index 98% rename from spec/ruby/library/net/http/httpheader/fetch_spec.rb rename to spec/ruby/library/net-http/httpheader/fetch_spec.rb index ea15679acb0..58c69c03773 100644 --- a/spec/ruby/library/net/http/httpheader/fetch_spec.rb +++ b/spec/ruby/library/net-http/httpheader/fetch_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' diff --git a/spec/ruby/library/net/http/httpheader/fixtures/classes.rb b/spec/ruby/library/net-http/httpheader/fixtures/classes.rb similarity index 100% rename from spec/ruby/library/net/http/httpheader/fixtures/classes.rb rename to 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 similarity index 82% rename from spec/ruby/library/net/http/httpheader/form_data_spec.rb rename to spec/ruby/library/net-http/httpheader/form_data_spec.rb index 9b29a03159f..acd913f53a9 100644 --- a/spec/ruby/library/net/http/httpheader/form_data_spec.rb +++ b/spec/ruby/library/net-http/httpheader/form_data_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' require_relative 'shared/set_form_data' diff --git a/spec/ruby/library/net/http/httpheader/get_fields_spec.rb b/spec/ruby/library/net-http/httpheader/get_fields_spec.rb similarity index 96% rename from spec/ruby/library/net/http/httpheader/get_fields_spec.rb rename to spec/ruby/library/net-http/httpheader/get_fields_spec.rb index 1b623bf2a35..0278bcede21 100644 --- a/spec/ruby/library/net/http/httpheader/get_fields_spec.rb +++ b/spec/ruby/library/net-http/httpheader/get_fields_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' 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 similarity index 94% rename from spec/ruby/library/net/http/httpheader/initialize_http_header_spec.rb rename to spec/ruby/library/net-http/httpheader/initialize_http_header_spec.rb index efc5e7d0b2c..f9e6d208e5f 100644 --- a/spec/ruby/library/net/http/httpheader/initialize_http_header_spec.rb +++ b/spec/ruby/library/net-http/httpheader/initialize_http_header_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' diff --git a/spec/ruby/library/net/http/httpheader/key_spec.rb b/spec/ruby/library/net-http/httpheader/key_spec.rb similarity index 92% rename from spec/ruby/library/net/http/httpheader/key_spec.rb rename to spec/ruby/library/net-http/httpheader/key_spec.rb index 90990242293..2b7aeb9c2ad 100644 --- a/spec/ruby/library/net/http/httpheader/key_spec.rb +++ b/spec/ruby/library/net-http/httpheader/key_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' diff --git a/spec/ruby/library/net/http/httpheader/length_spec.rb b/spec/ruby/library/net-http/httpheader/length_spec.rb similarity index 80% rename from spec/ruby/library/net/http/httpheader/length_spec.rb rename to spec/ruby/library/net-http/httpheader/length_spec.rb index 0d1da149f44..57e32742e47 100644 --- a/spec/ruby/library/net/http/httpheader/length_spec.rb +++ b/spec/ruby/library/net-http/httpheader/length_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' require_relative 'shared/size' diff --git a/spec/ruby/library/net/http/httpheader/main_type_spec.rb b/spec/ruby/library/net-http/httpheader/main_type_spec.rb similarity index 93% rename from spec/ruby/library/net/http/httpheader/main_type_spec.rb rename to spec/ruby/library/net-http/httpheader/main_type_spec.rb index 3e18de6b5bf..4dd551d8f4f 100644 --- a/spec/ruby/library/net/http/httpheader/main_type_spec.rb +++ b/spec/ruby/library/net-http/httpheader/main_type_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' 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 similarity index 90% rename from spec/ruby/library/net/http/httpheader/proxy_basic_auth_spec.rb rename to spec/ruby/library/net-http/httpheader/proxy_basic_auth_spec.rb index 8b576ee164e..d9f6afc5a73 100644 --- a/spec/ruby/library/net/http/httpheader/proxy_basic_auth_spec.rb +++ b/spec/ruby/library/net-http/httpheader/proxy_basic_auth_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' diff --git a/spec/ruby/library/net/http/httpheader/range_length_spec.rb b/spec/ruby/library/net-http/httpheader/range_length_spec.rb similarity index 96% rename from spec/ruby/library/net/http/httpheader/range_length_spec.rb rename to spec/ruby/library/net-http/httpheader/range_length_spec.rb index b8fce4f690b..77323ac8726 100644 --- a/spec/ruby/library/net/http/httpheader/range_length_spec.rb +++ b/spec/ruby/library/net-http/httpheader/range_length_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' diff --git a/spec/ruby/library/net/http/httpheader/range_spec.rb b/spec/ruby/library/net-http/httpheader/range_spec.rb similarity index 97% rename from spec/ruby/library/net/http/httpheader/range_spec.rb rename to spec/ruby/library/net-http/httpheader/range_spec.rb index 005177f6be3..2de80a825e7 100644 --- a/spec/ruby/library/net/http/httpheader/range_spec.rb +++ b/spec/ruby/library/net-http/httpheader/range_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' require_relative 'shared/set_range' 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 similarity index 83% rename from spec/ruby/library/net/http/httpheader/set_content_type_spec.rb rename to spec/ruby/library/net-http/httpheader/set_content_type_spec.rb index 125f7a7e0dd..7ec4f90b8e5 100644 --- a/spec/ruby/library/net/http/httpheader/set_content_type_spec.rb +++ b/spec/ruby/library/net-http/httpheader/set_content_type_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' require_relative 'shared/set_content_type' 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 similarity index 82% rename from spec/ruby/library/net/http/httpheader/set_form_data_spec.rb rename to spec/ruby/library/net-http/httpheader/set_form_data_spec.rb index 14c66ae01c5..7aac19f0451 100644 --- a/spec/ruby/library/net/http/httpheader/set_form_data_spec.rb +++ b/spec/ruby/library/net-http/httpheader/set_form_data_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' require_relative 'shared/set_form_data' diff --git a/spec/ruby/library/net/http/httpheader/set_range_spec.rb b/spec/ruby/library/net-http/httpheader/set_range_spec.rb similarity index 81% rename from spec/ruby/library/net/http/httpheader/set_range_spec.rb rename to spec/ruby/library/net-http/httpheader/set_range_spec.rb index 85b9c50422b..0f98de55e62 100644 --- a/spec/ruby/library/net/http/httpheader/set_range_spec.rb +++ b/spec/ruby/library/net-http/httpheader/set_range_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' require_relative 'shared/set_range' diff --git a/spec/ruby/library/net/http/httpheader/shared/each_capitalized.rb b/spec/ruby/library/net-http/httpheader/shared/each_capitalized.rb similarity index 100% rename from spec/ruby/library/net/http/httpheader/shared/each_capitalized.rb rename to spec/ruby/library/net-http/httpheader/shared/each_capitalized.rb diff --git a/spec/ruby/library/net/http/httpheader/shared/each_header.rb b/spec/ruby/library/net-http/httpheader/shared/each_header.rb similarity index 100% rename from spec/ruby/library/net/http/httpheader/shared/each_header.rb rename to spec/ruby/library/net-http/httpheader/shared/each_header.rb diff --git a/spec/ruby/library/net/http/httpheader/shared/each_name.rb b/spec/ruby/library/net-http/httpheader/shared/each_name.rb similarity index 100% rename from spec/ruby/library/net/http/httpheader/shared/each_name.rb rename to spec/ruby/library/net-http/httpheader/shared/each_name.rb 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 similarity index 100% rename from spec/ruby/library/net/http/httpheader/shared/set_content_type.rb rename to spec/ruby/library/net-http/httpheader/shared/set_content_type.rb 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 similarity index 100% rename from spec/ruby/library/net/http/httpheader/shared/set_form_data.rb rename to spec/ruby/library/net-http/httpheader/shared/set_form_data.rb diff --git a/spec/ruby/library/net/http/httpheader/shared/set_range.rb b/spec/ruby/library/net-http/httpheader/shared/set_range.rb similarity index 100% rename from spec/ruby/library/net/http/httpheader/shared/set_range.rb rename to spec/ruby/library/net-http/httpheader/shared/set_range.rb diff --git a/spec/ruby/library/net/http/httpheader/shared/size.rb b/spec/ruby/library/net-http/httpheader/shared/size.rb similarity index 100% rename from spec/ruby/library/net/http/httpheader/shared/size.rb rename to spec/ruby/library/net-http/httpheader/shared/size.rb diff --git a/spec/ruby/library/net/http/httpheader/size_spec.rb b/spec/ruby/library/net-http/httpheader/size_spec.rb similarity index 80% rename from spec/ruby/library/net/http/httpheader/size_spec.rb rename to spec/ruby/library/net-http/httpheader/size_spec.rb index a7d78f96e09..210060ce210 100644 --- a/spec/ruby/library/net/http/httpheader/size_spec.rb +++ b/spec/ruby/library/net-http/httpheader/size_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' require_relative 'shared/size' diff --git a/spec/ruby/library/net/http/httpheader/sub_type_spec.rb b/spec/ruby/library/net-http/httpheader/sub_type_spec.rb similarity index 95% rename from spec/ruby/library/net/http/httpheader/sub_type_spec.rb rename to spec/ruby/library/net-http/httpheader/sub_type_spec.rb index 3c73ca00272..b39b57fe8d4 100644 --- a/spec/ruby/library/net/http/httpheader/sub_type_spec.rb +++ b/spec/ruby/library/net-http/httpheader/sub_type_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' diff --git a/spec/ruby/library/net/http/httpheader/to_hash_spec.rb b/spec/ruby/library/net-http/httpheader/to_hash_spec.rb similarity index 94% rename from spec/ruby/library/net/http/httpheader/to_hash_spec.rb rename to spec/ruby/library/net-http/httpheader/to_hash_spec.rb index 8c1d36c30af..3cebc519a6c 100644 --- a/spec/ruby/library/net/http/httpheader/to_hash_spec.rb +++ b/spec/ruby/library/net-http/httpheader/to_hash_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' diff --git a/spec/ruby/library/net/http/httpheader/type_params_spec.rb b/spec/ruby/library/net-http/httpheader/type_params_spec.rb similarity index 94% rename from spec/ruby/library/net/http/httpheader/type_params_spec.rb rename to spec/ruby/library/net-http/httpheader/type_params_spec.rb index e77be7ea85f..ac97e2b48c1 100644 --- a/spec/ruby/library/net/http/httpheader/type_params_spec.rb +++ b/spec/ruby/library/net-http/httpheader/type_params_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'fixtures/classes' diff --git a/spec/ruby/library/net/http/httprequest/initialize_spec.rb b/spec/ruby/library/net-http/httprequest/initialize_spec.rb similarity index 96% rename from spec/ruby/library/net/http/httprequest/initialize_spec.rb rename to spec/ruby/library/net-http/httprequest/initialize_spec.rb index 88e9fb1c77d..d009a00ed2e 100644 --- a/spec/ruby/library/net/http/httprequest/initialize_spec.rb +++ b/spec/ruby/library/net-http/httprequest/initialize_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' module NetHTTPRequestSpecs diff --git a/spec/ruby/library/net/http/httpresponse/body_permitted_spec.rb b/spec/ruby/library/net-http/httpresponse/body_permitted_spec.rb similarity index 91% rename from spec/ruby/library/net/http/httpresponse/body_permitted_spec.rb rename to spec/ruby/library/net-http/httpresponse/body_permitted_spec.rb index 8ade46689fa..68965de4a18 100644 --- a/spec/ruby/library/net/http/httpresponse/body_permitted_spec.rb +++ b/spec/ruby/library/net-http/httpresponse/body_permitted_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTPResponse.body_permitted?" do diff --git a/spec/ruby/library/net/http/httpresponse/body_spec.rb b/spec/ruby/library/net-http/httpresponse/body_spec.rb similarity index 76% rename from spec/ruby/library/net/http/httpresponse/body_spec.rb rename to spec/ruby/library/net-http/httpresponse/body_spec.rb index 79569441f10..ddfcd834c49 100644 --- a/spec/ruby/library/net/http/httpresponse/body_spec.rb +++ b/spec/ruby/library/net-http/httpresponse/body_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'shared/body' diff --git a/spec/ruby/library/net/http/httpresponse/code_spec.rb b/spec/ruby/library/net-http/httpresponse/code_spec.rb similarity index 94% rename from spec/ruby/library/net/http/httpresponse/code_spec.rb rename to spec/ruby/library/net-http/httpresponse/code_spec.rb index 114277cb431..699062ad973 100644 --- a/spec/ruby/library/net/http/httpresponse/code_spec.rb +++ b/spec/ruby/library/net-http/httpresponse/code_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTPResponse#code" do diff --git a/spec/ruby/library/net/http/httpresponse/code_type_spec.rb b/spec/ruby/library/net-http/httpresponse/code_type_spec.rb similarity index 94% rename from spec/ruby/library/net/http/httpresponse/code_type_spec.rb rename to spec/ruby/library/net-http/httpresponse/code_type_spec.rb index fa2d572e9ac..beb661cbbe5 100644 --- a/spec/ruby/library/net/http/httpresponse/code_type_spec.rb +++ b/spec/ruby/library/net-http/httpresponse/code_type_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTPResponse#code_type" do diff --git a/spec/ruby/library/net/http/httpresponse/entity_spec.rb b/spec/ruby/library/net-http/httpresponse/entity_spec.rb similarity index 77% rename from spec/ruby/library/net/http/httpresponse/entity_spec.rb rename to spec/ruby/library/net-http/httpresponse/entity_spec.rb index f1639042c19..ca8c4b29c09 100644 --- a/spec/ruby/library/net/http/httpresponse/entity_spec.rb +++ b/spec/ruby/library/net-http/httpresponse/entity_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require_relative 'shared/body' diff --git a/spec/ruby/library/net/http/httpresponse/error_spec.rb b/spec/ruby/library/net-http/httpresponse/error_spec.rb similarity index 95% rename from spec/ruby/library/net/http/httpresponse/error_spec.rb rename to spec/ruby/library/net-http/httpresponse/error_spec.rb index 89f4a47f601..6ced90fa234 100644 --- a/spec/ruby/library/net/http/httpresponse/error_spec.rb +++ b/spec/ruby/library/net-http/httpresponse/error_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTPResponse#error!" do diff --git a/spec/ruby/library/net/http/httpresponse/error_type_spec.rb b/spec/ruby/library/net-http/httpresponse/error_type_spec.rb similarity index 95% rename from spec/ruby/library/net/http/httpresponse/error_type_spec.rb rename to spec/ruby/library/net-http/httpresponse/error_type_spec.rb index 8885b7706bd..3969621a5ea 100644 --- a/spec/ruby/library/net/http/httpresponse/error_type_spec.rb +++ b/spec/ruby/library/net-http/httpresponse/error_type_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTPResponse#error_type" do diff --git a/spec/ruby/library/net/http/httpresponse/exception_type_spec.rb b/spec/ruby/library/net-http/httpresponse/exception_type_spec.rb similarity index 92% rename from spec/ruby/library/net/http/httpresponse/exception_type_spec.rb rename to spec/ruby/library/net-http/httpresponse/exception_type_spec.rb index 0c9c11291f2..dd2761a744c 100644 --- a/spec/ruby/library/net/http/httpresponse/exception_type_spec.rb +++ b/spec/ruby/library/net-http/httpresponse/exception_type_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTPResponse.exception_type" do diff --git a/spec/ruby/library/net/http/httpresponse/header_spec.rb b/spec/ruby/library/net-http/httpresponse/header_spec.rb similarity index 82% rename from spec/ruby/library/net/http/httpresponse/header_spec.rb rename to spec/ruby/library/net-http/httpresponse/header_spec.rb index a9615feda83..a403dbd2c33 100644 --- a/spec/ruby/library/net/http/httpresponse/header_spec.rb +++ b/spec/ruby/library/net-http/httpresponse/header_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTPResponse#header" do diff --git a/spec/ruby/library/net/http/httpresponse/http_version_spec.rb b/spec/ruby/library/net-http/httpresponse/http_version_spec.rb similarity index 88% rename from spec/ruby/library/net/http/httpresponse/http_version_spec.rb rename to spec/ruby/library/net-http/httpresponse/http_version_spec.rb index db85696d77d..a3e413a360f 100644 --- a/spec/ruby/library/net/http/httpresponse/http_version_spec.rb +++ b/spec/ruby/library/net-http/httpresponse/http_version_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTPResponse#http_version" do diff --git a/spec/ruby/library/net/http/httpresponse/initialize_spec.rb b/spec/ruby/library/net-http/httpresponse/initialize_spec.rb similarity index 90% rename from spec/ruby/library/net/http/httpresponse/initialize_spec.rb rename to spec/ruby/library/net-http/httpresponse/initialize_spec.rb index eb77e2e2774..673c11a2459 100644 --- a/spec/ruby/library/net/http/httpresponse/initialize_spec.rb +++ b/spec/ruby/library/net-http/httpresponse/initialize_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTPResponse#initialize when passed http_version, response_code, response_message" do diff --git a/spec/ruby/library/net/http/httpresponse/inspect_spec.rb b/spec/ruby/library/net-http/httpresponse/inspect_spec.rb similarity index 92% rename from spec/ruby/library/net/http/httpresponse/inspect_spec.rb rename to spec/ruby/library/net-http/httpresponse/inspect_spec.rb index 1e1a2c7cc75..43071ec8cdf 100644 --- a/spec/ruby/library/net/http/httpresponse/inspect_spec.rb +++ b/spec/ruby/library/net-http/httpresponse/inspect_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require "stringio" diff --git a/spec/ruby/library/net/http/httpresponse/message_spec.rb b/spec/ruby/library/net-http/httpresponse/message_spec.rb similarity index 83% rename from spec/ruby/library/net/http/httpresponse/message_spec.rb rename to spec/ruby/library/net-http/httpresponse/message_spec.rb index ae8e3678a13..5ba73bb449f 100644 --- a/spec/ruby/library/net/http/httpresponse/message_spec.rb +++ b/spec/ruby/library/net-http/httpresponse/message_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTPResponse#message" do diff --git a/spec/ruby/library/net/http/httpresponse/msg_spec.rb b/spec/ruby/library/net-http/httpresponse/msg_spec.rb similarity index 83% rename from spec/ruby/library/net/http/httpresponse/msg_spec.rb rename to spec/ruby/library/net-http/httpresponse/msg_spec.rb index 0e5e7eb4aa9..04f5836d7ab 100644 --- a/spec/ruby/library/net/http/httpresponse/msg_spec.rb +++ b/spec/ruby/library/net-http/httpresponse/msg_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTPResponse#msg" do diff --git a/spec/ruby/library/net/http/httpresponse/read_body_spec.rb b/spec/ruby/library/net-http/httpresponse/read_body_spec.rb similarity index 98% rename from spec/ruby/library/net/http/httpresponse/read_body_spec.rb rename to spec/ruby/library/net-http/httpresponse/read_body_spec.rb index ec9b42f9195..380d17d3b97 100644 --- a/spec/ruby/library/net/http/httpresponse/read_body_spec.rb +++ b/spec/ruby/library/net-http/httpresponse/read_body_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require 'stringio' diff --git a/spec/ruby/library/net/http/httpresponse/read_header_spec.rb b/spec/ruby/library/net-http/httpresponse/read_header_spec.rb similarity index 82% rename from spec/ruby/library/net/http/httpresponse/read_header_spec.rb rename to spec/ruby/library/net-http/httpresponse/read_header_spec.rb index 6af8c6bd6a2..3ea4ee834b4 100644 --- a/spec/ruby/library/net/http/httpresponse/read_header_spec.rb +++ b/spec/ruby/library/net-http/httpresponse/read_header_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTPResponse#read_header" do diff --git a/spec/ruby/library/net/http/httpresponse/read_new_spec.rb b/spec/ruby/library/net-http/httpresponse/read_new_spec.rb similarity index 93% rename from spec/ruby/library/net/http/httpresponse/read_new_spec.rb rename to spec/ruby/library/net-http/httpresponse/read_new_spec.rb index dc2cdc96210..82f7a47ce8d 100644 --- a/spec/ruby/library/net/http/httpresponse/read_new_spec.rb +++ b/spec/ruby/library/net-http/httpresponse/read_new_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require 'stringio' diff --git a/spec/ruby/library/net/http/httpresponse/reading_body_spec.rb b/spec/ruby/library/net-http/httpresponse/reading_body_spec.rb similarity index 97% rename from spec/ruby/library/net/http/httpresponse/reading_body_spec.rb rename to spec/ruby/library/net-http/httpresponse/reading_body_spec.rb index ebdab891e1b..637a2806f89 100644 --- a/spec/ruby/library/net/http/httpresponse/reading_body_spec.rb +++ b/spec/ruby/library/net-http/httpresponse/reading_body_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' require "stringio" diff --git a/spec/ruby/library/net/http/httpresponse/response_spec.rb b/spec/ruby/library/net-http/httpresponse/response_spec.rb similarity index 82% rename from spec/ruby/library/net/http/httpresponse/response_spec.rb rename to spec/ruby/library/net-http/httpresponse/response_spec.rb index f6035f36955..caa0ca2d190 100644 --- a/spec/ruby/library/net/http/httpresponse/response_spec.rb +++ b/spec/ruby/library/net-http/httpresponse/response_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTPResponse#response" do diff --git a/spec/ruby/library/net/http/httpresponse/shared/body.rb b/spec/ruby/library/net-http/httpresponse/shared/body.rb similarity index 100% rename from spec/ruby/library/net/http/httpresponse/shared/body.rb rename to spec/ruby/library/net-http/httpresponse/shared/body.rb diff --git a/spec/ruby/library/net/http/httpresponse/value_spec.rb b/spec/ruby/library/net-http/httpresponse/value_spec.rb similarity index 95% rename from spec/ruby/library/net/http/httpresponse/value_spec.rb rename to spec/ruby/library/net-http/httpresponse/value_spec.rb index 5cd58316ef2..2df8beaa10d 100644 --- a/spec/ruby/library/net/http/httpresponse/value_spec.rb +++ b/spec/ruby/library/net-http/httpresponse/value_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../spec_helper' +require_relative '../../../spec_helper' require 'net/http' describe "Net::HTTPResponse#value" do diff --git a/spec/ruby/library/net/FTPError_spec.rb b/spec/ruby/library/net/FTPError_spec.rb deleted file mode 100644 index 84128511db2..00000000000 --- a/spec/ruby/library/net/FTPError_spec.rb +++ /dev/null @@ -1,11 +0,0 @@ -require_relative '../../spec_helper' - -ruby_version_is ""..."3.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/FTPPermError_spec.rb b/spec/ruby/library/net/FTPPermError_spec.rb deleted file mode 100644 index 0da35e7d82c..00000000000 --- a/spec/ruby/library/net/FTPPermError_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -require_relative '../../spec_helper' - -ruby_version_is ""..."3.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/FTPProtoError_spec.rb b/spec/ruby/library/net/FTPProtoError_spec.rb deleted file mode 100644 index 20e30dd2dd3..00000000000 --- a/spec/ruby/library/net/FTPProtoError_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -require_relative '../../spec_helper' - -ruby_version_is ""..."3.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/FTPReplyError_spec.rb b/spec/ruby/library/net/FTPReplyError_spec.rb deleted file mode 100644 index cc774aabe5b..00000000000 --- a/spec/ruby/library/net/FTPReplyError_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -require_relative '../../spec_helper' - -ruby_version_is ""..."3.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/FTPTempError_spec.rb b/spec/ruby/library/net/FTPTempError_spec.rb deleted file mode 100644 index e2fbdfd842e..00000000000 --- a/spec/ruby/library/net/FTPTempError_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -require_relative '../../spec_helper' - -ruby_version_is ""..."3.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 deleted file mode 100644 index ebdfed4b160..00000000000 --- a/spec/ruby/library/net/ftp/abort_spec.rb +++ /dev/null @@ -1,65 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.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_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.") - -> { @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.") - -> { @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.") - -> { @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.") - -> { @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.") - -> { @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.") - -> { @ftp.abort }.should raise_error(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 deleted file mode 100644 index a960ae20a43..00000000000 --- a/spec/ruby/library/net/ftp/acct_spec.rb +++ /dev/null @@ -1,61 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.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_error - 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_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.") - -> { @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.") - -> { @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.") - -> { @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.") - -> { @ftp.acct("my_account") }.should raise_error(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 deleted file mode 100644 index da7e2d6c146..00000000000 --- a/spec/ruby/library/net/ftp/binary_spec.rb +++ /dev/null @@ -1,27 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.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 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 -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 741c3c845ed..00000000000 --- a/spec/ruby/library/net/ftp/chdir_spec.rb +++ /dev/null @@ -1,102 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.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 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.") - -> { @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.") - -> { @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.") - -> { @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.") - -> { @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.") - -> { @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.") - -> { @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.") - -> { @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.") - -> { @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.") - -> { @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.") - -> { @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.") - -> { @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.") - -> { @ftp.chdir("test") }.should raise_error(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 deleted file mode 100644 index 49cdf4dea70..00000000000 --- a/spec/ruby/library/net/ftp/close_spec.rb +++ /dev/null @@ -1,33 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.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 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 -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 a81917090a9..00000000000 --- a/spec/ruby/library/net/ftp/closed_spec.rb +++ /dev/null @@ -1,24 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.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 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 -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 b45e46c5303..00000000000 --- a/spec/ruby/library/net/ftp/connect_spec.rb +++ /dev/null @@ -1,52 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.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_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 - -> { @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!" - -> { @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." - -> { @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." - -> { @ftp.connect(@server.hostname, @server.server_port) }.should raise_error(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 deleted file mode 100644 index 46d207bbea5..00000000000 --- a/spec/ruby/library/net/ftp/debug_mode_spec.rb +++ /dev/null @@ -1,26 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.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 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 -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 9348d3294d9..00000000000 --- a/spec/ruby/library/net/ftp/default_passive_spec.rb +++ /dev/null @@ -1,11 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.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 deleted file mode 100644 index 43bfcc15415..00000000000 --- a/spec/ruby/library/net/ftp/delete_spec.rb +++ /dev/null @@ -1,62 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.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_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.") - -> { @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.") - -> { @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.") - -> { @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.") - -> { @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.") - -> { @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.") - -> { @ftp.delete("test.file") }.should raise_error(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 deleted file mode 100644 index dce50a5ac55..00000000000 --- a/spec/ruby/library/net/ftp/dir_spec.rb +++ /dev/null @@ -1,11 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.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/get_spec.rb b/spec/ruby/library/net/ftp/get_spec.rb deleted file mode 100644 index 892b30061c2..00000000000 --- a/spec/ruby/library/net/ftp/get_spec.rb +++ /dev/null @@ -1,24 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.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 deleted file mode 100644 index c5abdd67e74..00000000000 --- a/spec/ruby/library/net/ftp/getbinaryfile_spec.rb +++ /dev/null @@ -1,11 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.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 deleted file mode 100644 index 8f6fca5bfb5..00000000000 --- a/spec/ruby/library/net/ftp/getdir_spec.rb +++ /dev/null @@ -1,10 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.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 deleted file mode 100644 index e272ae73b10..00000000000 --- a/spec/ruby/library/net/ftp/gettextfile_spec.rb +++ /dev/null @@ -1,11 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.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 deleted file mode 100644 index 9b15f42ede6..00000000000 --- a/spec/ruby/library/net/ftp/help_spec.rb +++ /dev/null @@ -1,69 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.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_error - 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_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.") - -> { @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.") - -> { @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.") - -> { @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.") - -> { @ftp.help }.should raise_error(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 deleted file mode 100644 index 80f71a91618..00000000000 --- a/spec/ruby/library/net/ftp/initialize_spec.rb +++ /dev/null @@ -1,408 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.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.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 - - before :each do - @ftp.stub!(:login) - end - - describe 'when the host' do - describe 'is set' do - describe 'and port option' do - describe 'is set' do - it 'tries to connect to the host on the specified port' do - options = mock('ftp initialize options') - options.should_receive(:to_hash).and_return({ port: 8080 }) - @ftp.should_receive(:connect).with('localhost', 8080) - - @ftp.send(:initialize, 'localhost', options) - end - end - - describe 'is not set' do - it 'tries to connect to the host without a port' do - @ftp.should_receive(:connect).with("localhost", *@port_args) - - @ftp.send(:initialize, 'localhost') - end - end - end - - describe 'when the username option' do - describe 'is set' do - describe 'and the password option' do - describe 'is set' do - describe 'and the account option' do - describe 'is set' do - it 'tries to log in with the supplied parameters' do - options = mock('ftp initialize options') - options.should_receive(:to_hash).and_return({ username: 'a', password: 'topsecret', account: 'b' }) - @ftp.should_receive(:login).with('a', 'topsecret', 'b') - - @ftp.send(:initialize, 'localhost', options) - end - end - - describe 'is unset' do - it 'tries to log in with the supplied parameters' do - options = mock('ftp initialize options') - options.should_receive(:to_hash).and_return({ username: 'a', password: 'topsecret' }) - @ftp.should_receive(:login).with('a', 'topsecret', nil) - - @ftp.send(:initialize, 'localhost', options) - end - end - end - end - - describe 'is unset' do - describe 'and the account option' do - describe 'is set' do - it 'tries to log in with the supplied parameters' do - options = mock('ftp initialize options') - options.should_receive(:to_hash).and_return({ username: 'a', account: 'b' }) - @ftp.should_receive(:login).with('a', nil, 'b') - - @ftp.send(:initialize, 'localhost', options) - end - end - - describe 'is unset' do - it 'tries to log in with the supplied parameters' do - options = mock('ftp initialize options') - options.should_receive(:to_hash).and_return({ username: 'a'}) - @ftp.should_receive(:login).with('a', nil, nil) - - @ftp.send(:initialize, 'localhost', options) - end - end - end - end - end - end - - describe 'is not set' do - it 'does not try to log in' do - options = mock('ftp initialize options') - options.should_receive(:to_hash).and_return({}) - @ftp.should_not_receive(:login) - - @ftp.send(:initialize, 'localhost', options) - end - end - end - end - - describe 'is unset' do - it 'does not try to connect' do - @ftp.should_not_receive(:connect) - - @ftp.send(:initialize) - end - - it 'does not try to log in' do - @ftp.should_not_receive(:login) - - @ftp.send(:initialize) - end - end - end - - describe 'when the passive option' do - describe 'is set' do - describe 'to true' do - it 'sets passive to true' do - options = mock('ftp initialize options') - options.should_receive(:to_hash).and_return({ passive: true }) - - @ftp.send(:initialize, nil, options) - @ftp.passive.should == true - end - end - - describe 'to false' do - it 'sets passive to false' do - options = mock('ftp initialize options') - options.should_receive(:to_hash).and_return({ passive: false }) - - @ftp.send(:initialize, nil, options) - @ftp.passive.should == false - end - end - end - - describe 'is unset' do - it 'sets passive to false' do - @ftp.send(:initialize) - @ftp.passive.should == false - end - end - end - - describe 'when the debug_mode option' do - describe 'is set' do - describe 'to true' do - it 'sets debug_mode to true' do - options = mock('ftp initialize options') - options.should_receive(:to_hash).and_return({ debug_mode: true }) - - @ftp.send(:initialize, nil, options) - @ftp.debug_mode.should == true - end - end - - describe 'to false' do - it 'sets debug_mode to false' do - options = mock('ftp initialize options') - options.should_receive(:to_hash).and_return({ debug_mode: false }) - - @ftp.send(:initialize, nil, options) - @ftp.debug_mode.should == false - end - end - end - - describe 'is unset' do - it 'sets debug_mode to false' do - @ftp.send(:initialize) - @ftp.debug_mode.should == false - end - end - end - - describe 'when the open_timeout option' do - describe 'is set' do - it 'sets open_timeout to the specified value' do - options = mock('ftp initialize options') - options.should_receive(:to_hash).and_return({ open_timeout: 42 }) - - @ftp.send(:initialize, nil, options) - @ftp.open_timeout.should == 42 - end - end - - describe 'is not set' do - it 'sets open_timeout to nil' do - @ftp.send(:initialize) - @ftp.open_timeout.should == nil - end - end - end - - describe 'when the read_timeout option' do - describe 'is set' do - it 'sets read_timeout to the specified value' do - options = mock('ftp initialize options') - options.should_receive(:to_hash).and_return({ read_timeout: 100 }) - - @ftp.send(:initialize, nil, options) - @ftp.read_timeout.should == 100 - end - end - - describe 'is not set' do - it 'sets read_timeout to the default value' do - @ftp.send(:initialize) - @ftp.read_timeout.should == 60 - end - end - end - - describe 'when the ssl_handshake_timeout option' do - describe 'is set' do - it 'sets ssl_handshake_timeout to the specified value' do - options = mock('ftp initialize options') - options.should_receive(:to_hash).and_return({ ssl_handshake_timeout: 23 }) - - @ftp.send(:initialize, nil, options) - @ftp.ssl_handshake_timeout.should == 23 - end - end - - describe 'is not set' do - it 'sets ssl_handshake_timeout to nil' do - @ftp.send(:initialize) - @ftp.ssl_handshake_timeout.should == nil - end - end - end - - describe 'when the ssl option' do - describe 'is set' do - describe "and the ssl option's value is true" do - it 'initializes ssl_context to a blank SSLContext object' do - options = mock('ftp initialize options') - options.should_receive(:to_hash).and_return({ ssl: true }) - - ssl_context = OpenSSL::SSL::SSLContext.allocate - ssl_context.stub!(:set_params) - - OpenSSL::SSL::SSLContext.should_receive(:new).and_return(ssl_context) - ssl_context.should_receive(:set_params).with({}) - - @ftp.send(:initialize, nil, options) - @ftp.instance_variable_get(:@ssl_context).should == ssl_context - end - end - - describe "and the ssl option's value is a hash" do - it 'initializes ssl_context to a configured SSLContext object' do - options = mock('ftp initialize options') - options.should_receive(:to_hash).and_return({ ssl: {key: 'value'} }) - - ssl_context = OpenSSL::SSL::SSLContext.allocate - ssl_context.stub!(:set_params) - - OpenSSL::SSL::SSLContext.should_receive(:new).and_return(ssl_context) - ssl_context.should_receive(:set_params).with({key: 'value'}) - - @ftp.send(:initialize, nil, options) - @ftp.instance_variable_get(:@ssl_context).should == ssl_context - end - end - - describe 'and private_data_connection' do - describe 'is set' do - it 'sets private_data_connection to that value' do - options = mock('ftp initialize options') - options.should_receive(:to_hash).and_return({ ssl: true, private_data_connection: 'true' }) - - @ftp.send(:initialize, nil, options) - @ftp.instance_variable_get(:@private_data_connection).should == 'true' - end - end - - describe 'is not set' do - it 'sets private_data_connection to nil' do - options = mock('ftp initialize options') - options.should_receive(:to_hash).and_return({ ssl: true }) - - @ftp.send(:initialize, nil, options) - @ftp.instance_variable_get(:@private_data_connection).should == true - end - end - end - end - - describe 'is not set' do - it 'sets ssl_context to nil' do - options = mock('ftp initialize options') - options.should_receive(:to_hash).and_return({}) - - @ftp.send(:initialize, nil, options) - @ftp.instance_variable_get(:@ssl_context).should == nil - end - - describe 'private_data_connection' do - describe 'is set' do - it 'raises an ArgumentError' do - options = mock('ftp initialize options') - options.should_receive(:to_hash).and_return({ private_data_connection: true }) - - -> { - @ftp.send(:initialize, nil, options) - }.should raise_error(ArgumentError, /private_data_connection can be set to true only when ssl is enabled/) - end - end - - describe 'is not set' do - it 'sets private_data_connection to false' do - options = mock('ftp initialize options') - options.should_receive(:to_hash).and_return({}) - - @ftp.send(:initialize, nil, options) - @ftp.instance_variable_get(:@private_data_connection).should == false - end - end - end - end - end - end -end diff --git a/spec/ruby/library/net/ftp/last_response_code_spec.rb b/spec/ruby/library/net/ftp/last_response_code_spec.rb deleted file mode 100644 index 86f2b9a6950..00000000000 --- a/spec/ruby/library/net/ftp/last_response_code_spec.rb +++ /dev/null @@ -1,11 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.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 deleted file mode 100644 index 1d29b9b73fb..00000000000 --- a/spec/ruby/library/net/ftp/last_response_spec.rb +++ /dev/null @@ -1,28 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.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 deleted file mode 100644 index 9d26efb8f8f..00000000000 --- a/spec/ruby/library/net/ftp/lastresp_spec.rb +++ /dev/null @@ -1,11 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.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 deleted file mode 100644 index 6cffafeb4f6..00000000000 --- a/spec/ruby/library/net/ftp/list_spec.rb +++ /dev/null @@ -1,11 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.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 deleted file mode 100644 index 981b4390821..00000000000 --- a/spec/ruby/library/net/ftp/login_spec.rb +++ /dev/null @@ -1,198 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.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_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.") - -> { @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.") - -> { @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.") - -> { @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.") - -> { @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.") - -> { @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.") - -> { @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.") - -> { @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.") - -> { @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.") - -> { @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.") - -> { @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.") - -> { @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.") - -> { @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.") - -> { @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.") - -> { @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.") - -> { @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.") - -> { @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.") - -> { @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.") - -> { @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.") - -> { @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.") - -> { @ftp.login("rubyspec", "rocks", "account") }.should raise_error(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 deleted file mode 100644 index f2625158652..00000000000 --- a/spec/ruby/library/net/ftp/ls_spec.rb +++ /dev/null @@ -1,11 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.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 deleted file mode 100644 index ea55533c436..00000000000 --- a/spec/ruby/library/net/ftp/mdtm_spec.rb +++ /dev/null @@ -1,41 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.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_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.") - -> { @ftp.mdtm("test.file") }.should raise_error(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 deleted file mode 100644 index 2cb437a0768..00000000000 --- a/spec/ruby/library/net/ftp/mkdir_spec.rb +++ /dev/null @@ -1,64 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.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_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.") - -> { @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.") - -> { @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.") - -> { @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.") - -> { @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.") - -> { @ftp.mkdir("test.folder") }.should raise_error(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 deleted file mode 100644 index 7265667a522..00000000000 --- a/spec/ruby/library/net/ftp/mtime_spec.rb +++ /dev/null @@ -1,53 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.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_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.") - -> { @ftp.mtime("test.file") }.should raise_error(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 deleted file mode 100644 index 0de84b3a766..00000000000 --- a/spec/ruby/library/net/ftp/nlst_spec.rb +++ /dev/null @@ -1,95 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.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_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.") - -> { @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.") - -> { @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.") - -> { @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.") - -> { @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.") - -> { @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.") - -> { @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.") - -> { @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.") - -> { @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.") - -> { @ftp.nlst }.should raise_error(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 deleted file mode 100644 index 71011d4af7e..00000000000 --- a/spec/ruby/library/net/ftp/noop_spec.rb +++ /dev/null @@ -1,41 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.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 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.") - -> { @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.") - -> { @ftp.noop }.should raise_error(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 deleted file mode 100644 index 89187b98020..00000000000 --- a/spec/ruby/library/net/ftp/open_spec.rb +++ /dev/null @@ -1,58 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.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 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 -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 f9c34efb7d9..00000000000 --- a/spec/ruby/library/net/ftp/passive_spec.rb +++ /dev/null @@ -1,31 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.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 be_false - - ftp.passive = true - ftp.passive.should be_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 be_true - - ftp.passive = false - ftp.passive.should be_false - end - 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 36ba6c19637..00000000000 --- a/spec/ruby/library/net/ftp/put_spec.rb +++ /dev/null @@ -1,24 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.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 deleted file mode 100644 index 6ced5246fe1..00000000000 --- a/spec/ruby/library/net/ftp/putbinaryfile_spec.rb +++ /dev/null @@ -1,11 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.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 deleted file mode 100644 index 0cab6bd3c32..00000000000 --- a/spec/ruby/library/net/ftp/puttextfile_spec.rb +++ /dev/null @@ -1,11 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.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 deleted file mode 100644 index 856ff5ff9b0..00000000000 --- a/spec/ruby/library/net/ftp/pwd_spec.rb +++ /dev/null @@ -1,56 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.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_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.") - -> { @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.") - -> { @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.") - -> { @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.") - -> { @ftp.pwd }.should raise_error(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 deleted file mode 100644 index 12b9fd3ceef..00000000000 --- a/spec/ruby/library/net/ftp/quit_spec.rb +++ /dev/null @@ -1,36 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.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 be_false - end - - it "returns nil" do - @ftp.quit.should be_nil - end - 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 aa7c1360b53..00000000000 --- a/spec/ruby/library/net/ftp/rename_spec.rb +++ /dev/null @@ -1,97 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.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 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.") - -> { @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.") - -> { @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.") - -> { @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.") - -> { @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.") - -> { @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.") - -> { @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.") - -> { @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.") - -> { @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.") - -> { @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.") - -> { @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.") - -> { @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.") - -> { @ftp.rename("from.file", "to.file") }.should raise_error(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 deleted file mode 100644 index 1b575c29f16..00000000000 --- a/spec/ruby/library/net/ftp/resume_spec.rb +++ /dev/null @@ -1,26 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.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 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 -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 1f89f0d454d..00000000000 --- a/spec/ruby/library/net/ftp/retrbinary_spec.rb +++ /dev/null @@ -1,33 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.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 deleted file mode 100644 index f26b0086803..00000000000 --- a/spec/ruby/library/net/ftp/retrlines_spec.rb +++ /dev/null @@ -1,37 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.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 deleted file mode 100644 index 67fc9d3b19f..00000000000 --- a/spec/ruby/library/net/ftp/return_code_spec.rb +++ /dev/null @@ -1,27 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.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 deleted file mode 100644 index 5b9586c6f06..00000000000 --- a/spec/ruby/library/net/ftp/rmdir_spec.rb +++ /dev/null @@ -1,61 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.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 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.") - -> { @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.") - -> { @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.") - -> { @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.") - -> { @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.") - -> { @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.") - -> { @ftp.rmdir("test.folder") }.should raise_error(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 deleted file mode 100644 index fefb89ae0b1..00000000000 --- a/spec/ruby/library/net/ftp/sendcmd_spec.rb +++ /dev/null @@ -1,57 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.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_error - - @server.should_receive(:help).and_respond("200 Command okay.") - -> { @ftp.sendcmd("HELP") }.should_not raise_error - - @server.should_receive(:help).and_respond("350 Requested file action pending further information.") - -> { @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.") - -> { @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.") - -> { @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.") - -> { @ftp.sendcmd("HELP") }.should raise_error(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 deleted file mode 100644 index 6c8b58fb790..00000000000 --- a/spec/ruby/library/net/ftp/set_socket_spec.rb +++ /dev/null @@ -1,11 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.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/site_spec.rb b/spec/ruby/library/net/ftp/site_spec.rb deleted file mode 100644 index ca4f4991124..00000000000 --- a/spec/ruby/library/net/ftp/site_spec.rb +++ /dev/null @@ -1,56 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.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 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.") - -> { @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.") - -> { @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.") - -> { @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.") - -> { @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.") - -> { @ftp.site("param") }.should raise_error(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 deleted file mode 100644 index 0c20b105493..00000000000 --- a/spec/ruby/library/net/ftp/size_spec.rb +++ /dev/null @@ -1,51 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.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_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.") - -> { @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.") - -> { @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.") - -> { @ftp.size("test.file") }.should raise_error(Net::FTPPermError) - end - end -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 03bc5d6e05d..00000000000 --- a/spec/ruby/library/net/ftp/status_spec.rb +++ /dev/null @@ -1,70 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.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_error - 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_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.") - -> { @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.") - -> { @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.") - -> { @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.") - -> { @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.") - -> { @ftp.status }.should raise_error(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 deleted file mode 100644 index 6f733446120..00000000000 --- a/spec/ruby/library/net/ftp/storbinary_spec.rb +++ /dev/null @@ -1,51 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.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 deleted file mode 100644 index 32b9448732b..00000000000 --- a/spec/ruby/library/net/ftp/storlines_spec.rb +++ /dev/null @@ -1,46 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.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 deleted file mode 100644 index 0630bbe1f61..00000000000 --- a/spec/ruby/library/net/ftp/system_spec.rb +++ /dev/null @@ -1,51 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.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_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.") - -> { @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.") - -> { @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.") - -> { @ftp.system }.should raise_error(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 deleted file mode 100644 index ee74455d63a..00000000000 --- a/spec/ruby/library/net/ftp/voidcmd_spec.rb +++ /dev/null @@ -1,57 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.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_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.") - -> { @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.") - -> { @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.") - -> { @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.") - -> { @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.") - -> { @ftp.voidcmd("HELP") }.should raise_error(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 deleted file mode 100644 index e5414ef6075..00000000000 --- a/spec/ruby/library/net/ftp/welcome_spec.rb +++ /dev/null @@ -1,28 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.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 be_nil - @ftp.login - @ftp.welcome.should == "230 User logged in, proceed. (USER anonymous)\n" - end - end -end diff --git a/spec/ruby/library/observer/add_observer_spec.rb b/spec/ruby/library/observer/add_observer_spec.rb index 4c33c647348..5217ae6dc45 100644 --- a/spec/ruby/library/observer/add_observer_spec.rb +++ b/spec/ruby/library/observer/add_observer_spec.rb @@ -1,26 +1,23 @@ require_relative '../../spec_helper' +require_relative 'fixtures/classes' -ruby_version_is ""..."3.4" do - require_relative 'fixtures/classes' +describe "Observer#add_observer" do - describe "Observer#add_observer" do - - before :each do - @observable = ObservableSpecs.new - @observer = ObserverCallbackSpecs.new - end - - it "adds the observer" do - @observer.value.should == nil - @observable.changed - @observable.notify_observers("test") - @observer.value.should == nil + before :each do + @observable = ObservableSpecs.new + @observer = ObserverCallbackSpecs.new + end - @observable.add_observer(@observer) - @observable.changed - @observable.notify_observers("test2") - @observer.value.should == "test2" - end + it "adds the observer" do + @observer.value.should == nil + @observable.changed + @observable.notify_observers("test") + @observer.value.should == nil + @observable.add_observer(@observer) + @observable.changed + @observable.notify_observers("test2") + @observer.value.should == "test2" end + end diff --git a/spec/ruby/library/observer/count_observers_spec.rb b/spec/ruby/library/observer/count_observers_spec.rb index ab733e4e40b..c93674196d9 100644 --- a/spec/ruby/library/observer/count_observers_spec.rb +++ b/spec/ruby/library/observer/count_observers_spec.rb @@ -1,26 +1,23 @@ require_relative '../../spec_helper' +require_relative 'fixtures/classes' -ruby_version_is ""..."3.4" do - require_relative 'fixtures/classes' - - describe "Observer#count_observers" do - before :each do - @observable = ObservableSpecs.new - @observer = ObserverCallbackSpecs.new - @observer2 = ObserverCallbackSpecs.new - end +describe "Observer#count_observers" do + before :each do + @observable = ObservableSpecs.new + @observer = ObserverCallbackSpecs.new + @observer2 = ObserverCallbackSpecs.new + end - it "returns the number of observers" do - @observable.count_observers.should == 0 - @observable.add_observer(@observer) - @observable.count_observers.should == 1 - @observable.add_observer(@observer2) - @observable.count_observers.should == 2 - end + it "returns the number of observers" do + @observable.count_observers.should == 0 + @observable.add_observer(@observer) + @observable.count_observers.should == 1 + @observable.add_observer(@observer2) + @observable.count_observers.should == 2 + end - it "returns the number of unique observers" do - 2.times { @observable.add_observer(@observer) } - @observable.count_observers.should == 1 - end + it "returns the number of unique observers" do + 2.times { @observable.add_observer(@observer) } + @observable.count_observers.should == 1 end end diff --git a/spec/ruby/library/observer/delete_observer_spec.rb b/spec/ruby/library/observer/delete_observer_spec.rb index 83db19bae2c..52be1a6cbab 100644 --- a/spec/ruby/library/observer/delete_observer_spec.rb +++ b/spec/ruby/library/observer/delete_observer_spec.rb @@ -1,22 +1,19 @@ require_relative '../../spec_helper' +require_relative 'fixtures/classes' -ruby_version_is ""..."3.4" do - require_relative 'fixtures/classes' - - describe "Observer#delete_observer" do - before :each do - @observable = ObservableSpecs.new - @observer = ObserverCallbackSpecs.new - end - - it "deletes the observer" do - @observable.add_observer(@observer) - @observable.delete_observer(@observer) +describe "Observer#delete_observer" do + before :each do + @observable = ObservableSpecs.new + @observer = ObserverCallbackSpecs.new + end - @observable.changed - @observable.notify_observers("test") - @observer.value.should == nil - end + it "deletes the observer" do + @observable.add_observer(@observer) + @observable.delete_observer(@observer) + @observable.changed + @observable.notify_observers("test") + @observer.value.should == nil end + end diff --git a/spec/ruby/library/observer/delete_observers_spec.rb b/spec/ruby/library/observer/delete_observers_spec.rb index 5e7fe21d741..186e93a013c 100644 --- a/spec/ruby/library/observer/delete_observers_spec.rb +++ b/spec/ruby/library/observer/delete_observers_spec.rb @@ -1,22 +1,19 @@ require_relative '../../spec_helper' +require_relative 'fixtures/classes' -ruby_version_is ""..."3.4" do - require_relative 'fixtures/classes' - - describe "Observer#delete_observers" do - before :each do - @observable = ObservableSpecs.new - @observer = ObserverCallbackSpecs.new - end - - it "deletes the observers" do - @observable.add_observer(@observer) - @observable.delete_observers +describe "Observer#delete_observers" do + before :each do + @observable = ObservableSpecs.new + @observer = ObserverCallbackSpecs.new + end - @observable.changed - @observable.notify_observers("test") - @observer.value.should == nil - end + it "deletes the observers" do + @observable.add_observer(@observer) + @observable.delete_observers + @observable.changed + @observable.notify_observers("test") + @observer.value.should == nil end + end diff --git a/spec/ruby/library/observer/fixtures/classes.rb b/spec/ruby/library/observer/fixtures/classes.rb index d1f9079963e..70cd1b1be27 100644 --- a/spec/ruby/library/observer/fixtures/classes.rb +++ b/spec/ruby/library/observer/fixtures/classes.rb @@ -1,19 +1,17 @@ -ruby_version_is ""..."3.4" do - require 'observer' +require 'observer' - class ObserverCallbackSpecs - attr_reader :value +class ObserverCallbackSpecs + attr_reader :value - def initialize - @value = nil - end - - def update(value) - @value = value - end + def initialize + @value = nil end - class ObservableSpecs - include Observable + def update(value) + @value = value end end + +class ObservableSpecs + include Observable +end diff --git a/spec/ruby/library/observer/notify_observers_spec.rb b/spec/ruby/library/observer/notify_observers_spec.rb index 1030ae701ec..31f82e9266d 100644 --- a/spec/ruby/library/observer/notify_observers_spec.rb +++ b/spec/ruby/library/observer/notify_observers_spec.rb @@ -1,34 +1,31 @@ require_relative '../../spec_helper' +require_relative 'fixtures/classes' -ruby_version_is ""..."3.4" do - require_relative 'fixtures/classes' +describe "Observer#notify_observers" do - describe "Observer#notify_observers" do - - before :each do - @observable = ObservableSpecs.new - @observer = ObserverCallbackSpecs.new - @observable.add_observer(@observer) - end - - it "must call changed before notifying observers" do - @observer.value.should == nil - @observable.notify_observers("test") - @observer.value.should == nil - end + before :each do + @observable = ObservableSpecs.new + @observer = ObserverCallbackSpecs.new + @observable.add_observer(@observer) + end - it "verifies observer responds to update" do - -> { - @observable.add_observer(@observable) - }.should raise_error(NoMethodError) - end + it "must call changed before notifying observers" do + @observer.value.should == nil + @observable.notify_observers("test") + @observer.value.should == nil + end - it "receives the callback" do - @observer.value.should == nil - @observable.changed - @observable.notify_observers("test") - @observer.value.should == "test" - end + it "verifies observer responds to update" do + -> { + @observable.add_observer(@observable) + }.should raise_error(NoMethodError) + end + it "receives the callback" do + @observer.value.should == nil + @observable.changed + @observable.notify_observers("test") + @observer.value.should == "test" end + end diff --git a/spec/ruby/library/prime/each_spec.rb b/spec/ruby/library/prime/each_spec.rb index c89e8715825..b99cf7cf0e0 100644 --- a/spec/ruby/library/prime/each_spec.rb +++ b/spec/ruby/library/prime/each_spec.rb @@ -1,170 +1,167 @@ require_relative '../../spec_helper' +require 'prime' -ruby_version_is ""..."3.1" do - require 'prime' - - describe :prime_each, shared: true do - before :each do - ScratchPad.record [] - end +describe :prime_each, shared: true do + before :each do + ScratchPad.record [] + end - it "enumerates primes" do - primes = Prime.instance - result = [] + it "enumerates primes" do + primes = Prime.instance + result = [] - primes.each { |p| - result << p - break if p > 10 - } + primes.each { |p| + result << p + break if p > 10 + } - result.should == [2, 3, 5, 7, 11] - end + result.should == [2, 3, 5, 7, 11] + end - it "yields ascending primes to the block" do - previous = 1 - @object.each do |prime| - break if prime > 1000 - ScratchPad << prime - prime.should > previous - previous = prime - end - - all_prime = true - ScratchPad.recorded.all? do |prime| - all_prime &&= (2..Math.sqrt(prime)).all? { |d| prime % d != 0 } - end - - all_prime.should be_true + it "yields ascending primes to the block" do + previous = 1 + @object.each do |prime| + break if prime > 1000 + ScratchPad << prime + prime.should > previous + previous = prime end - it "returns the last evaluated expression in the passed block" do - @object.each { break :value }.should equal(:value) + all_prime = true + ScratchPad.recorded.all? do |prime| + all_prime &&= (2..Math.sqrt(prime)).all? { |d| prime % d != 0 } end - describe "when not passed a block" do - before :each do - @prime_enum = @object.each - end - - it "returns an object that is Enumerable" do - @prime_enum.each.should be_kind_of(Enumerable) - end - - it "returns an object that responds to #with_index" do - @prime_enum.should respond_to(:with_index) - end + all_prime.should be_true + end - it "returns an object that responds to #with_object" do - @prime_enum.should respond_to(:with_object) - end + it "returns the last evaluated expression in the passed block" do + @object.each { break :value }.should equal(:value) + end - it "returns an object that responds to #next" do - @prime_enum.should respond_to(:next) - end + describe "when not passed a block" do + before :each do + @prime_enum = @object.each + end - it "returns an object that responds to #rewind" do - @prime_enum.should respond_to(:rewind) - end + it "returns an object that is Enumerable" do + @prime_enum.each.should be_kind_of(Enumerable) + end - it "yields primes starting at 2 independent of prior enumerators" do - @prime_enum.next.should == 2 - @prime_enum.next.should == 3 + it "returns an object that responds to #with_index" do + @prime_enum.should respond_to(:with_index) + end - @object.each { |prime| break prime }.should == 2 - end + it "returns an object that responds to #with_object" do + @prime_enum.should respond_to(:with_object) + end - it "returns an enumerator that yields previous primes when #rewind is called" do - @prime_enum.next.should == 2 - @prime_enum.next.should == 3 - @prime_enum.rewind - @prime_enum.next.should == 2 - end + it "returns an object that responds to #next" do + @prime_enum.should respond_to(:next) + end - it "returns independent enumerators" do - enum = @object.each - enum.next.should == 2 - enum.next.should == 3 + it "returns an object that responds to #rewind" do + @prime_enum.should respond_to(:rewind) + end - @prime_enum.next.should == 2 + it "yields primes starting at 2 independent of prior enumerators" do + @prime_enum.next.should == 2 + @prime_enum.next.should == 3 - enum.next.should == 5 - end + @object.each { |prime| break prime }.should == 2 end - end - describe :prime_each_with_arguments, shared: true do - before :each do - ScratchPad.record [] + it "returns an enumerator that yields previous primes when #rewind is called" do + @prime_enum.next.should == 2 + @prime_enum.next.should == 3 + @prime_enum.rewind + @prime_enum.next.should == 2 end - it "yields ascending primes less than or equal to the argument" do - bound = 1000 - previous = 1 - @object.each(bound) do |prime| - ScratchPad << prime - prime.should > previous - previous = prime - end + it "returns independent enumerators" do + enum = @object.each + enum.next.should == 2 + enum.next.should == 3 - ScratchPad.recorded.all? do |prime| - (2..Math.sqrt(prime)).all? { |d| prime % d != 0 } - end.should be_true + @prime_enum.next.should == 2 - ScratchPad.recorded.all? { |prime| prime <= bound }.should be_true + enum.next.should == 5 end + end +end - it "returns nil when no prime is generated" do - @object.each(1) { :value }.should be_nil - end +describe :prime_each_with_arguments, shared: true do + before :each do + ScratchPad.record [] + end - it "yields primes starting at 2 independent of prior enumeration" do - @object.each(10) { |prime| prime }.should == 7 - @object.each(10) { |prime| break prime }.should == 2 + it "yields ascending primes less than or equal to the argument" do + bound = 1000 + previous = 1 + @object.each(bound) do |prime| + ScratchPad << prime + prime.should > previous + previous = prime end - it "accepts a pseudo-prime generator as the second argument" do - generator = mock('very bad pseudo-prime generator') - generator.should_receive(:upper_bound=).with(100) - generator.should_receive(:each).and_yield(2).and_yield(3).and_yield(4) - - @object.each(100, generator) { |prime| ScratchPad << prime } - ScratchPad.recorded.should == [2, 3, 4] - end + ScratchPad.recorded.all? do |prime| + (2..Math.sqrt(prime)).all? { |d| prime % d != 0 } + end.should be_true - describe "when not passed a block" do - it "returns an object that returns primes less than or equal to the bound" do - bound = 100 - @object.each(bound).all? { |prime| prime <= bound }.should be_true - end - end + ScratchPad.recorded.all? { |prime| prime <= bound }.should be_true end - describe "Prime.each" do - it_behaves_like :prime_each, :each, Prime + it "returns nil when no prime is generated" do + @object.each(1) { :value }.should be_nil end - describe "Prime.each" do - it_behaves_like :prime_each_with_arguments, :each, Prime + it "yields primes starting at 2 independent of prior enumeration" do + @object.each(10) { |prime| prime }.should == 7 + @object.each(10) { |prime| break prime }.should == 2 end - describe "Prime#each with Prime.instance" do - it_behaves_like :prime_each, :each, Prime.instance - end + it "accepts a pseudo-prime generator as the second argument" do + generator = mock('very bad pseudo-prime generator') + generator.should_receive(:upper_bound=).with(100) + generator.should_receive(:each).and_yield(2).and_yield(3).and_yield(4) - describe "Prime#each with Prime.instance" do - it_behaves_like :prime_each_with_arguments, :each, Prime.instance + @object.each(100, generator) { |prime| ScratchPad << prime } + ScratchPad.recorded.should == [2, 3, 4] end - describe "Prime#each with Prime.instance" do - before :each do - @object = Prime.instance + describe "when not passed a block" do + it "returns an object that returns primes less than or equal to the bound" do + bound = 100 + @object.each(bound).all? { |prime| prime <= bound }.should be_true end + end +end - it_behaves_like :prime_each, :each +describe "Prime.each" do + it_behaves_like :prime_each, :each, Prime +end - it "resets the enumerator with each call" do - @object.each { |prime| break if prime > 10 } - @object.each { |prime| break prime }.should == 2 - end +describe "Prime.each" do + it_behaves_like :prime_each_with_arguments, :each, Prime +end + +describe "Prime#each with Prime.instance" do + it_behaves_like :prime_each, :each, Prime.instance +end + +describe "Prime#each with Prime.instance" do + it_behaves_like :prime_each_with_arguments, :each, Prime.instance +end + +describe "Prime#each with Prime.instance" do + before :each do + @object = Prime.instance + end + + it_behaves_like :prime_each, :each + + it "resets the enumerator with each call" do + @object.each { |prime| break if prime > 10 } + @object.each { |prime| break prime }.should == 2 end end diff --git a/spec/ruby/library/prime/instance_spec.rb b/spec/ruby/library/prime/instance_spec.rb index 82f21913b79..5183f369018 100644 --- a/spec/ruby/library/prime/instance_spec.rb +++ b/spec/ruby/library/prime/instance_spec.rb @@ -1,24 +1,21 @@ require_relative '../../spec_helper' +require 'prime' -ruby_version_is ""..."3.1" do - require 'prime' - - describe "Prime.instance" do - it "returns a object representing the set of prime numbers" do - Prime.instance.should be_kind_of(Prime) - end +describe "Prime.instance" do + it "returns a object representing the set of prime numbers" do + Prime.instance.should be_kind_of(Prime) + end - it "returns a object with no obsolete features" do - Prime.instance.should_not respond_to(:succ) - Prime.instance.should_not respond_to(:next) - end + it "returns a object with no obsolete features" do + Prime.instance.should_not respond_to(:succ) + Prime.instance.should_not respond_to(:next) + end - it "does not complain anything" do - -> { Prime.instance }.should_not complain - end + it "does not complain anything" do + -> { Prime.instance }.should_not complain + end - it "raises a ArgumentError when is called with some arguments" do - -> { Prime.instance(1) }.should raise_error(ArgumentError) - end + it "raises a ArgumentError when is called with some arguments" do + -> { Prime.instance(1) }.should raise_error(ArgumentError) end end diff --git a/spec/ruby/library/prime/int_from_prime_division_spec.rb b/spec/ruby/library/prime/int_from_prime_division_spec.rb index 5c881aefa14..5abb7221df3 100644 --- a/spec/ruby/library/prime/int_from_prime_division_spec.rb +++ b/spec/ruby/library/prime/int_from_prime_division_spec.rb @@ -1,16 +1,13 @@ require_relative '../../spec_helper' +require 'prime' -ruby_version_is ""..."3.1" do - require 'prime' - - describe "Prime.int_from_prime_division" do - it "returns the product of the given factorization" do - Prime.int_from_prime_division([[2,3], [3,3], [5,3], [7,3], [11,3], [13,3], [17,3]]). - should == 2**3 * 3**3 * 5**3 * 7**3 * 11**3 * 13**3 * 17**3 - end +describe "Prime.int_from_prime_division" do + it "returns the product of the given factorization" do + Prime.int_from_prime_division([[2,3], [3,3], [5,3], [7,3], [11,3], [13,3], [17,3]]). + should == 2**3 * 3**3 * 5**3 * 7**3 * 11**3 * 13**3 * 17**3 + end - it "returns 1 for an empty factorization" do - Prime.int_from_prime_division([]).should == 1 - end + it "returns 1 for an empty factorization" do + Prime.int_from_prime_division([]).should == 1 end end diff --git a/spec/ruby/library/prime/integer/each_prime_spec.rb b/spec/ruby/library/prime/integer/each_prime_spec.rb index 6034802e730..a71296b0df3 100644 --- a/spec/ruby/library/prime/integer/each_prime_spec.rb +++ b/spec/ruby/library/prime/integer/each_prime_spec.rb @@ -1,16 +1,13 @@ require_relative '../../../spec_helper' +require 'prime' -ruby_version_is ""..."3.1" do - require 'prime' - - describe "Integer.each_prime" do - it "is transferred to Prime.each" do - Prime.should_receive(:each).with(100).and_yield(2).and_yield(3).and_yield(5) - yielded = [] - Integer.each_prime(100) do |prime| - yielded << prime - end - yielded.should == [2,3,5] +describe "Integer.each_prime" do + it "is transferred to Prime.each" do + Prime.should_receive(:each).with(100).and_yield(2).and_yield(3).and_yield(5) + yielded = [] + Integer.each_prime(100) do |prime| + yielded << prime end + yielded.should == [2,3,5] end end diff --git a/spec/ruby/library/prime/integer/from_prime_division_spec.rb b/spec/ruby/library/prime/integer/from_prime_division_spec.rb index 5422bc651ce..e0e74fb3369 100644 --- a/spec/ruby/library/prime/integer/from_prime_division_spec.rb +++ b/spec/ruby/library/prime/integer/from_prime_division_spec.rb @@ -1,16 +1,13 @@ require_relative '../../../spec_helper' +require 'prime' -ruby_version_is ""..."3.1" do - require 'prime' - - describe "Integer.from_prime_division" do - it "returns the product of the given factorization" do - Integer.from_prime_division([[2,3], [3,3], [5,3], [7,3], [11,3], [13,3], [17,3]]). - should == 2**3 * 3**3 * 5**3 * 7**3 * 11**3 * 13**3 * 17**3 - end +describe "Integer.from_prime_division" do + it "returns the product of the given factorization" do + Integer.from_prime_division([[2,3], [3,3], [5,3], [7,3], [11,3], [13,3], [17,3]]). + should == 2**3 * 3**3 * 5**3 * 7**3 * 11**3 * 13**3 * 17**3 + end - it "returns 1 for an empty factorization" do - Integer.from_prime_division([]).should == 1 - end + it "returns 1 for an empty factorization" do + Integer.from_prime_division([]).should == 1 end end diff --git a/spec/ruby/library/prime/integer/prime_division_spec.rb b/spec/ruby/library/prime/integer/prime_division_spec.rb index 03be0be27b7..be03438a6f8 100644 --- a/spec/ruby/library/prime/integer/prime_division_spec.rb +++ b/spec/ruby/library/prime/integer/prime_division_spec.rb @@ -1,22 +1,19 @@ require_relative '../../../spec_helper' +require 'prime' -ruby_version_is ""..."3.1" do - require 'prime' - - describe "Integer#prime_division" do - it "returns an array of a prime factor and a corresponding exponent" do - (2*3*5*7*11*13*17).prime_division.should == - [[2,1], [3,1], [5,1], [7,1], [11,1], [13,1], [17,1]] - end +describe "Integer#prime_division" do + it "returns an array of a prime factor and a corresponding exponent" do + (2*3*5*7*11*13*17).prime_division.should == + [[2,1], [3,1], [5,1], [7,1], [11,1], [13,1], [17,1]] + end - it "returns an empty array for 1" do - 1.prime_division.should == [] - end - it "returns an empty array for -1" do - -1.prime_division.should == [[-1, 1]] - end - it "raises ZeroDivisionError for 0" do - -> { 0.prime_division }.should raise_error(ZeroDivisionError) - end + it "returns an empty array for 1" do + 1.prime_division.should == [] + end + it "returns an empty array for -1" do + -1.prime_division.should == [[-1, 1]] + end + it "raises ZeroDivisionError for 0" do + -> { 0.prime_division }.should raise_error(ZeroDivisionError) end end diff --git a/spec/ruby/library/prime/integer/prime_spec.rb b/spec/ruby/library/prime/integer/prime_spec.rb index 65b779e3191..53de76d5ab3 100644 --- a/spec/ruby/library/prime/integer/prime_spec.rb +++ b/spec/ruby/library/prime/integer/prime_spec.rb @@ -1,20 +1,17 @@ require_relative '../../../spec_helper' +require 'prime' -ruby_version_is ""..."3.1" do - require 'prime' - - describe "Integer#prime?" do - it "returns a true value for prime numbers" do - 2.prime?.should be_true - 3.prime?.should be_true - (2**31-1).prime?.should be_true # 8th Mersenne prime (M8) - end +describe "Integer#prime?" do + it "returns a true value for prime numbers" do + 2.prime?.should be_true + 3.prime?.should be_true + (2**31-1).prime?.should be_true # 8th Mersenne prime (M8) + end - it "returns a false value for composite numbers" do - 4.prime?.should be_false - 15.prime?.should be_false - (2**32-1).prime?.should be_false - ( (2**17-1)*(2**19-1) ).prime?.should be_false # M6*M7 - end + it "returns a false value for composite numbers" do + 4.prime?.should be_false + 15.prime?.should be_false + (2**32-1).prime?.should be_false + ( (2**17-1)*(2**19-1) ).prime?.should be_false # M6*M7 end end diff --git a/spec/ruby/library/prime/next_spec.rb b/spec/ruby/library/prime/next_spec.rb index 8e805ed0440..39c4ae16ae8 100644 --- a/spec/ruby/library/prime/next_spec.rb +++ b/spec/ruby/library/prime/next_spec.rb @@ -1,10 +1,7 @@ require_relative '../../spec_helper' +require_relative 'shared/next' +require 'prime' -ruby_version_is ""..."3.1" do - require_relative 'shared/next' - require 'prime' - - describe "Prime#next" do - it_behaves_like :prime_next, :next - end +describe "Prime#next" do + it_behaves_like :prime_next, :next end diff --git a/spec/ruby/library/prime/prime_division_spec.rb b/spec/ruby/library/prime/prime_division_spec.rb index 4c93d5936a9..6293478f592 100644 --- a/spec/ruby/library/prime/prime_division_spec.rb +++ b/spec/ruby/library/prime/prime_division_spec.rb @@ -1,28 +1,25 @@ require_relative '../../spec_helper' +require 'prime' -ruby_version_is ""..."3.1" do - require 'prime' - - describe "Prime.prime_division" do - it "returns an array of a prime factor and a corresponding exponent" do - Prime.prime_division(2*3*5*7*11*13*17).should == - [[2,1], [3,1], [5,1], [7,1], [11,1], [13,1], [17,1]] - end +describe "Prime.prime_division" do + it "returns an array of a prime factor and a corresponding exponent" do + Prime.prime_division(2*3*5*7*11*13*17).should == + [[2,1], [3,1], [5,1], [7,1], [11,1], [13,1], [17,1]] + end - it "returns an empty array for 1" do - Prime.prime_division(1).should == [] - end + it "returns an empty array for 1" do + Prime.prime_division(1).should == [] + end - it "returns [[-1, 1]] for -1" do - Prime.prime_division(-1).should == [[-1, 1]] - end + it "returns [[-1, 1]] for -1" do + Prime.prime_division(-1).should == [[-1, 1]] + end - it "includes [[-1, 1]] in the divisors of a negative number" do - Prime.prime_division(-10).should include([-1, 1]) - end + it "includes [[-1, 1]] in the divisors of a negative number" do + Prime.prime_division(-10).should include([-1, 1]) + end - it "raises ZeroDivisionError for 0" do - -> { Prime.prime_division(0) }.should raise_error(ZeroDivisionError) - end + it "raises ZeroDivisionError for 0" do + -> { Prime.prime_division(0) }.should raise_error(ZeroDivisionError) end end diff --git a/spec/ruby/library/prime/prime_spec.rb b/spec/ruby/library/prime/prime_spec.rb index e2afddd5b28..0896c7f0f39 100644 --- a/spec/ruby/library/prime/prime_spec.rb +++ b/spec/ruby/library/prime/prime_spec.rb @@ -1,20 +1,17 @@ require_relative '../../spec_helper' +require 'prime' -ruby_version_is ""..."3.1" do - require 'prime' - - describe "Prime#prime?" do - it "returns a true value for prime numbers" do - Prime.prime?(2).should be_true - Prime.prime?(3).should be_true - Prime.prime?(2**31-1).should be_true # 8th Mersenne prime (M8) - end +describe "Prime#prime?" do + it "returns a true value for prime numbers" do + Prime.prime?(2).should be_true + Prime.prime?(3).should be_true + Prime.prime?(2**31-1).should be_true # 8th Mersenne prime (M8) + end - it "returns a false value for composite numbers" do - Prime.prime?(4).should be_false - Prime.prime?(15).should be_false - Prime.prime?(2**32-1).should be_false - Prime.prime?( (2**17-1)*(2**19-1) ).should be_false # M6*M7 - end + it "returns a false value for composite numbers" do + Prime.prime?(4).should be_false + Prime.prime?(15).should be_false + Prime.prime?(2**32-1).should be_false + Prime.prime?( (2**17-1)*(2**19-1) ).should be_false # M6*M7 end end diff --git a/spec/ruby/library/prime/succ_spec.rb b/spec/ruby/library/prime/succ_spec.rb index 9843dae25dc..34c18d2ba06 100644 --- a/spec/ruby/library/prime/succ_spec.rb +++ b/spec/ruby/library/prime/succ_spec.rb @@ -1,10 +1,7 @@ require_relative '../../spec_helper' +require_relative 'shared/next' +require 'prime' -ruby_version_is ""..."3.1" do - require_relative 'shared/next' - require 'prime' - - describe "Prime#succ" do - it_behaves_like :prime_next, :succ - end +describe "Prime#succ" do + it_behaves_like :prime_next, :succ end diff --git a/spec/ruby/library/set/set_spec.rb b/spec/ruby/library/set/set_spec.rb new file mode 100644 index 00000000000..2a4edc6dfc6 --- /dev/null +++ b/spec/ruby/library/set/set_spec.rb @@ -0,0 +1,12 @@ +require_relative '../../spec_helper' + +describe 'Set' do + ruby_version_is '3.2' do + it 'is available without explicit requiring' do + output = ruby_exe(<<~RUBY, options: '--disable-gems', args: '2>&1') + puts Set.new([1, 2, 3]) + RUBY + output.chomp.should == "#" + end + end +end diff --git a/spec/ruby/library/socket/tcpserver/accept_spec.rb b/spec/ruby/library/socket/tcpserver/accept_spec.rb index 8f1f0016f0c..d8892cd5f06 100644 --- a/spec/ruby/library/socket/tcpserver/accept_spec.rb +++ b/spec/ruby/library/socket/tcpserver/accept_spec.rb @@ -69,7 +69,7 @@ Thread.pass while t.status and t.status != "sleep" # Thread#backtrace uses SIGVTALRM on TruffleRuby and potentially other implementations. # Sending a signal to a thread is not possible with Ruby APIs. - t.backtrace.join("\n").should.include?("in `accept'") + t.backtrace.join("\n").should =~ /in [`'](?:TCPServer#)?accept'/ socket = TCPSocket.new('127.0.0.1', @port) socket.write("OK") diff --git a/spec/ruby/library/syslog/alert_spec.rb b/spec/ruby/library/syslog/alert_spec.rb index a3a616bd6d8..edff789dc96 100644 --- a/spec/ruby/library/syslog/alert_spec.rb +++ b/spec/ruby/library/syslog/alert_spec.rb @@ -1,13 +1,10 @@ require_relative '../../spec_helper' -ruby_version_is ""..."3.4" do +platform_is_not :windows do + require_relative 'shared/log' + require 'syslog' - platform_is_not :windows do - require_relative 'shared/log' - require 'syslog' - - describe "Syslog.alert" do - it_behaves_like :syslog_log, :alert - end + describe "Syslog.alert" do + it_behaves_like :syslog_log, :alert end end diff --git a/spec/ruby/library/syslog/close_spec.rb b/spec/ruby/library/syslog/close_spec.rb index 60866de9715..8c3b67c05bd 100644 --- a/spec/ruby/library/syslog/close_spec.rb +++ b/spec/ruby/library/syslog/close_spec.rb @@ -1,60 +1,57 @@ require_relative '../../spec_helper' -ruby_version_is ""..."3.4" do - - platform_is_not :windows do - require 'syslog' - - describe "Syslog.close" do - platform_is_not :windows do - - before :each do - Syslog.opened?.should be_false - end - - after :each do - Syslog.opened?.should be_false - end - - it "closes the log" do - Syslog.opened?.should be_false - Syslog.open - Syslog.opened?.should be_true - Syslog.close - Syslog.opened?.should be_false - end - - it "raises a RuntimeError if the log's already closed" do - -> { Syslog.close }.should raise_error(RuntimeError) - end - - it "it does not work inside blocks" do - -> { - Syslog.open { |s| s.close } - }.should raise_error(RuntimeError) - Syslog.should_not.opened? - end - - it "sets the identity to nil" do - Syslog.open("rubyspec") - Syslog.ident.should == "rubyspec" - Syslog.close - Syslog.ident.should be_nil - end - - it "sets the options to nil" do - Syslog.open("rubyspec", Syslog::LOG_PID) - Syslog.options.should == Syslog::LOG_PID - Syslog.close - Syslog.options.should == nil - end - - it "sets the facility to nil" do - Syslog.open - Syslog.facility.should == 8 - Syslog.close - Syslog.facility.should == nil - end +platform_is_not :windows do + require 'syslog' + + describe "Syslog.close" do + platform_is_not :windows do + + before :each do + Syslog.opened?.should be_false + end + + after :each do + Syslog.opened?.should be_false + end + + it "closes the log" do + Syslog.opened?.should be_false + Syslog.open + Syslog.opened?.should be_true + Syslog.close + Syslog.opened?.should be_false + end + + it "raises a RuntimeError if the log's already closed" do + -> { Syslog.close }.should raise_error(RuntimeError) + end + + it "it does not work inside blocks" do + -> { + Syslog.open { |s| s.close } + }.should raise_error(RuntimeError) + Syslog.should_not.opened? + end + + it "sets the identity to nil" do + Syslog.open("rubyspec") + Syslog.ident.should == "rubyspec" + Syslog.close + Syslog.ident.should be_nil + end + + it "sets the options to nil" do + Syslog.open("rubyspec", Syslog::LOG_PID) + Syslog.options.should == Syslog::LOG_PID + Syslog.close + Syslog.options.should == nil + end + + it "sets the facility to nil" do + Syslog.open + Syslog.facility.should == 8 + Syslog.close + Syslog.facility.should == nil end end end diff --git a/spec/ruby/library/syslog/constants_spec.rb b/spec/ruby/library/syslog/constants_spec.rb index d44d67e2de8..2b9524c53d8 100644 --- a/spec/ruby/library/syslog/constants_spec.rb +++ b/spec/ruby/library/syslog/constants_spec.rb @@ -1,43 +1,40 @@ require_relative '../../spec_helper' -ruby_version_is ""..."3.4" do +platform_is_not :windows do + require 'syslog' - platform_is_not :windows do - require 'syslog' - - describe "Syslog::Constants" do - platform_is_not :windows, :solaris, :aix do - before :all do - @constants = %w(LOG_AUTHPRIV LOG_USER LOG_LOCAL2 LOG_NOTICE LOG_NDELAY - LOG_SYSLOG LOG_ALERT LOG_FTP LOG_LOCAL5 LOG_ERR LOG_AUTH - LOG_LOCAL1 LOG_ODELAY LOG_NEWS LOG_DAEMON LOG_LOCAL4 - LOG_CRIT LOG_INFO LOG_PERROR LOG_LOCAL0 LOG_CONS LOG_LPR - LOG_LOCAL7 LOG_WARNING LOG_CRON LOG_LOCAL3 LOG_EMERG - LOG_NOWAIT LOG_UUCP LOG_PID LOG_KERN LOG_MAIL LOG_LOCAL6 - LOG_DEBUG) - end + describe "Syslog::Constants" do + platform_is_not :windows, :solaris, :aix do + before :all do + @constants = %w(LOG_AUTHPRIV LOG_USER LOG_LOCAL2 LOG_NOTICE LOG_NDELAY + LOG_SYSLOG LOG_ALERT LOG_FTP LOG_LOCAL5 LOG_ERR LOG_AUTH + LOG_LOCAL1 LOG_ODELAY LOG_NEWS LOG_DAEMON LOG_LOCAL4 + LOG_CRIT LOG_INFO LOG_PERROR LOG_LOCAL0 LOG_CONS LOG_LPR + LOG_LOCAL7 LOG_WARNING LOG_CRON LOG_LOCAL3 LOG_EMERG + LOG_NOWAIT LOG_UUCP LOG_PID LOG_KERN LOG_MAIL LOG_LOCAL6 + LOG_DEBUG) + end - it "includes the Syslog constants" do - @constants.each do |c| - Syslog::Constants.should have_constant(c) - end + it "includes the Syslog constants" do + @constants.each do |c| + Syslog::Constants.should have_constant(c) end end + end - # The masks are defined in + # The masks are defined in - describe "Syslog::Constants.LOG_MASK" do - it "returns the mask value for a priority" do - Syslog::Constants.LOG_MASK(Syslog::LOG_DEBUG).should == 128 - Syslog::Constants.LOG_MASK(Syslog::LOG_WARNING).should == 16 - end + describe "Syslog::Constants.LOG_MASK" do + it "returns the mask value for a priority" do + Syslog::Constants.LOG_MASK(Syslog::LOG_DEBUG).should == 128 + Syslog::Constants.LOG_MASK(Syslog::LOG_WARNING).should == 16 end + end - describe "Syslog::Constants.LOG_UPTO" do - it "returns a mask for the priorities up to a given argument" do - Syslog::Constants.LOG_UPTO(Syslog::LOG_ALERT).should == 3 - Syslog::Constants.LOG_UPTO(Syslog::LOG_DEBUG).should == 255 - end + describe "Syslog::Constants.LOG_UPTO" do + it "returns a mask for the priorities up to a given argument" do + Syslog::Constants.LOG_UPTO(Syslog::LOG_ALERT).should == 3 + Syslog::Constants.LOG_UPTO(Syslog::LOG_DEBUG).should == 255 end end end diff --git a/spec/ruby/library/syslog/crit_spec.rb b/spec/ruby/library/syslog/crit_spec.rb index d7841ac0102..5d3904f7196 100644 --- a/spec/ruby/library/syslog/crit_spec.rb +++ b/spec/ruby/library/syslog/crit_spec.rb @@ -1,13 +1,10 @@ require_relative '../../spec_helper' -ruby_version_is ""..."3.4" do +platform_is_not :windows do + require_relative 'shared/log' + require 'syslog' - platform_is_not :windows do - require_relative 'shared/log' - require 'syslog' - - describe "Syslog.crit" do - it_behaves_like :syslog_log, :crit - end + describe "Syslog.crit" do + it_behaves_like :syslog_log, :crit end end diff --git a/spec/ruby/library/syslog/debug_spec.rb b/spec/ruby/library/syslog/debug_spec.rb index 94e640c7413..d03e8a88c9f 100644 --- a/spec/ruby/library/syslog/debug_spec.rb +++ b/spec/ruby/library/syslog/debug_spec.rb @@ -1,13 +1,10 @@ require_relative '../../spec_helper' -ruby_version_is ""..."3.4" do +platform_is_not :windows do + require_relative 'shared/log' + require 'syslog' - platform_is_not :windows do - require_relative 'shared/log' - require 'syslog' - - describe "Syslog.debug" do - it_behaves_like :syslog_log, :debug - end + describe "Syslog.debug" do + it_behaves_like :syslog_log, :debug end end diff --git a/spec/ruby/library/syslog/emerg_spec.rb b/spec/ruby/library/syslog/emerg_spec.rb index 86938ce8897..2ab4d60291c 100644 --- a/spec/ruby/library/syslog/emerg_spec.rb +++ b/spec/ruby/library/syslog/emerg_spec.rb @@ -1,19 +1,16 @@ require_relative '../../spec_helper' -ruby_version_is ""..."3.4" do +platform_is_not :windows do + require_relative 'shared/log' + require 'syslog' - platform_is_not :windows do - require_relative 'shared/log' - require 'syslog' - - describe "Syslog.emerg" do - # Some way needs do be found to prevent this spec - # from causing output on all open terminals. If this - # is not possible, this spec may need a special guard - # that only runs when requested. - quarantine! do - it_behaves_like :syslog_log, :emerg - end + describe "Syslog.emerg" do + # Some way needs do be found to prevent this spec + # from causing output on all open terminals. If this + # is not possible, this spec may need a special guard + # that only runs when requested. + quarantine! do + it_behaves_like :syslog_log, :emerg end end end diff --git a/spec/ruby/library/syslog/err_spec.rb b/spec/ruby/library/syslog/err_spec.rb index a7b39ea5c0a..43e876ed378 100644 --- a/spec/ruby/library/syslog/err_spec.rb +++ b/spec/ruby/library/syslog/err_spec.rb @@ -1,13 +1,10 @@ require_relative '../../spec_helper' -ruby_version_is ""..."3.4" do +platform_is_not :windows do + require_relative 'shared/log' + require 'syslog' - platform_is_not :windows do - require_relative 'shared/log' - require 'syslog' - - describe "Syslog.err" do - it_behaves_like :syslog_log, :err - end + describe "Syslog.err" do + it_behaves_like :syslog_log, :err end end diff --git a/spec/ruby/library/syslog/facility_spec.rb b/spec/ruby/library/syslog/facility_spec.rb index 1129dd9ee3e..550ca70b112 100644 --- a/spec/ruby/library/syslog/facility_spec.rb +++ b/spec/ruby/library/syslog/facility_spec.rb @@ -1,50 +1,47 @@ require_relative '../../spec_helper' -ruby_version_is ""..."3.4" do - - platform_is_not :windows do - require 'syslog' - - describe "Syslog.facility" do - platform_is_not :windows do - - before :each do - Syslog.opened?.should be_false - end - - after :each do - Syslog.opened?.should be_false - end - - it "returns the logging facility" do - Syslog.open("rubyspec", 3, Syslog::LOG_MAIL) - Syslog.facility.should == Syslog::LOG_MAIL - Syslog.close - end - - it "returns nil if the log is closed" do - Syslog.opened?.should be_false - Syslog.facility.should == nil - end - - it "defaults to LOG_USER" do - Syslog.open - Syslog.facility.should == Syslog::LOG_USER - Syslog.close - end - - it "resets after each open call" do - Syslog.open - Syslog.facility.should == Syslog::LOG_USER - - Syslog.open!("rubyspec", 3, Syslog::LOG_MAIL) - Syslog.facility.should == Syslog::LOG_MAIL - Syslog.close - - Syslog.open - Syslog.facility.should == Syslog::LOG_USER - Syslog.close - end +platform_is_not :windows do + require 'syslog' + + describe "Syslog.facility" do + platform_is_not :windows do + + before :each do + Syslog.opened?.should be_false + end + + after :each do + Syslog.opened?.should be_false + end + + it "returns the logging facility" do + Syslog.open("rubyspec", 3, Syslog::LOG_MAIL) + Syslog.facility.should == Syslog::LOG_MAIL + Syslog.close + end + + it "returns nil if the log is closed" do + Syslog.opened?.should be_false + Syslog.facility.should == nil + end + + it "defaults to LOG_USER" do + Syslog.open + Syslog.facility.should == Syslog::LOG_USER + Syslog.close + end + + it "resets after each open call" do + Syslog.open + Syslog.facility.should == Syslog::LOG_USER + + Syslog.open!("rubyspec", 3, Syslog::LOG_MAIL) + Syslog.facility.should == Syslog::LOG_MAIL + Syslog.close + + Syslog.open + Syslog.facility.should == Syslog::LOG_USER + Syslog.close end end end diff --git a/spec/ruby/library/syslog/ident_spec.rb b/spec/ruby/library/syslog/ident_spec.rb index 524e5603738..3b083271406 100644 --- a/spec/ruby/library/syslog/ident_spec.rb +++ b/spec/ruby/library/syslog/ident_spec.rb @@ -1,37 +1,34 @@ require_relative '../../spec_helper' -ruby_version_is ""..."3.4" do +platform_is_not :windows do + require 'syslog' - platform_is_not :windows do - require 'syslog' + describe "Syslog.ident" do + platform_is_not :windows do - describe "Syslog.ident" do - platform_is_not :windows do - - before :each do - Syslog.opened?.should be_false - end + before :each do + Syslog.opened?.should be_false + end - after :each do - Syslog.opened?.should be_false - end + after :each do + Syslog.opened?.should be_false + end - it "returns the logging identity" do - Syslog.open("rubyspec") - Syslog.ident.should == "rubyspec" - Syslog.close - end + it "returns the logging identity" do + Syslog.open("rubyspec") + Syslog.ident.should == "rubyspec" + Syslog.close + end - it "returns nil if the log is closed" do - Syslog.should_not.opened? - Syslog.ident.should == nil - end + it "returns nil if the log is closed" do + Syslog.should_not.opened? + Syslog.ident.should == nil + end - it "defaults to $0" do - Syslog.open - Syslog.ident.should == $0 - Syslog.close - end + it "defaults to $0" do + Syslog.open + Syslog.ident.should == $0 + Syslog.close end end end diff --git a/spec/ruby/library/syslog/info_spec.rb b/spec/ruby/library/syslog/info_spec.rb index 03bb6f6003b..f2d535299c5 100644 --- a/spec/ruby/library/syslog/info_spec.rb +++ b/spec/ruby/library/syslog/info_spec.rb @@ -1,13 +1,10 @@ require_relative '../../spec_helper' -ruby_version_is ""..."3.4" do +platform_is_not :windows do + require_relative 'shared/log' + require 'syslog' - platform_is_not :windows do - require_relative 'shared/log' - require 'syslog' - - describe "Syslog.info" do - it_behaves_like :syslog_log, :info - end + describe "Syslog.info" do + it_behaves_like :syslog_log, :info end end diff --git a/spec/ruby/library/syslog/inspect_spec.rb b/spec/ruby/library/syslog/inspect_spec.rb index 5e1e09e86fc..f45231f8e31 100644 --- a/spec/ruby/library/syslog/inspect_spec.rb +++ b/spec/ruby/library/syslog/inspect_spec.rb @@ -1,41 +1,38 @@ require_relative '../../spec_helper' -ruby_version_is ""..."3.4" do +platform_is_not :windows do + require 'syslog' - platform_is_not :windows do - require 'syslog' + describe "Syslog.inspect" do + platform_is_not :windows do - describe "Syslog.inspect" do - platform_is_not :windows do - - before :each do - Syslog.opened?.should be_false - end + before :each do + Syslog.opened?.should be_false + end - after :each do - Syslog.opened?.should be_false - end + after :each do + Syslog.opened?.should be_false + end - it "returns a string a closed log" do - Syslog.inspect.should =~ /opened=false/ - end + it "returns a string a closed log" do + Syslog.inspect.should =~ /opened=false/ + end - it "returns a string for an opened log" do - Syslog.open - Syslog.inspect.should =~ /opened=true.*/ - Syslog.close - end + it "returns a string for an opened log" do + Syslog.open + Syslog.inspect.should =~ /opened=true.*/ + Syslog.close + end - it "includes the ident, options, facility and mask" do - Syslog.open("rubyspec", Syslog::LOG_PID, Syslog::LOG_USER) - inspect_str = Syslog.inspect.split ", " - inspect_str[0].should =~ /opened=true/ - inspect_str[1].should == "ident=\"rubyspec\"" - inspect_str[2].should == "options=#{Syslog::LOG_PID}" - inspect_str[3].should == "facility=#{Syslog::LOG_USER}" - inspect_str[4].should == "mask=255>" - Syslog.close - end + it "includes the ident, options, facility and mask" do + Syslog.open("rubyspec", Syslog::LOG_PID, Syslog::LOG_USER) + inspect_str = Syslog.inspect.split ", " + inspect_str[0].should =~ /opened=true/ + inspect_str[1].should == "ident=\"rubyspec\"" + inspect_str[2].should == "options=#{Syslog::LOG_PID}" + inspect_str[3].should == "facility=#{Syslog::LOG_USER}" + inspect_str[4].should == "mask=255>" + Syslog.close end end end diff --git a/spec/ruby/library/syslog/instance_spec.rb b/spec/ruby/library/syslog/instance_spec.rb index b7a7d122f09..891296c52d1 100644 --- a/spec/ruby/library/syslog/instance_spec.rb +++ b/spec/ruby/library/syslog/instance_spec.rb @@ -1,15 +1,12 @@ require_relative '../../spec_helper' -ruby_version_is ""..."3.4" do +platform_is_not :windows do + require 'syslog' - platform_is_not :windows do - require 'syslog' - - describe "Syslog.instance" do - platform_is_not :windows do - it "returns the module" do - Syslog.instance.should == Syslog - end + describe "Syslog.instance" do + platform_is_not :windows do + it "returns the module" do + Syslog.instance.should == Syslog end end end diff --git a/spec/ruby/library/syslog/log_spec.rb b/spec/ruby/library/syslog/log_spec.rb index 749d825c104..8589fb1f733 100644 --- a/spec/ruby/library/syslog/log_spec.rb +++ b/spec/ruby/library/syslog/log_spec.rb @@ -1,58 +1,55 @@ require_relative '../../spec_helper' -ruby_version_is ""..."3.4" do +platform_is_not :windows do + require 'syslog' - platform_is_not :windows do - require 'syslog' + describe "Syslog.log" do + platform_is_not :windows, :darwin, :solaris, :aix, :android do - describe "Syslog.log" do - platform_is_not :windows, :darwin, :solaris, :aix, :android do - - before :each do - Syslog.opened?.should be_false - end - - after :each do - Syslog.opened?.should be_false - end + before :each do + Syslog.opened?.should be_false + end - it "receives a priority as first argument" do - -> { - Syslog.open("rubyspec", Syslog::LOG_PERROR) do |s| - s.log(Syslog::LOG_ALERT, "Hello") - s.log(Syslog::LOG_CRIT, "World") - end - }.should output_to_fd(/\Arubyspec(?::| \d+ - -) Hello\nrubyspec(?::| \d+ - -) World\n\z/, $stderr) - end + after :each do + Syslog.opened?.should be_false + end - it "accepts undefined priorities" do - -> { - Syslog.open("rubyspec", Syslog::LOG_PERROR) do |s| - s.log(1337, "Hello") - end - # use a regex since it'll output unknown facility/priority messages - }.should output_to_fd(/rubyspec(?::| \d+ - -) Hello\n\z/, $stderr) - end + it "receives a priority as first argument" do + -> { + Syslog.open("rubyspec", Syslog::LOG_PERROR) do |s| + s.log(Syslog::LOG_ALERT, "Hello") + s.log(Syslog::LOG_CRIT, "World") + end + }.should output_to_fd(/\Arubyspec(?::| \d+ - -) Hello\nrubyspec(?::| \d+ - -) World\n\z/, $stderr) + end - it "fails with TypeError on nil log messages" do - Syslog.open do |s| - -> { s.log(1, nil) }.should raise_error(TypeError) + it "accepts undefined priorities" do + -> { + Syslog.open("rubyspec", Syslog::LOG_PERROR) do |s| + s.log(1337, "Hello") end - end + # use a regex since it'll output unknown facility/priority messages + }.should output_to_fd(/rubyspec(?::| \d+ - -) Hello\n\z/, $stderr) + end - it "fails if the log is closed" do - -> { - Syslog.log(Syslog::LOG_ALERT, "test") - }.should raise_error(RuntimeError) + it "fails with TypeError on nil log messages" do + Syslog.open do |s| + -> { s.log(1, nil) }.should raise_error(TypeError) end + end - it "accepts printf parameters" do - -> { - Syslog.open("rubyspec", Syslog::LOG_PERROR) do |s| - s.log(Syslog::LOG_ALERT, "%s x %d", "chunky bacon", 2) - end - }.should output_to_fd(/rubyspec(?::| \d+ - -) chunky bacon x 2\n\z/, $stderr) - end + it "fails if the log is closed" do + -> { + Syslog.log(Syslog::LOG_ALERT, "test") + }.should raise_error(RuntimeError) + end + + it "accepts printf parameters" do + -> { + Syslog.open("rubyspec", Syslog::LOG_PERROR) do |s| + s.log(Syslog::LOG_ALERT, "%s x %d", "chunky bacon", 2) + end + }.should output_to_fd(/rubyspec(?::| \d+ - -) chunky bacon x 2\n\z/, $stderr) end end end diff --git a/spec/ruby/library/syslog/mask_spec.rb b/spec/ruby/library/syslog/mask_spec.rb index 05c64ceec89..b3f1250b24a 100644 --- a/spec/ruby/library/syslog/mask_spec.rb +++ b/spec/ruby/library/syslog/mask_spec.rb @@ -1,114 +1,111 @@ require_relative '../../spec_helper' -ruby_version_is ""..."3.4" do +platform_is_not :windows do + require 'syslog' - platform_is_not :windows do - require 'syslog' + describe "Syslog.mask" do + platform_is_not :windows do - describe "Syslog.mask" do - platform_is_not :windows do + before :each do + Syslog.opened?.should be_false + end - before :each do - Syslog.opened?.should be_false - end + after :each do + Syslog.opened?.should be_false + # make sure we return the mask to the default value + Syslog.open { |s| s.mask = 255 } + end - after :each do - Syslog.opened?.should be_false - # make sure we return the mask to the default value - Syslog.open { |s| s.mask = 255 } + it "returns the log priority mask" do + Syslog.open("rubyspec") do + Syslog.mask.should == 255 + Syslog.mask = 3 + Syslog.mask.should == 3 + Syslog.mask = 255 end + end - it "returns the log priority mask" do - Syslog.open("rubyspec") do - Syslog.mask.should == 255 - Syslog.mask = 3 - Syslog.mask.should == 3 - Syslog.mask = 255 - end + it "defaults to 255" do + Syslog.open do |s| + s.mask.should == 255 end + end - it "defaults to 255" do - Syslog.open do |s| - s.mask.should == 255 - end - end + it "returns nil if the log is closed" do + Syslog.should_not.opened? + Syslog.mask.should == nil + end - it "returns nil if the log is closed" do - Syslog.should_not.opened? - Syslog.mask.should == nil - end + platform_is :darwin do + it "resets if the log is reopened" do + Syslog.open + Syslog.mask.should == 255 + Syslog.mask = 64 - platform_is :darwin do - it "resets if the log is reopened" do - Syslog.open + Syslog.reopen("rubyspec") do Syslog.mask.should == 255 - Syslog.mask = 64 - - Syslog.reopen("rubyspec") do - Syslog.mask.should == 255 - end + end - Syslog.open do - Syslog.mask.should == 255 - end + Syslog.open do + Syslog.mask.should == 255 end end + end - platform_is_not :darwin do - it "persists if the log is reopened" do - Syslog.open - Syslog.mask.should == 255 - Syslog.mask = 64 + platform_is_not :darwin do + it "persists if the log is reopened" do + Syslog.open + Syslog.mask.should == 255 + Syslog.mask = 64 - Syslog.reopen("rubyspec") do - Syslog.mask.should == 64 - end + Syslog.reopen("rubyspec") do + Syslog.mask.should == 64 + end - Syslog.open do - Syslog.mask.should == 64 - end + Syslog.open do + Syslog.mask.should == 64 end end end end + end - describe "Syslog.mask=" do - platform_is_not :windows do + describe "Syslog.mask=" do + platform_is_not :windows do - before :each do - Syslog.opened?.should be_false - end + before :each do + Syslog.opened?.should be_false + end - after :each do - Syslog.opened?.should be_false - # make sure we return the mask to the default value - Syslog.open { |s| s.mask = 255 } - end + after :each do + Syslog.opened?.should be_false + # make sure we return the mask to the default value + Syslog.open { |s| s.mask = 255 } + end - it "sets the log priority mask" do - Syslog.open do - Syslog.mask = 64 - Syslog.mask.should == 64 - end + it "sets the log priority mask" do + Syslog.open do + Syslog.mask = 64 + Syslog.mask.should == 64 end + end - it "raises an error if the log is closed" do - -> { Syslog.mask = 1337 }.should raise_error(RuntimeError) - end + it "raises an error if the log is closed" do + -> { Syslog.mask = 1337 }.should raise_error(RuntimeError) + end - it "only accepts numbers" do - Syslog.open do + it "only accepts numbers" do + Syslog.open do - Syslog.mask = 1337 - Syslog.mask.should == 1337 + Syslog.mask = 1337 + Syslog.mask.should == 1337 - Syslog.mask = 3.1416 - Syslog.mask.should == 3 + Syslog.mask = 3.1416 + Syslog.mask.should == 3 - -> { Syslog.mask = "oh hai" }.should raise_error(TypeError) - -> { Syslog.mask = "43" }.should raise_error(TypeError) + -> { Syslog.mask = "oh hai" }.should raise_error(TypeError) + -> { Syslog.mask = "43" }.should raise_error(TypeError) - end end end end diff --git a/spec/ruby/library/syslog/notice_spec.rb b/spec/ruby/library/syslog/notice_spec.rb index 41c175cb49f..a2134e0140f 100644 --- a/spec/ruby/library/syslog/notice_spec.rb +++ b/spec/ruby/library/syslog/notice_spec.rb @@ -1,13 +1,10 @@ require_relative '../../spec_helper' -ruby_version_is ""..."3.4" do +platform_is_not :windows do + require_relative 'shared/log' + require 'syslog' - platform_is_not :windows do - require_relative 'shared/log' - require 'syslog' - - describe "Syslog.notice" do - it_behaves_like :syslog_log, :notice - end + describe "Syslog.notice" do + it_behaves_like :syslog_log, :notice end end diff --git a/spec/ruby/library/syslog/open_spec.rb b/spec/ruby/library/syslog/open_spec.rb index 9cd65cda4a1..543f5d418b3 100644 --- a/spec/ruby/library/syslog/open_spec.rb +++ b/spec/ruby/library/syslog/open_spec.rb @@ -1,95 +1,92 @@ require_relative '../../spec_helper' -ruby_version_is ""..."3.4" do +platform_is_not :windows do + require_relative 'shared/reopen' + require 'syslog' - platform_is_not :windows do - require_relative 'shared/reopen' - require 'syslog' + describe "Syslog.open" do + platform_is_not :windows do - describe "Syslog.open" do - platform_is_not :windows do - - before :each do - Syslog.opened?.should be_false - end + before :each do + Syslog.opened?.should be_false + end - after :each do - Syslog.opened?.should be_false - end + after :each do + Syslog.opened?.should be_false + end - it "returns the module" do - Syslog.open.should == Syslog - Syslog.close - Syslog.open("Test", 5, 9).should == Syslog - Syslog.close - end + it "returns the module" do + Syslog.open.should == Syslog + Syslog.close + Syslog.open("Test", 5, 9).should == Syslog + Syslog.close + end - it "receives an identity as first argument" do - Syslog.open("rubyspec") - Syslog.ident.should == "rubyspec" - Syslog.close - end + it "receives an identity as first argument" do + Syslog.open("rubyspec") + Syslog.ident.should == "rubyspec" + Syslog.close + end - it "defaults the identity to $0" do - Syslog.open - Syslog.ident.should == $0 - Syslog.close - end + it "defaults the identity to $0" do + Syslog.open + Syslog.ident.should == $0 + Syslog.close + end - it "receives the logging options as second argument" do - Syslog.open("rubyspec", Syslog::LOG_PID) - Syslog.options.should == Syslog::LOG_PID - Syslog.close - end + it "receives the logging options as second argument" do + Syslog.open("rubyspec", Syslog::LOG_PID) + Syslog.options.should == Syslog::LOG_PID + Syslog.close + end - it "defaults the logging options to LOG_PID | LOG_CONS" do - Syslog.open - Syslog.options.should == Syslog::LOG_PID | Syslog::LOG_CONS - Syslog.close - end + it "defaults the logging options to LOG_PID | LOG_CONS" do + Syslog.open + Syslog.options.should == Syslog::LOG_PID | Syslog::LOG_CONS + Syslog.close + end - it "receives a facility as third argument" do - Syslog.open("rubyspec", Syslog::LOG_PID, 0) - Syslog.facility.should == 0 - Syslog.close - end + it "receives a facility as third argument" do + Syslog.open("rubyspec", Syslog::LOG_PID, 0) + Syslog.facility.should == 0 + Syslog.close + end - it "defaults the facility to LOG_USER" do - Syslog.open - Syslog.facility.should == Syslog::LOG_USER - Syslog.close - end + it "defaults the facility to LOG_USER" do + Syslog.open + Syslog.facility.should == Syslog::LOG_USER + Syslog.close + end - it "receives a block and calls it with the module" do - Syslog.open("rubyspec", 3, 8) do |s| - s.should == Syslog - s.ident.should == "rubyspec" - s.options.should == 3 - s.facility.should == Syslog::LOG_USER - end + it "receives a block and calls it with the module" do + Syslog.open("rubyspec", 3, 8) do |s| + s.should == Syslog + s.ident.should == "rubyspec" + s.options.should == 3 + s.facility.should == Syslog::LOG_USER end + end - it "closes the log if after it receives a block" do - Syslog.open{ } - Syslog.opened?.should be_false - end + it "closes the log if after it receives a block" do + Syslog.open{ } + Syslog.opened?.should be_false + end - it "raises an error if the log is opened" do + it "raises an error if the log is opened" do + Syslog.open + -> { Syslog.open - -> { - Syslog.open - }.should raise_error(RuntimeError, /syslog already open/) - -> { - Syslog.close - Syslog.open - }.should_not raise_error + }.should raise_error(RuntimeError, /syslog already open/) + -> { Syslog.close - end + Syslog.open + }.should_not raise_error + Syslog.close end end + end - describe "Syslog.open!" do - it_behaves_like :syslog_reopen, :open! - end + describe "Syslog.open!" do + it_behaves_like :syslog_reopen, :open! end end diff --git a/spec/ruby/library/syslog/opened_spec.rb b/spec/ruby/library/syslog/opened_spec.rb index ee7a884a50f..94432e65a44 100644 --- a/spec/ruby/library/syslog/opened_spec.rb +++ b/spec/ruby/library/syslog/opened_spec.rb @@ -1,41 +1,38 @@ require_relative '../../spec_helper' -ruby_version_is ""..."3.4" do +platform_is_not :windows do + require 'syslog' - platform_is_not :windows do - require 'syslog' + describe "Syslog.opened?" do + platform_is_not :windows do - describe "Syslog.opened?" do - platform_is_not :windows do - - before :each do - Syslog.opened?.should be_false - end + before :each do + Syslog.opened?.should be_false + end - after :each do - Syslog.opened?.should be_false - end + after :each do + Syslog.opened?.should be_false + end - it "returns true if the log is opened" do - Syslog.open - Syslog.opened?.should be_true - Syslog.close - end + it "returns true if the log is opened" do + Syslog.open + Syslog.opened?.should be_true + Syslog.close + end - it "returns false otherwise" do - Syslog.opened?.should be_false - Syslog.open - Syslog.close - Syslog.opened?.should be_false - end + it "returns false otherwise" do + Syslog.opened?.should be_false + Syslog.open + Syslog.close + Syslog.opened?.should be_false + end - it "works inside a block" do - Syslog.open do |s| - s.opened?.should be_true - Syslog.opened?.should be_true - end - Syslog.opened?.should be_false + it "works inside a block" do + Syslog.open do |s| + s.opened?.should be_true + Syslog.opened?.should be_true end + Syslog.opened?.should be_false end end end diff --git a/spec/ruby/library/syslog/options_spec.rb b/spec/ruby/library/syslog/options_spec.rb index 814f7daee60..83ba43503ec 100644 --- a/spec/ruby/library/syslog/options_spec.rb +++ b/spec/ruby/library/syslog/options_spec.rb @@ -1,50 +1,47 @@ require_relative '../../spec_helper' -ruby_version_is ""..."3.4" do - - platform_is_not :windows do - require 'syslog' - - describe "Syslog.options" do - platform_is_not :windows do - - before :each do - Syslog.opened?.should be_false - end - - after :each do - Syslog.opened?.should be_false - end - - it "returns the logging options" do - Syslog.open("rubyspec", Syslog::LOG_PID) - Syslog.options.should == Syslog::LOG_PID - Syslog.close - end - - it "returns nil when the log is closed" do - Syslog.opened?.should be_false - Syslog.options.should == nil - end - - it "defaults to LOG_PID | LOG_CONS" do - Syslog.open - Syslog.options.should == Syslog::LOG_PID | Syslog::LOG_CONS - Syslog.close - end - - it "resets after each open call" do - Syslog.open - Syslog.options.should == Syslog::LOG_PID | Syslog::LOG_CONS - - Syslog.open!("rubyspec", Syslog::LOG_PID) - Syslog.options.should == Syslog::LOG_PID - Syslog.close - - Syslog.open - Syslog.options.should == Syslog::LOG_PID | Syslog::LOG_CONS - Syslog.close - end +platform_is_not :windows do + require 'syslog' + + describe "Syslog.options" do + platform_is_not :windows do + + before :each do + Syslog.opened?.should be_false + end + + after :each do + Syslog.opened?.should be_false + end + + it "returns the logging options" do + Syslog.open("rubyspec", Syslog::LOG_PID) + Syslog.options.should == Syslog::LOG_PID + Syslog.close + end + + it "returns nil when the log is closed" do + Syslog.opened?.should be_false + Syslog.options.should == nil + end + + it "defaults to LOG_PID | LOG_CONS" do + Syslog.open + Syslog.options.should == Syslog::LOG_PID | Syslog::LOG_CONS + Syslog.close + end + + it "resets after each open call" do + Syslog.open + Syslog.options.should == Syslog::LOG_PID | Syslog::LOG_CONS + + Syslog.open!("rubyspec", Syslog::LOG_PID) + Syslog.options.should == Syslog::LOG_PID + Syslog.close + + Syslog.open + Syslog.options.should == Syslog::LOG_PID | Syslog::LOG_CONS + Syslog.close end end end diff --git a/spec/ruby/library/syslog/reopen_spec.rb b/spec/ruby/library/syslog/reopen_spec.rb index 47861bc1c0d..a78529fa1fe 100644 --- a/spec/ruby/library/syslog/reopen_spec.rb +++ b/spec/ruby/library/syslog/reopen_spec.rb @@ -1,13 +1,10 @@ require_relative '../../spec_helper' -ruby_version_is ""..."3.4" do +platform_is_not :windows do + require_relative 'shared/reopen' + require 'syslog' - platform_is_not :windows do - require_relative 'shared/reopen' - require 'syslog' - - describe "Syslog.reopen" do - it_behaves_like :syslog_reopen, :reopen - end + describe "Syslog.reopen" do + it_behaves_like :syslog_reopen, :reopen end end diff --git a/spec/ruby/library/syslog/shared/log.rb b/spec/ruby/library/syslog/shared/log.rb index d6daf3cc67c..12e4ea8366a 100644 --- a/spec/ruby/library/syslog/shared/log.rb +++ b/spec/ruby/library/syslog/shared/log.rb @@ -1,41 +1,39 @@ -ruby_version_is ""..."3.4" do - describe :syslog_log, shared: true do - platform_is_not :windows, :darwin, :solaris, :aix, :android do - before :each do - Syslog.opened?.should be_false - end +describe :syslog_log, shared: true do + platform_is_not :windows, :darwin, :solaris, :aix, :android do + before :each do + Syslog.opened?.should be_false + end - after :each do - Syslog.opened?.should be_false - end + after :each do + Syslog.opened?.should be_false + end - it "logs a message" do - -> { - Syslog.open("rubyspec", Syslog::LOG_PERROR) do - Syslog.send(@method, "Hello") - end - }.should output_to_fd(/\Arubyspec(?::| \d+ - -) Hello\n\z/, $stderr) - end + it "logs a message" do + -> { + Syslog.open("rubyspec", Syslog::LOG_PERROR) do + Syslog.send(@method, "Hello") + end + }.should output_to_fd(/\Arubyspec(?::| \d+ - -) Hello\n\z/, $stderr) + end - it "accepts sprintf arguments" do - -> { - Syslog.open("rubyspec", Syslog::LOG_PERROR) do - Syslog.send(@method, "Hello %s", "world") - Syslog.send(@method, "%d dogs", 2) - end - }.should output_to_fd(/\Arubyspec(?::| \d+ - -) Hello world\nrubyspec(?::| \d+ - -) 2 dogs\n\z/, $stderr) - end + it "accepts sprintf arguments" do + -> { + Syslog.open("rubyspec", Syslog::LOG_PERROR) do + Syslog.send(@method, "Hello %s", "world") + Syslog.send(@method, "%d dogs", 2) + end + }.should output_to_fd(/\Arubyspec(?::| \d+ - -) Hello world\nrubyspec(?::| \d+ - -) 2 dogs\n\z/, $stderr) + end - it "works as an alias for Syslog.log" do - level = Syslog.const_get "LOG_#{@method.to_s.upcase}" - -> { - Syslog.open("rubyspec", Syslog::LOG_PERROR) do - Syslog.send(@method, "Hello") - Syslog.log(level, "Hello") - end - # make sure the same thing is written to $stderr. - }.should output_to_fd(/\A(?:rubyspec(?::| \d+ - -) Hello\n){2}\z/, $stderr) - end + it "works as an alias for Syslog.log" do + level = Syslog.const_get "LOG_#{@method.to_s.upcase}" + -> { + Syslog.open("rubyspec", Syslog::LOG_PERROR) do + Syslog.send(@method, "Hello") + Syslog.log(level, "Hello") + end + # make sure the same thing is written to $stderr. + }.should output_to_fd(/\A(?:rubyspec(?::| \d+ - -) Hello\n){2}\z/, $stderr) end end end diff --git a/spec/ruby/library/syslog/shared/reopen.rb b/spec/ruby/library/syslog/shared/reopen.rb index 935349010be..621437a01d8 100644 --- a/spec/ruby/library/syslog/shared/reopen.rb +++ b/spec/ruby/library/syslog/shared/reopen.rb @@ -1,42 +1,40 @@ -ruby_version_is ""..."3.4" do - describe :syslog_reopen, shared: true do - platform_is_not :windows do - before :each do - Syslog.opened?.should be_false - end +describe :syslog_reopen, shared: true do + platform_is_not :windows do + before :each do + Syslog.opened?.should be_false + end - after :each do - Syslog.opened?.should be_false - end + after :each do + Syslog.opened?.should be_false + end - it "reopens the log" do - Syslog.open - -> { Syslog.send(@method)}.should_not raise_error - Syslog.opened?.should be_true - Syslog.close - end + it "reopens the log" do + Syslog.open + -> { Syslog.send(@method)}.should_not raise_error + Syslog.opened?.should be_true + Syslog.close + end - it "fails with RuntimeError if the log is closed" do - -> { Syslog.send(@method)}.should raise_error(RuntimeError) - end + it "fails with RuntimeError if the log is closed" do + -> { Syslog.send(@method)}.should raise_error(RuntimeError) + end - it "receives the same parameters as Syslog.open" do - Syslog.open - Syslog.send(@method, "rubyspec", 3, 8) do |s| - s.should == Syslog - s.ident.should == "rubyspec" - s.options.should == 3 - s.facility.should == Syslog::LOG_USER - s.opened?.should be_true - end - Syslog.opened?.should be_false + it "receives the same parameters as Syslog.open" do + Syslog.open + Syslog.send(@method, "rubyspec", 3, 8) do |s| + s.should == Syslog + s.ident.should == "rubyspec" + s.options.should == 3 + s.facility.should == Syslog::LOG_USER + s.opened?.should be_true end + Syslog.opened?.should be_false + end - it "returns the module" do - Syslog.open - Syslog.send(@method).should == Syslog - Syslog.close - end + it "returns the module" do + Syslog.open + Syslog.send(@method).should == Syslog + Syslog.close end end end diff --git a/spec/ruby/library/syslog/warning_spec.rb b/spec/ruby/library/syslog/warning_spec.rb index cf0f7d0dc21..eeca6031362 100644 --- a/spec/ruby/library/syslog/warning_spec.rb +++ b/spec/ruby/library/syslog/warning_spec.rb @@ -1,13 +1,10 @@ require_relative '../../spec_helper' -ruby_version_is ""..."3.4" do +platform_is_not :windows do + require_relative 'shared/log' + require 'syslog' - platform_is_not :windows do - require_relative 'shared/log' - require 'syslog' - - describe "Syslog.warning" do - it_behaves_like :syslog_log, :warning - end + describe "Syslog.warning" do + it_behaves_like :syslog_log, :warning end end diff --git a/spec/ruby/optional/capi/encoding_spec.rb b/spec/ruby/optional/capi/encoding_spec.rb index 36437cc7b68..b0c38d75a93 100644 --- a/spec/ruby/optional/capi/encoding_spec.rb +++ b/spec/ruby/optional/capi/encoding_spec.rb @@ -2,7 +2,7 @@ require_relative 'spec_helper' require_relative 'fixtures/encoding' -load_extension('encoding') +extension_path = load_extension('encoding') describe :rb_enc_get_index, shared: true do it "returns the index of the encoding of a String" do @@ -559,19 +559,19 @@ describe "rb_ascii8bit_encindex" do it "returns an index for the ASCII-8BIT encoding" do - @s.rb_ascii8bit_encindex().should >= 0 + @s.rb_ascii8bit_encindex().should == 0 end end describe "rb_utf8_encindex" do it "returns an index for the UTF-8 encoding" do - @s.rb_utf8_encindex().should >= 0 + @s.rb_utf8_encindex().should == 1 end end describe "rb_usascii_encindex" do it "returns an index for the US-ASCII encoding" do - @s.rb_usascii_encindex().should >= 0 + @s.rb_usascii_encindex().should == 2 end end @@ -721,4 +721,27 @@ str.bytes.should == [0, 0x24] end end + + describe "rb_define_dummy_encoding" do + it "defines the dummy encoding" do + @s.rb_define_dummy_encoding("FOO") + enc = Encoding.find("FOO") + enc.should.dummy? + end + + it "returns the index of the dummy encoding" do + index = @s.rb_define_dummy_encoding("BAR") + index.should == Encoding.list.size - 1 + end + + ruby_version_is "3.2" do + it "raises EncodingError if too many encodings" do + code = <<-RUBY + require #{extension_path.dump} + 1_000.times {|i| CApiEncodingSpecs.new.rb_define_dummy_encoding("R_\#{i}") } + RUBY + ruby_exe(code, args: "2>&1", exit_status: 1).should.include?('too many encoding (> 256) (EncodingError)') + end + end + end end diff --git a/spec/ruby/optional/capi/ext/encoding_spec.c b/spec/ruby/optional/capi/ext/encoding_spec.c index 3343848b542..aa8662cfbd6 100644 --- a/spec/ruby/optional/capi/ext/encoding_spec.c +++ b/spec/ruby/optional/capi/ext/encoding_spec.c @@ -320,6 +320,10 @@ static VALUE encoding_spec_rb_enc_left_char_head(VALUE self, VALUE str, VALUE of return LONG2NUM(result - ptr); } +static VALUE encoding_spec_rb_define_dummy_encoding(VALUE self, VALUE name) { + return INT2NUM(rb_define_dummy_encoding(RSTRING_PTR(name))); +} + void Init_encoding_spec(void) { VALUE cls; native_rb_encoding_pointer = (rb_encoding**) malloc(sizeof(rb_encoding*)); @@ -379,6 +383,7 @@ void Init_encoding_spec(void) { rb_define_method(cls, "rb_uv_to_utf8", encoding_spec_rb_uv_to_utf8, 2); rb_define_method(cls, "ONIGENC_MBC_CASE_FOLD", encoding_spec_ONIGENC_MBC_CASE_FOLD, 1); rb_define_method(cls, "rb_enc_left_char_head", encoding_spec_rb_enc_left_char_head, 2); + rb_define_method(cls, "rb_define_dummy_encoding", encoding_spec_rb_define_dummy_encoding, 1); } #ifdef __cplusplus diff --git a/spec/ruby/optional/capi/ext/string_spec.c b/spec/ruby/optional/capi/ext/string_spec.c index 2bd789fb728..070a88759ba 100644 --- a/spec/ruby/optional/capi/ext/string_spec.c +++ b/spec/ruby/optional/capi/ext/string_spec.c @@ -51,12 +51,6 @@ VALUE string_spec_rb_str_set_len_RSTRING_LEN(VALUE self, VALUE str, VALUE len) { return INT2FIX(RSTRING_LEN(str)); } -VALUE rb_fstring(VALUE str); /* internal.h, used in ripper */ - -VALUE string_spec_rb_str_fstring(VALUE self, VALUE str) { - return rb_fstring(str); -} - VALUE string_spec_rb_str_buf_new(VALUE self, VALUE len, VALUE str) { VALUE buf; @@ -578,11 +572,19 @@ static VALUE string_spec_rb_str_unlocktmp(VALUE self, VALUE str) { return rb_str_unlocktmp(str); } +static VALUE string_spec_rb_enc_interned_str_cstr(VALUE self, VALUE str, VALUE enc) { + rb_encoding *e = rb_to_encoding(enc); + return rb_enc_interned_str_cstr(RSTRING_PTR(str), e); +} + +static VALUE string_spec_rb_str_to_interned_str(VALUE self, VALUE str) { + return rb_str_to_interned_str(str); +} + void Init_string_spec(void) { VALUE cls = rb_define_class("CApiStringSpecs", rb_cObject); rb_define_method(cls, "rb_cstr2inum", string_spec_rb_cstr2inum, 2); rb_define_method(cls, "rb_cstr_to_inum", string_spec_rb_cstr_to_inum, 3); - rb_define_method(cls, "rb_fstring", string_spec_rb_str_fstring, 1); rb_define_method(cls, "rb_str2inum", string_spec_rb_str2inum, 2); rb_define_method(cls, "rb_str_append", string_spec_rb_str_append, 2); rb_define_method(cls, "rb_str_buf_new", string_spec_rb_str_buf_new, 2); @@ -679,6 +681,8 @@ void Init_string_spec(void) { rb_define_method(cls, "rb_str_catf", string_spec_rb_str_catf, 1); rb_define_method(cls, "rb_str_locktmp", string_spec_rb_str_locktmp, 1); rb_define_method(cls, "rb_str_unlocktmp", string_spec_rb_str_unlocktmp, 1); + rb_define_method(cls, "rb_enc_interned_str_cstr", string_spec_rb_enc_interned_str_cstr, 2); + rb_define_method(cls, "rb_str_to_interned_str", string_spec_rb_str_to_interned_str, 1); } #ifdef __cplusplus diff --git a/spec/ruby/optional/capi/ext/util_spec.c b/spec/ruby/optional/capi/ext/util_spec.c index 95ba71ea9dc..b5bde420d21 100644 --- a/spec/ruby/optional/capi/ext/util_spec.c +++ b/spec/ruby/optional/capi/ext/util_spec.c @@ -62,22 +62,17 @@ static VALUE util_spec_rb_get_kwargs(VALUE self, VALUE keyword_hash, VALUE keys, int len = RARRAY_LENINT(keys); int values_len = req + (opt < 0 ? -1 - opt : opt); - int i = 0; - ID *ids = (ID*) malloc(sizeof(VALUE) * len); - VALUE *results = (VALUE*) malloc(sizeof(VALUE) * values_len); - int extracted = 0; - VALUE ary = Qundef; + ID *ids = (ID *)alloca(sizeof(VALUE) * len); + VALUE *results = (VALUE *)alloca(sizeof(VALUE) * values_len); - for (i = 0; i < len; i++) { + for (int i = 0; i < len; i++) { ids[i] = SYM2ID(rb_ary_entry(keys, i)); } - extracted = rb_get_kwargs(keyword_hash, ids, req, opt, results); - ary = rb_ary_new_from_values(extracted, results); - free(results); - free(ids); - return ary; + int extracted = rb_get_kwargs(keyword_hash, ids, req, opt, results); + + return rb_ary_new_from_values(extracted, results); } static VALUE util_spec_rb_long2int(VALUE self, VALUE n) { diff --git a/spec/ruby/optional/capi/string_spec.rb b/spec/ruby/optional/capi/string_spec.rb index 3a47fa9762f..d9c20cf1760 100644 --- a/spec/ruby/optional/capi/string_spec.rb +++ b/spec/ruby/optional/capi/string_spec.rb @@ -498,25 +498,6 @@ def inspect end end - describe "rb_fstring" do - it 'returns self if the String is frozen' do - input = 'foo'.freeze - output = @s.rb_fstring(input) - - output.should equal(input) - output.should.frozen? - end - - it 'returns a frozen copy if the String is not frozen' do - input = 'foo' - output = @s.rb_fstring(input) - - output.should.frozen? - output.should_not equal(input) - output.should == 'foo' - end - end - describe "rb_str_subseq" do it "returns a byte-indexed substring" do str = "\x00\x01\x02\x03\x04".force_encoding("binary") @@ -1227,4 +1208,59 @@ def inspect -> { @s.rb_str_unlocktmp("test") }.should raise_error(RuntimeError, 'temporal unlocking already unlocked string') end end + + describe "rb_enc_interned_str_cstr" do + it "returns a frozen string" do + str = "hello" + val = @s.rb_enc_interned_str_cstr(str, Encoding::US_ASCII) + + val.should.is_a?(String) + val.encoding.should == Encoding::US_ASCII + val.should.frozen? + end + + it "returns the same frozen string" do + str = "hello" + result1 = @s.rb_enc_interned_str_cstr(str, Encoding::US_ASCII) + result2 = @s.rb_enc_interned_str_cstr(str, Encoding::US_ASCII) + result1.should.equal?(result2) + end + + it "returns different frozen strings for different encodings" do + str = "hello" + result1 = @s.rb_enc_interned_str_cstr(str, Encoding::US_ASCII) + result2 = @s.rb_enc_interned_str_cstr(str, Encoding::UTF_8) + result1.should_not.equal?(result2) + end + + it "returns the same string as String#-@" do + @s.rb_enc_interned_str_cstr("hello", Encoding::UTF_8).should.equal?(-"hello") + end + end + + describe "rb_str_to_interned_str" do + it "returns a frozen string" do + str = "hello" + result = @s.rb_str_to_interned_str(str) + result.should.is_a?(String) + result.should.frozen? + end + + it "returns the same frozen string" do + str = "hello" + result1 = @s.rb_str_to_interned_str(str) + result2 = @s.rb_str_to_interned_str(str) + result1.should.equal?(result2) + end + + it "returns different frozen strings for different encodings" do + result1 = @s.rb_str_to_interned_str("hello".force_encoding(Encoding::US_ASCII)) + result2 = @s.rb_str_to_interned_str("hello".force_encoding(Encoding::UTF_8)) + result1.should_not.equal?(result2) + end + + it "returns the same string as String#-@" do + @s.rb_str_to_interned_str("hello").should.equal?(-"hello") + end + end end diff --git a/spec/ruby/shared/rational/coerce.rb b/spec/ruby/shared/rational/coerce.rb deleted file mode 100644 index 38925721ed3..00000000000 --- a/spec/ruby/shared/rational/coerce.rb +++ /dev/null @@ -1,35 +0,0 @@ -require_relative '../../spec_helper' - -describe :rational_coerce, shared: true 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 be_true - result.last.is_a?(Float).should be_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 be_true - result.last.is_a?(Rational).should be_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 - - ruby_version_is ""..."3.4" do - require 'bigdecimal' - it "raises an error when passed a BigDecimal" do - -> { - Rational(500, 3).coerce(BigDecimal('166.666666666')) - }.should raise_error(TypeError, /BigDecimal can't be coerced into Rational/) - end - end -end From 0c7f0821cb0a409d8c0ef08a4451d244fe73cbfe Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Mon, 26 Feb 2024 16:09:22 +0100 Subject: [PATCH 05/33] net-http specs moved --- spec/jruby.mspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/jruby.mspec b/spec/jruby.mspec index ab4f2c57a80..ee24b5fcb34 100644 --- a/spec/jruby.mspec +++ b/spec/jruby.mspec @@ -46,7 +46,7 @@ class MSpecScript SPEC_DIR + '/core/kernel/at_exit_spec.rb', SPEC_DIR + '/language/predefined_spec.rb', SPEC_DIR + '/language/predefined/data_spec.rb', - SPEC_DIR + '/library/net/http', + SPEC_DIR + '/library/net-http', *get(:command_line), *get(:security), ] From 75d9c743c7089621831bd141439bd31f8c7f5f40 Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Mon, 26 Feb 2024 16:32:54 +0100 Subject: [PATCH 06/33] Add tags for new failing specs --- spec/tags/ruby/core/exception/top_level_tags.txt | 1 + spec/tags/ruby/core/file/lutime_tags.txt | 5 +++++ spec/tags/ruby/core/method/clone_tags.txt | 1 + spec/tags/ruby/core/proc/clone_tags.txt | 1 + spec/tags/ruby/core/proc/parameters_tags.txt | 1 + spec/tags/ruby/core/unboundmethod/clone_tags.txt | 1 + spec/tags/ruby/language/hash_tags.txt | 2 ++ spec/tags/ruby/language/symbol_tags.txt | 1 + spec/tags/ruby/library/net-ftp/initialize_tags.txt | 4 ++++ 9 files changed, 17 insertions(+) create mode 100644 spec/tags/ruby/core/file/lutime_tags.txt create mode 100644 spec/tags/ruby/core/method/clone_tags.txt create mode 100644 spec/tags/ruby/core/proc/clone_tags.txt create mode 100644 spec/tags/ruby/core/proc/parameters_tags.txt create mode 100644 spec/tags/ruby/core/unboundmethod/clone_tags.txt create mode 100644 spec/tags/ruby/language/symbol_tags.txt create mode 100644 spec/tags/ruby/library/net-ftp/initialize_tags.txt diff --git a/spec/tags/ruby/core/exception/top_level_tags.txt b/spec/tags/ruby/core/exception/top_level_tags.txt index 54c6469c6f6..5ee13afa40a 100644 --- a/spec/tags/ruby/core/exception/top_level_tags.txt +++ b/spec/tags/ruby/core/exception/top_level_tags.txt @@ -1 +1,2 @@ fails:An Exception reaching the top level kills all threads and fibers, ensure clauses are only run for threads current fibers, not for suspended fibers with ensure on non-root fiber +fails:An Exception reaching the top level the Exception#cause is printed to STDERR with backtraces diff --git a/spec/tags/ruby/core/file/lutime_tags.txt b/spec/tags/ruby/core/file/lutime_tags.txt new file mode 100644 index 00000000000..ea93cc1abc0 --- /dev/null +++ b/spec/tags/ruby/core/file/lutime_tags.txt @@ -0,0 +1,5 @@ +fails:File.lutime sets the access and modification time of each file +fails:File.lutime accepts an object that has a #to_path method +fails:File.lutime may set nanosecond precision +fails:File.lutime returns the number of filenames in the arguments +fails:File.lutime 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) diff --git a/spec/tags/ruby/core/method/clone_tags.txt b/spec/tags/ruby/core/method/clone_tags.txt new file mode 100644 index 00000000000..e5b7db675bd --- /dev/null +++ b/spec/tags/ruby/core/method/clone_tags.txt @@ -0,0 +1 @@ +fails:Method#clone preserves frozen status diff --git a/spec/tags/ruby/core/proc/clone_tags.txt b/spec/tags/ruby/core/proc/clone_tags.txt new file mode 100644 index 00000000000..c382e6da246 --- /dev/null +++ b/spec/tags/ruby/core/proc/clone_tags.txt @@ -0,0 +1 @@ +fails:Proc#clone preserves frozen status diff --git a/spec/tags/ruby/core/proc/parameters_tags.txt b/spec/tags/ruby/core/proc/parameters_tags.txt new file mode 100644 index 00000000000..b6be32b3447 --- /dev/null +++ b/spec/tags/ruby/core/proc/parameters_tags.txt @@ -0,0 +1 @@ +fails:Proc#parameters returns :nokey for **nil parameter diff --git a/spec/tags/ruby/core/unboundmethod/clone_tags.txt b/spec/tags/ruby/core/unboundmethod/clone_tags.txt new file mode 100644 index 00000000000..de2e1a659fa --- /dev/null +++ b/spec/tags/ruby/core/unboundmethod/clone_tags.txt @@ -0,0 +1 @@ +fails:UnboundMethod#clone preserves frozen status diff --git a/spec/tags/ruby/language/hash_tags.txt b/spec/tags/ruby/language/hash_tags.txt index 22d6c3ea1e7..cd71c0d524b 100644 --- a/spec/tags/ruby/language/hash_tags.txt +++ b/spec/tags/ruby/language/hash_tags.txt @@ -1 +1,3 @@ fails:The ** operator makes a copy when calling a method taking a positional Hash +fails:Hash literal raises a SyntaxError at parse time when Symbol key with invalid bytes +fails:Hash literal raises a SyntaxError at parse time when Symbol key with invalid bytes and 'key: value' syntax used diff --git a/spec/tags/ruby/language/symbol_tags.txt b/spec/tags/ruby/language/symbol_tags.txt new file mode 100644 index 00000000000..c02bf9af89b --- /dev/null +++ b/spec/tags/ruby/language/symbol_tags.txt @@ -0,0 +1 @@ +fails:A Symbol literal raises an SyntaxError at parse time when Symbol with invalid bytes diff --git a/spec/tags/ruby/library/net-ftp/initialize_tags.txt b/spec/tags/ruby/library/net-ftp/initialize_tags.txt new file mode 100644 index 00000000000..3814846444c --- /dev/null +++ b/spec/tags/ruby/library/net-ftp/initialize_tags.txt @@ -0,0 +1,4 @@ +fails:Net::FTP#initialize when the ssl option is set and the ssl option's value is true initializes ssl_context to a blank SSLContext object +fails:Net::FTP#initialize when the ssl option is set and the ssl option's value is a hash initializes ssl_context to a configured SSLContext object +fails:Net::FTP#initialize when the ssl option is set and private_data_connection is set sets private_data_connection to that value +fails:Net::FTP#initialize when the ssl option is set and private_data_connection is not set sets private_data_connection to nil From 95655623c715ea38b11d9fd2464bbd3603ba785f Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Mon, 26 Feb 2024 12:14:21 -0600 Subject: [PATCH 07/33] Handle prepended shims like included shims Fixes #8121 --- core/src/main/java/org/jruby/RubyClass.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/jruby/RubyClass.java b/core/src/main/java/org/jruby/RubyClass.java index 00ff7353765..116fb8b1af1 100644 --- a/core/src/main/java/org/jruby/RubyClass.java +++ b/core/src/main/java/org/jruby/RubyClass.java @@ -1087,7 +1087,7 @@ private void concreteSubclasses(Collection subs) { Set keys = subclasses.keySet(); for (RubyClass klass: keys) { if (klass.isSingleton()) continue; - if (klass.isIncluded()) { + if (klass.isIncluded() || klass.isPrepended()) { klass.concreteSubclasses(subs); continue; } From 2a786c45bc1b8f193c9bcf6568b47b0528f71aa6 Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Mon, 26 Feb 2024 13:26:08 -0600 Subject: [PATCH 08/33] Add subclasses specs for more prepend/include cases See jruby/jruby#8121 --- spec/ruby/core/class/subclasses_spec.rb | 29 ++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/spec/ruby/core/class/subclasses_spec.rb b/spec/ruby/core/class/subclasses_spec.rb index a16b934d4fc..50eb5358d97 100644 --- a/spec/ruby/core/class/subclasses_spec.rb +++ b/spec/ruby/core/class/subclasses_spec.rb @@ -7,7 +7,7 @@ assert_subclasses(ModuleSpecs::Parent, [ModuleSpecs::Child, ModuleSpecs::Child2]) end - it "does not return included modules" do + it "does not return included modules from the parent" do parent = Class.new child = Class.new(parent) mod = Module.new @@ -16,6 +16,33 @@ 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 From faea64967802a57d6052750fcb2ff9d34cd500a4 Mon Sep 17 00:00:00 2001 From: "Thomas E. Enebo" Date: Tue, 27 Feb 2024 12:56:19 -0500 Subject: [PATCH 09/33] lutimes was passing huge wrong values to function --- core/src/main/java/org/jruby/RubyFile.java | 5 ++--- spec/tags/ruby/core/file/lutime_tags.txt | 4 ---- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/core/src/main/java/org/jruby/RubyFile.java b/core/src/main/java/org/jruby/RubyFile.java index 1bb37b7e454..4c4c8dac469 100644 --- a/core/src/main/java/org/jruby/RubyFile.java +++ b/core/src/main/java/org/jruby/RubyFile.java @@ -1306,8 +1306,8 @@ public static IRubyObject lutime(ThreadContext context, IRubyObject recv, IRubyO long[] mtimeval = null; if (args[0] != context.nil || args[1] != context.nil) { - atimeval = extractTimespec(context, args[0]); - mtimeval = extractTimespec(context, args[1]); + atimeval = convertTimespecToTimeval(extractTimespec(context, args[0])); + mtimeval = convertTimespecToTimeval(extractTimespec(context, args[1])); } for (int i = 2, j = argc; i < j; i++) { @@ -1356,7 +1356,6 @@ public static IRubyObject utime(ThreadContext context, IRubyObject recv, IRubyOb result = runtime.getPosix().utimensat(0, fileToTouch.getAbsolutePath(), atimespec, mtimespec, 0); } catch (NotImplementedError re) { // fall back on utimes - result = runtime.getPosix().utimes(fileToTouch.getAbsolutePath(), atimespec, mtimespec); long[] atimeval = convertTimespecToTimeval(atimespec); long[] mtimeval = convertTimespecToTimeval(mtimespec); result = runtime.getPosix().utimes(fileToTouch.getAbsolutePath(), atimeval, mtimeval); diff --git a/spec/tags/ruby/core/file/lutime_tags.txt b/spec/tags/ruby/core/file/lutime_tags.txt index ea93cc1abc0..c848eba9e72 100644 --- a/spec/tags/ruby/core/file/lutime_tags.txt +++ b/spec/tags/ruby/core/file/lutime_tags.txt @@ -1,5 +1 @@ -fails:File.lutime sets the access and modification time of each file -fails:File.lutime accepts an object that has a #to_path method -fails:File.lutime may set nanosecond precision -fails:File.lutime returns the number of filenames in the arguments fails:File.lutime 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) From 3ab59d8370b6b492bc4cf471c2f025be105ae4e7 Mon Sep 17 00:00:00 2001 From: "Thomas E. Enebo" Date: Tue, 27 Feb 2024 12:59:51 -0500 Subject: [PATCH 10/33] Method.clone of frozen should stay frozen --- core/src/main/java/org/jruby/RubyMethod.java | 1 + spec/tags/ruby/core/method/clone_tags.txt | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) delete mode 100644 spec/tags/ruby/core/method/clone_tags.txt diff --git a/core/src/main/java/org/jruby/RubyMethod.java b/core/src/main/java/org/jruby/RubyMethod.java index 7ebbad1bb11..e9f6da165f8 100644 --- a/core/src/main/java/org/jruby/RubyMethod.java +++ b/core/src/main/java/org/jruby/RubyMethod.java @@ -217,6 +217,7 @@ private long hashCodeImpl() { public RubyMethod rbClone() { RubyMethod newMethod = newMethod(implementationModule, methodName, originModule, originName, entry, receiver); newMethod.setMetaClass(getMetaClass()); + newMethod.setFrozen(isFrozen()); return newMethod; } diff --git a/spec/tags/ruby/core/method/clone_tags.txt b/spec/tags/ruby/core/method/clone_tags.txt deleted file mode 100644 index e5b7db675bd..00000000000 --- a/spec/tags/ruby/core/method/clone_tags.txt +++ /dev/null @@ -1 +0,0 @@ -fails:Method#clone preserves frozen status From 0b03c62a58bda8a9bdaf3637f9937317487d1ca4 Mon Sep 17 00:00:00 2001 From: "Thomas E. Enebo" Date: Tue, 27 Feb 2024 13:05:14 -0500 Subject: [PATCH 11/33] Proc#clone of frozen proc should stay frozen --- core/src/main/java/org/jruby/RubyProc.java | 4 +++- spec/tags/ruby/core/proc/clone_tags.txt | 1 - 2 files changed, 3 insertions(+), 2 deletions(-) delete mode 100644 spec/tags/ruby/core/proc/clone_tags.txt diff --git a/core/src/main/java/org/jruby/RubyProc.java b/core/src/main/java/org/jruby/RubyProc.java index c62fd28f497..bd231f0377c 100644 --- a/core/src/main/java/org/jruby/RubyProc.java +++ b/core/src/main/java/org/jruby/RubyProc.java @@ -213,7 +213,9 @@ private void setup(Block procBlock) { @JRubyMethod(name = "clone") @Override public IRubyObject rbClone() { - return newProc(getRuntime(), block, type, file, line); + RubyProc proc = newProc(getRuntime(), block, type, file, line); + if (isFrozen()) proc.setFrozen(true); + return proc; } @JRubyMethod(name = "dup") diff --git a/spec/tags/ruby/core/proc/clone_tags.txt b/spec/tags/ruby/core/proc/clone_tags.txt deleted file mode 100644 index c382e6da246..00000000000 --- a/spec/tags/ruby/core/proc/clone_tags.txt +++ /dev/null @@ -1 +0,0 @@ -fails:Proc#clone preserves frozen status From 569baf0c64333bf63d4d847bd31f2c84424ae600 Mon Sep 17 00:00:00 2001 From: "Thomas E. Enebo" Date: Tue, 27 Feb 2024 13:07:09 -0500 Subject: [PATCH 12/33] Only set frozen if original is frozen --- core/src/main/java/org/jruby/RubyMethod.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/jruby/RubyMethod.java b/core/src/main/java/org/jruby/RubyMethod.java index e9f6da165f8..2725b565a9a 100644 --- a/core/src/main/java/org/jruby/RubyMethod.java +++ b/core/src/main/java/org/jruby/RubyMethod.java @@ -217,7 +217,7 @@ private long hashCodeImpl() { public RubyMethod rbClone() { RubyMethod newMethod = newMethod(implementationModule, methodName, originModule, originName, entry, receiver); newMethod.setMetaClass(getMetaClass()); - newMethod.setFrozen(isFrozen()); + if (isFrozen()) newMethod.setFrozen(true); return newMethod; } From a3e35f41e7c12e48b24a8f056399fa4a5e566d44 Mon Sep 17 00:00:00 2001 From: "Thomas E. Enebo" Date: Tue, 27 Feb 2024 13:10:22 -0500 Subject: [PATCH 13/33] UnboundMethod#clone of frozen UnboundMethod should stay frozen --- core/src/main/java/org/jruby/RubyUnboundMethod.java | 4 +++- spec/tags/ruby/core/unboundmethod/clone_tags.txt | 1 - 2 files changed, 3 insertions(+), 2 deletions(-) delete mode 100644 spec/tags/ruby/core/unboundmethod/clone_tags.txt diff --git a/core/src/main/java/org/jruby/RubyUnboundMethod.java b/core/src/main/java/org/jruby/RubyUnboundMethod.java index 6c541df44cd..3e19a9f81bd 100644 --- a/core/src/main/java/org/jruby/RubyUnboundMethod.java +++ b/core/src/main/java/org/jruby/RubyUnboundMethod.java @@ -149,7 +149,9 @@ private CacheEntry convertUnboundMethodToCallableEntry(ThreadContext context, Ru @JRubyMethod(name = "clone") @Override public RubyUnboundMethod rbClone() { - return newUnboundMethod(implementationModule, methodName, originModule, originName, entry); + RubyUnboundMethod unboundMethod = newUnboundMethod(implementationModule, methodName, originModule, originName, entry); + if (isFrozen()) unboundMethod.setFrozen(true); + return unboundMethod; } @JRubyMethod(required = 1, rest = true, checkArity = false, keywords = true) diff --git a/spec/tags/ruby/core/unboundmethod/clone_tags.txt b/spec/tags/ruby/core/unboundmethod/clone_tags.txt deleted file mode 100644 index de2e1a659fa..00000000000 --- a/spec/tags/ruby/core/unboundmethod/clone_tags.txt +++ /dev/null @@ -1 +0,0 @@ -fails:UnboundMethod#clone preserves frozen status From 4e42bf204bea3b697ad12c7f7a5c080d7e9d4a63 Mon Sep 17 00:00:00 2001 From: "Thomas E. Enebo" Date: Tue, 27 Feb 2024 13:16:04 -0500 Subject: [PATCH 14/33] EncodingError should be SyntaxError for bad symbols? --- core/src/main/java/org/jruby/parser/RubyParserBase.java | 2 +- spec/tags/ruby/language/hash_tags.txt | 2 -- spec/tags/ruby/language/symbol_tags.txt | 1 - 3 files changed, 1 insertion(+), 4 deletions(-) delete mode 100644 spec/tags/ruby/language/symbol_tags.txt diff --git a/core/src/main/java/org/jruby/parser/RubyParserBase.java b/core/src/main/java/org/jruby/parser/RubyParserBase.java index 5deb56c64ae..bebc7402af9 100644 --- a/core/src/main/java/org/jruby/parser/RubyParserBase.java +++ b/core/src/main/java/org/jruby/parser/RubyParserBase.java @@ -1228,7 +1228,7 @@ public RubySymbol symbolID(ByteList identifierValue) { // FIXME: We walk this during identifier construction so we should calculate CR without having to walk twice. if (RubyString.scanForCodeRange(identifierValue) == StringSupport.CR_BROKEN) { Ruby runtime = getRuntime(); - throw runtime.newEncodingError(str(runtime, "invalid symbol in encoding " + lexer.getEncoding() + " :\"", inspectIdentifierByteList(runtime, identifierValue), "\"")); + throw runtime.newSyntaxError(str(runtime, "invalid symbol in encoding " + lexer.getEncoding() + " :\"", inspectIdentifierByteList(runtime, identifierValue), "\"")); } return RubySymbol.newIDSymbol(getRuntime(), identifierValue); diff --git a/spec/tags/ruby/language/hash_tags.txt b/spec/tags/ruby/language/hash_tags.txt index cd71c0d524b..22d6c3ea1e7 100644 --- a/spec/tags/ruby/language/hash_tags.txt +++ b/spec/tags/ruby/language/hash_tags.txt @@ -1,3 +1 @@ fails:The ** operator makes a copy when calling a method taking a positional Hash -fails:Hash literal raises a SyntaxError at parse time when Symbol key with invalid bytes -fails:Hash literal raises a SyntaxError at parse time when Symbol key with invalid bytes and 'key: value' syntax used diff --git a/spec/tags/ruby/language/symbol_tags.txt b/spec/tags/ruby/language/symbol_tags.txt deleted file mode 100644 index c02bf9af89b..00000000000 --- a/spec/tags/ruby/language/symbol_tags.txt +++ /dev/null @@ -1 +0,0 @@ -fails:A Symbol literal raises an SyntaxError at parse time when Symbol with invalid bytes From c73a88c23f1dfefd2d2cb84acb6dd48a1e4f4415 Mon Sep 17 00:00:00 2001 From: "Thomas E. Enebo" Date: Tue, 27 Feb 2024 14:53:53 -0500 Subject: [PATCH 15/33] parameters value for **nil should be nokey --- .../java/org/jruby/ir/builder/IRBuilderAST.java | 11 +++++++++-- .../main/java/org/jruby/runtime/ArgumentType.java | 5 ++++- core/src/main/java/org/jruby/runtime/Helpers.java | 13 ++++++++++--- .../main/java/org/jruby/util/CommonByteLists.java | 1 + spec/tags/ruby/core/method/parameters_tags.txt | 1 - spec/tags/ruby/core/proc/parameters_tags.txt | 1 - 6 files changed, 24 insertions(+), 8 deletions(-) delete mode 100644 spec/tags/ruby/core/method/parameters_tags.txt delete mode 100644 spec/tags/ruby/core/proc/parameters_tags.txt diff --git a/core/src/main/java/org/jruby/ir/builder/IRBuilderAST.java b/core/src/main/java/org/jruby/ir/builder/IRBuilderAST.java index 4b707a9ec17..a9e6e8ff1f7 100644 --- a/core/src/main/java/org/jruby/ir/builder/IRBuilderAST.java +++ b/core/src/main/java/org/jruby/ir/builder/IRBuilderAST.java @@ -1775,10 +1775,17 @@ public void receiveArgs(final ArgsNode argsNode) { // 2.0 keyword rest arg if (keyRest != null) { - ArgumentType type = ArgumentType.keyrest; + ArgumentType type; + // FIXME: combined processing of argumentType could be removed and use same helper that blocks use. // anonymous keyrest - if (restName == null || restName.getBytes().realSize() == 0) type = ArgumentType.anonkeyrest; + if (restName == null || restName.getBytes().realSize() == 0) { + type = ArgumentType.anonkeyrest; + } else if (restName.getBytes().equals(CommonByteLists.NIL)) { + type = ArgumentType.nokey; + } else { + type = ArgumentType.keyrest; + } Variable av = getNewLocalVariable(restName, 0); if (scope instanceof IRMethod) addArgumentDescription(type, restName); diff --git a/core/src/main/java/org/jruby/runtime/ArgumentType.java b/core/src/main/java/org/jruby/runtime/ArgumentType.java index de8441d726a..c9e0b9c17f4 100644 --- a/core/src/main/java/org/jruby/runtime/ArgumentType.java +++ b/core/src/main/java/org/jruby/runtime/ArgumentType.java @@ -19,7 +19,8 @@ public enum ArgumentType { anonreq("req", true), anonopt("opt", true), anonrest("rest", true), - anonkeyrest("keyrest", true); + anonkeyrest("keyrest", true), + nokey("nokey", true); ArgumentType(String typeId, boolean anonymous) { this.typeId = typeId; @@ -36,6 +37,7 @@ public static ArgumentType valueOf(char prefix) { case 'o': return opt; case 'r': return rest; case 'q': return req; + case 'l': return nokey; // These are sourced from DescriptorInfo because ArgumentType references Ruby. case DescriptorInfo.ANONREQ_CHAR: return anonreq; case DescriptorInfo.ANONOPT_CHAR: return anonopt; @@ -55,6 +57,7 @@ static char prefixFrom(ArgumentType type) { case opt: return 'o'; case rest: return 'r'; case req: return 'q'; + case nokey: return 'l'; case anonreq: return DescriptorInfo.ANONREQ_CHAR; case anonopt: return DescriptorInfo.ANONOPT_CHAR; case anonrest: return DescriptorInfo.ANONREST_CHAR; diff --git a/core/src/main/java/org/jruby/runtime/Helpers.java b/core/src/main/java/org/jruby/runtime/Helpers.java index 9caaab241fb..3df0f54f94d 100644 --- a/core/src/main/java/org/jruby/runtime/Helpers.java +++ b/core/src/main/java/org/jruby/runtime/Helpers.java @@ -71,6 +71,7 @@ import org.jruby.util.ArraySupport; import org.jruby.util.ByteList; import org.jruby.util.CodegenUtils; +import org.jruby.util.CommonByteLists; import org.jruby.util.MurmurHash; import org.jruby.util.TypeConverter; @@ -2608,8 +2609,15 @@ public static ArgumentDescriptor[] argsNodeToArgumentDescriptors(ArgsNode argsNo if (argsNode.getKeyRest() != null) { RubySymbol argName = argsNode.getKeyRest().getName(); - // FIXME: Should a argName of "" really get saved that way here? - ArgumentType type = argName == null || argName.getBytes().length() == 0 ? ArgumentType.anonkeyrest : ArgumentType.keyrest; + ArgumentType type; + + if (argName == null || argName.getBytes().length() == 0) { + type = ArgumentType.anonkeyrest; + } else if (argName.getBytes().equals(CommonByteLists.NIL)) { + type = ArgumentType.nokey; + } else { + type = ArgumentType.keyrest; + } descs.add(new ArgumentDescriptor(type, argName)); } if (argsNode.getBlock() != null) descs.add(new ArgumentDescriptor(ArgumentType.block, argsNode.getBlock().getName())); @@ -2628,7 +2636,6 @@ public static ArgumentDescriptor[] parameterListToArgumentDescriptors(Ruby runti String param = parameterList[i]; if (param.equals("NONE")) break; - if (param.equals("nil")) param = "n"; // make length 1 so we don't look for a name ArgumentType type = ArgumentType.valueOf(param.charAt(0)); diff --git a/core/src/main/java/org/jruby/util/CommonByteLists.java b/core/src/main/java/org/jruby/util/CommonByteLists.java index 0716dcedaa7..cd3b89a1bd1 100644 --- a/core/src/main/java/org/jruby/util/CommonByteLists.java +++ b/core/src/main/java/org/jruby/util/CommonByteLists.java @@ -54,4 +54,5 @@ public class CommonByteLists { public static final ByteList REFINE_METHOD = new ByteList(new byte[] {'r', 'e', 'f', 'i', 'n', 'e'}); public static final ByteList ZERO = new ByteList(new byte[] {'0'}); public static final ByteList SEND = new ByteList("send".getBytes()); + public static final ByteList NIL = new ByteList("nil".getBytes()); } diff --git a/spec/tags/ruby/core/method/parameters_tags.txt b/spec/tags/ruby/core/method/parameters_tags.txt deleted file mode 100644 index c4aa842ceda..00000000000 --- a/spec/tags/ruby/core/method/parameters_tags.txt +++ /dev/null @@ -1 +0,0 @@ -fails:Method#parameters returns [[:nokey]] for a method with a single **nil parameter diff --git a/spec/tags/ruby/core/proc/parameters_tags.txt b/spec/tags/ruby/core/proc/parameters_tags.txt deleted file mode 100644 index b6be32b3447..00000000000 --- a/spec/tags/ruby/core/proc/parameters_tags.txt +++ /dev/null @@ -1 +0,0 @@ -fails:Proc#parameters returns :nokey for **nil parameter From b7f2682bf8a181dd555063591281f3ec7e001d67 Mon Sep 17 00:00:00 2001 From: "Thomas E. Enebo" Date: Tue, 27 Feb 2024 16:59:33 -0500 Subject: [PATCH 16/33] Return proper encoding error string for String#to_c --- core/src/main/java/org/jruby/RubyString.java | 2 ++ spec/tags/ruby/core/string/to_c_tags.txt | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/jruby/RubyString.java b/core/src/main/java/org/jruby/RubyString.java index f6cf4b5d706..f34cb91e960 100644 --- a/core/src/main/java/org/jruby/RubyString.java +++ b/core/src/main/java/org/jruby/RubyString.java @@ -6514,6 +6514,8 @@ public IRubyObject sumCommon(ThreadContext context, long bits) { public IRubyObject to_c(ThreadContext context) { Ruby runtime = context.runtime; + verifyAsciiCompatible(); + RubyRegexp underscore_pattern = RubyRegexp.newDummyRegexp(runtime, Numeric.ComplexPatterns.underscores_pat); RubyString s = gsubFast(context, underscore_pattern, runtime.newString(UNDERSCORE), Block.NULL_BLOCK); diff --git a/spec/tags/ruby/core/string/to_c_tags.txt b/spec/tags/ruby/core/string/to_c_tags.txt index 7dd4db1a2f6..bb4f9d7c897 100644 --- a/spec/tags/ruby/core/string/to_c_tags.txt +++ b/spec/tags/ruby/core/string/to_c_tags.txt @@ -1,2 +1 @@ -fails:String#to_c raises Encoding::CompatibilityError if String is in not ASCII-compatible encoding fails:String#to_c ignores trailing garbage From bf044f69acb0b3dd5c673fe86556d275b7512b2e Mon Sep 17 00:00:00 2001 From: "Thomas E. Enebo" Date: Wed, 28 Feb 2024 16:48:05 -0500 Subject: [PATCH 17/33] frozen error handling for remove_instance_variable --- core/src/main/java/org/jruby/RubyBasicObject.java | 3 ++- spec/tags/ruby/core/kernel/remove_instance_variable_tags.txt | 2 -- 2 files changed, 2 insertions(+), 3 deletions(-) delete mode 100644 spec/tags/ruby/core/kernel/remove_instance_variable_tags.txt diff --git a/core/src/main/java/org/jruby/RubyBasicObject.java b/core/src/main/java/org/jruby/RubyBasicObject.java index 0a2a5684dd1..f2c7ae270ce 100644 --- a/core/src/main/java/org/jruby/RubyBasicObject.java +++ b/core/src/main/java/org/jruby/RubyBasicObject.java @@ -2848,8 +2848,9 @@ public IRubyObject instance_variable_set(IRubyObject name, IRubyObject value) { * d.var #=> nil */ public IRubyObject remove_instance_variable(ThreadContext context, IRubyObject name, Block block) { + String id = validateInstanceVariable(name); ensureInstanceVariablesSettable(); - IRubyObject value = (IRubyObject) variableTableRemove(validateInstanceVariable(name)); + IRubyObject value = (IRubyObject) variableTableRemove(id); if (value != null) return value; throw context.runtime.newNameError("instance variable %1$s not defined", this, name); } diff --git a/spec/tags/ruby/core/kernel/remove_instance_variable_tags.txt b/spec/tags/ruby/core/kernel/remove_instance_variable_tags.txt deleted file mode 100644 index c81bb21ff59..00000000000 --- a/spec/tags/ruby/core/kernel/remove_instance_variable_tags.txt +++ /dev/null @@ -1,2 +0,0 @@ -fails:Kernel#remove_instance_variable raises a FrozenError if self is frozen -fails:Kernel#remove_instance_variable raises for frozen objects From 886eb7ff44d0a2ce80f5c552766841cc5661076e Mon Sep 17 00:00:00 2001 From: "Thomas E. Enebo" Date: Wed, 28 Feb 2024 16:54:40 -0500 Subject: [PATCH 18/33] test flags for stats need to handle file instances as well as strings --- core/src/main/java/org/jruby/RubyKernel.java | 7 ++++--- spec/tags/ruby/core/kernel/test_tags.txt | 3 --- 2 files changed, 4 insertions(+), 6 deletions(-) delete mode 100644 spec/tags/ruby/core/kernel/test_tags.txt diff --git a/core/src/main/java/org/jruby/RubyKernel.java b/core/src/main/java/org/jruby/RubyKernel.java index 8e7e01d44a5..77041df8a79 100644 --- a/core/src/main/java/org/jruby/RubyKernel.java +++ b/core/src/main/java/org/jruby/RubyKernel.java @@ -94,6 +94,7 @@ import static org.jruby.RubyEnumerator.SizeFn; import static org.jruby.RubyEnumerator.enumeratorizeWithSize; +import static org.jruby.RubyFile.fileResource; import static org.jruby.anno.FrameField.BACKREF; import static org.jruby.RubyIO.checkUnsupportedOptions; import static org.jruby.RubyIO.checkValidSpawnOptions; @@ -1760,13 +1761,13 @@ private static IRubyObject testCommon(ThreadContext context, IRubyObject recv, i switch (cmd) { case 'A': // ?A | Time | Last access time for file1 - return context.runtime.newFileStat(arg1.convertToString().toString(), false).atime(); + return context.runtime.newFileStat(fileResource(arg1).path(), false).atime(); case 'b': // ?b | boolean | True if file1 is a block device return RubyFileTest.blockdev_p(recv, arg1); case 'c': // ?c | boolean | True if file1 is a character device return RubyFileTest.chardev_p(recv, arg1); case 'C': // ?C | Time | Last change time for file1 - return context.runtime.newFileStat(arg1.convertToString().toString(), false).ctime(); + return context.runtime.newFileStat(fileResource(arg1).path(), false).ctime(); case 'd': // ?d | boolean | True if file1 exists and is a directory return RubyFileTest.directory_p(context, recv, arg1); case 'e': // ?e | boolean | True if file1 exists @@ -1780,7 +1781,7 @@ private static IRubyObject testCommon(ThreadContext context, IRubyObject recv, i case 'k': // ?k | boolean | True if file1 exists and has the sticky bit set return RubyFileTest.sticky_p(recv, arg1); case 'M': // ?M | Time | Last modification time for file1 - return context.runtime.newFileStat(arg1.convertToString().toString(), false).mtime(); + return context.runtime.newFileStat(fileResource(arg1).path(), false).mtime(); case 'l': // ?l | boolean | True if file1 exists and is a symbolic link return RubyFileTest.symlink_p(recv, arg1); case 'o': // ?o | boolean | True if file1 exists and is owned by the caller's effective uid diff --git a/spec/tags/ruby/core/kernel/test_tags.txt b/spec/tags/ruby/core/kernel/test_tags.txt deleted file mode 100644 index d80b63c214d..00000000000 --- a/spec/tags/ruby/core/kernel/test_tags.txt +++ /dev/null @@ -1,3 +0,0 @@ -fails:Kernel#test time commands returns the last access time for the provided file when passed ?A -fails:Kernel#test time commands returns the time at which the file was created when passed ?C -fails:Kernel#test time commands returns the time at which the file was modified when passed ?M From c9cf49070d99e4d9abab3d2a9ef792ecdadf866e Mon Sep 17 00:00:00 2001 From: "Thomas E. Enebo" Date: Thu, 29 Feb 2024 11:10:39 -0500 Subject: [PATCH 19/33] Implement string/eval form of trace_var --- core/src/main/java/org/jruby/RubyKernel.java | 7 ++++++- spec/tags/ruby/core/kernel/trace_var_tags.txt | 1 - 2 files changed, 6 insertions(+), 2 deletions(-) delete mode 100644 spec/tags/ruby/core/kernel/trace_var_tags.txt diff --git a/core/src/main/java/org/jruby/RubyKernel.java b/core/src/main/java/org/jruby/RubyKernel.java index 8e7e01d44a5..516f4d15e9c 100644 --- a/core/src/main/java/org/jruby/RubyKernel.java +++ b/core/src/main/java/org/jruby/RubyKernel.java @@ -1615,7 +1615,12 @@ public static IRubyObject trace_var(ThreadContext context, IRubyObject recv, IRu if (argc == 1) { proc = RubyProc.newProc(context.runtime, block, Block.Type.PROC); } else if (argc == 2) { - proc = (RubyProc)TypeConverter.convertToType(args[1], context.runtime.getProc(), "to_proc", true); + if (args[1] instanceof RubyString) { + RubyString s = context.runtime.newString("proc {").cat19(((RubyString) args[1])).cat('}'); + proc = (RubyProc) evalCommon(context, recv, new IRubyObject[] { s }); + } else { + proc = (RubyProc) TypeConverter.convertToType(args[1], context.runtime.getProc(), "to_proc", true); + } } context.runtime.getGlobalVariables().setTraceVar(var, proc); diff --git a/spec/tags/ruby/core/kernel/trace_var_tags.txt b/spec/tags/ruby/core/kernel/trace_var_tags.txt deleted file mode 100644 index 9e69b77598f..00000000000 --- a/spec/tags/ruby/core/kernel/trace_var_tags.txt +++ /dev/null @@ -1 +0,0 @@ -fails:Kernel#trace_var accepts a String argument instead of a Proc or block From 15809ee7252f4ca80958b794b5a5b45939a6ae41 Mon Sep 17 00:00:00 2001 From: "Thomas E. Enebo" Date: Thu, 29 Feb 2024 13:11:25 -0500 Subject: [PATCH 20/33] kwargs arity check fixes for Kernel#open and File#open --- core/src/main/java/org/jruby/RubyFile.java | 12 +++++++----- core/src/main/java/org/jruby/RubyKernel.java | 18 +++++++++++++----- spec/tags/ruby/core/kernel/open_tags.txt | 4 ---- 3 files changed, 20 insertions(+), 14 deletions(-) delete mode 100644 spec/tags/ruby/core/kernel/open_tags.txt diff --git a/core/src/main/java/org/jruby/RubyFile.java b/core/src/main/java/org/jruby/RubyFile.java index 4c4c8dac469..abc1527b79d 100644 --- a/core/src/main/java/org/jruby/RubyFile.java +++ b/core/src/main/java/org/jruby/RubyFile.java @@ -80,6 +80,7 @@ import java.util.zip.ZipFile; import static org.jruby.RubyInteger.singleCharByteList; +import static org.jruby.runtime.ThreadContext.hasKeywords; import static org.jruby.runtime.Visibility.PRIVATE; import static org.jruby.util.StringSupport.*; import static org.jruby.util.io.EncodingUtils.vmode; @@ -341,13 +342,14 @@ public IRubyObject flock(ThreadContext context, IRubyObject operation) { } // rb_file_initialize - @JRubyMethod(name = "initialize", required = 1, optional = 3, checkArity = false, visibility = PRIVATE) + @JRubyMethod(name = "initialize", required = 1, optional = 3, checkArity = false, visibility = PRIVATE, keywords = true) public IRubyObject initialize(ThreadContext context, IRubyObject[] args, Block block) { - int argc = Arity.checkArgumentCount(context, args, 1, 4); + boolean keywords = hasKeywords(ThreadContext.resetCallInfo(context)); + // Mild hack. We want to arity-mismatch if extra arg is not really a kwarg but not if it is one. + int maxArgs = keywords ? 4 : 3; + int argc = Arity.checkArgumentCount(context, args, 1, maxArgs); - if (openFile != null) { - throw context.runtime.newRuntimeError("reinitializing File"); - } + if (openFile != null) throw context.runtime.newRuntimeError("reinitializing File"); if (argc > 0 && argc <= 3) { IRubyObject fd = TypeConverter.convertToTypeWithCheck(context, args[0], context.runtime.getFixnum(), sites(context).to_int_checked); diff --git a/core/src/main/java/org/jruby/RubyKernel.java b/core/src/main/java/org/jruby/RubyKernel.java index 8e7e01d44a5..2f5bf388871 100644 --- a/core/src/main/java/org/jruby/RubyKernel.java +++ b/core/src/main/java/org/jruby/RubyKernel.java @@ -259,14 +259,12 @@ public static IRubyObject open19(ThreadContext context, IRubyObject recv, IRubyO @JRubyMethod(name = "open", required = 1, optional = 3, checkArity = false, module = true, visibility = PRIVATE, keywords = true) public static IRubyObject open(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) { - int argc = Arity.checkArgumentCount(context, args, 1, 4); - - boolean keywords = hasKeywords(ThreadContext.resetCallInfo(context)); Ruby runtime = context.runtime; - // symbol to_open = 0; boolean redirect = false; + int callInfo = ThreadContext.resetCallInfo(context); + boolean keywords = hasKeywords(callInfo); - if (argc >= 1) { + if (args.length >= 1) { // CONST_ID(to_open, "to_open"); if (args[0].respondsTo("to_open")) { redirect = true; @@ -288,6 +286,13 @@ public static IRubyObject open(ThreadContext context, IRubyObject recv, IRubyObj } } } + + // Mild hack. We want to arity-mismatch if extra arg is not really a kwarg but not if it is one. + int maxArgs = keywords ? 5 : 4; + Arity.checkArgumentCount(context, args, 1, maxArgs); + + // symbol to_open = 0; + if (redirect) { if (keywords) context.callInfo = ThreadContext.CALL_KEYWORD; IRubyObject io = args[0].callMethod(context, "to_open", Arrays.copyOfRange(args, 1, args.length)); @@ -295,6 +300,9 @@ public static IRubyObject open(ThreadContext context, IRubyObject recv, IRubyObj RubyIO.ensureYieldClose(context, io, block); return io; } + + // We had to save callInfo from original call because kwargs needs to still pass through to IO#open + context.callInfo = callInfo; return RubyIO.open(context, runtime.getFile(), args, block); } diff --git a/spec/tags/ruby/core/kernel/open_tags.txt b/spec/tags/ruby/core/kernel/open_tags.txt deleted file mode 100644 index 1b2f8c3a37b..00000000000 --- a/spec/tags/ruby/core/kernel/open_tags.txt +++ /dev/null @@ -1,4 +0,0 @@ -windows:Kernel#open opens an io when path starts with a pipe -windows:Kernel#open opens an io when called with a block -fails:Kernel#open accepts options as keyword arguments -fails:Kernel#open when given an object that responds to to_open passes keyword arguments onto #to_open as keyword arguments if to_open accepts them From edbf38f78cfac410759b5a1d87777eb7b86143df Mon Sep 17 00:00:00 2001 From: "Thomas E. Enebo" Date: Thu, 29 Feb 2024 13:19:52 -0500 Subject: [PATCH 21/33] Add kwargs logic to IO#open --- core/src/main/java/org/jruby/RubyIO.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/org/jruby/RubyIO.java b/core/src/main/java/org/jruby/RubyIO.java index 10f7a3f279b..22505fd265e 100644 --- a/core/src/main/java/org/jruby/RubyIO.java +++ b/core/src/main/java/org/jruby/RubyIO.java @@ -107,6 +107,7 @@ import static com.headius.backport9.buffer.Buffers.limitBuffer; import static org.jruby.RubyEnumerator.enumeratorize; import static org.jruby.anno.FrameField.LASTLINE; +import static org.jruby.runtime.ThreadContext.hasKeywords; import static org.jruby.runtime.Visibility.*; import static org.jruby.util.RubyStringBuilder.str; import static org.jruby.util.RubyStringBuilder.types; @@ -1024,8 +1025,9 @@ public IRubyObject initialize(ThreadContext context, IRubyObject fileNumber, IRu return initializeCommon(context, fileno, vmode, options); } - @JRubyMethod(name = "initialize", visibility = PRIVATE) + @JRubyMethod(name = "initialize", visibility = PRIVATE, keywords = true) public IRubyObject initialize(ThreadContext context, IRubyObject fileNumber, IRubyObject modeValue, IRubyObject options, Block unused) { + int callInfo = ThreadContext.resetCallInfo(context); int fileno = RubyNumeric.fix2int(fileNumber); // TODO: MRI has a method name in ArgumentError. @@ -1033,9 +1035,7 @@ public IRubyObject initialize(ThreadContext context, IRubyObject fileNumber, IRu if (modeValue != null && !modeValue.isNil() && !(modeValue instanceof RubyInteger) && !(modeValue instanceof RubyString)) { throw context.runtime.newArgumentError(3, 1, 2); } - if (options == null || options.isNil()) { - throw context.runtime.newArgumentError(3, 1, 2); - } + if (!hasKeywords(callInfo)) throw context.runtime.newArgumentError(3, 1, 2); return initializeCommon(context, fileno, modeValue, options); } From 0ff21b0afb1bf874f696cb1c36cb0efac4155cf7 Mon Sep 17 00:00:00 2001 From: "Thomas E. Enebo" Date: Thu, 29 Feb 2024 13:22:04 -0500 Subject: [PATCH 22/33] untag passing specs --- spec/tags/ruby/core/file/open_tags.txt | 1 - spec/tags/ruby/core/io/open_tags.txt | 6 +----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/spec/tags/ruby/core/file/open_tags.txt b/spec/tags/ruby/core/file/open_tags.txt index 72d660d6fdb..4f3eae1a2c0 100644 --- a/spec/tags/ruby/core/file/open_tags.txt +++ b/spec/tags/ruby/core/file/open_tags.txt @@ -1,2 +1 @@ windows:File.open opens directories -fails:File.open accepts options as a keyword argument diff --git a/spec/tags/ruby/core/io/open_tags.txt b/spec/tags/ruby/core/io/open_tags.txt index e484a5c51ff..c1f343c0b04 100644 --- a/spec/tags/ruby/core/io/open_tags.txt +++ b/spec/tags/ruby/core/io/open_tags.txt @@ -1,7 +1,3 @@ -fails:IO.open raises an error if passed matching binary/text mode two ways -fails:IO.open raises an error if passed conflicting binary/text mode two ways windows:IO.open ingores the :encoding option when the :internal_encoding option is present windows:IO.open raises an Errno::EINVAL if the new mode is not compatible with the descriptor's current mode -fails:IO.open ignores the :encoding option when the :external_encoding option is present -fails:IO.open ignores the :encoding option when the :internal_encoding option is present -fails:IO.open accepts options as keyword arguments + From 07bca02d20d435670e82357ac102f24234cd2721 Mon Sep 17 00:00:00 2001 From: "Thomas E. Enebo" Date: Thu, 29 Feb 2024 13:54:18 -0500 Subject: [PATCH 23/33] IO#for_fd also accepts kwargs --- core/src/main/java/org/jruby/RubyIO.java | 2 +- spec/tags/ruby/core/io/for_fd_tags.txt | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/core/src/main/java/org/jruby/RubyIO.java b/core/src/main/java/org/jruby/RubyIO.java index 22505fd265e..95c8f7ae460 100644 --- a/core/src/main/java/org/jruby/RubyIO.java +++ b/core/src/main/java/org/jruby/RubyIO.java @@ -888,7 +888,7 @@ public static IRubyObject newInstance(ThreadContext context, IRubyObject recv, I return klass.newInstance(context, args, block); } - @JRubyMethod(rest = true, meta = true) + @JRubyMethod(rest = true, meta = true, keywords = true) public static IRubyObject for_fd(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) { RubyClass klass = (RubyClass)recv; diff --git a/spec/tags/ruby/core/io/for_fd_tags.txt b/spec/tags/ruby/core/io/for_fd_tags.txt index 95c24e997d4..1180ee20948 100644 --- a/spec/tags/ruby/core/io/for_fd_tags.txt +++ b/spec/tags/ruby/core/io/for_fd_tags.txt @@ -1,6 +1 @@ -fails:IO.for_fd raises an error if passed matching binary/text mode two ways -fails:IO.for_fd raises an error if passed conflicting binary/text mode two ways windows:IO.for_fd raises an Errno::EINVAL if the new mode is not compatible with the descriptor's current mode -fails:IO.for_fd ignores the :encoding option when the :external_encoding option is present -fails:IO.for_fd ignores the :encoding option when the :internal_encoding option is present -fails:IO.for_fd accepts options as keyword arguments From fe87e4284dd3dfc753cc3ace9ab06a7416579f25 Mon Sep 17 00:00:00 2001 From: "Thomas E. Enebo" Date: Thu, 29 Feb 2024 14:10:12 -0500 Subject: [PATCH 24/33] write shares same code as binwrite. update to also fix kwargs error --- core/src/main/java/org/jruby/RubyIO.java | 6 ++++-- spec/tags/ruby/core/io/binwrite_tags.txt | 2 +- spec/tags/ruby/core/io/write_tags.txt | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/org/jruby/RubyIO.java b/core/src/main/java/org/jruby/RubyIO.java index 95c8f7ae460..9cd275fee28 100644 --- a/core/src/main/java/org/jruby/RubyIO.java +++ b/core/src/main/java/org/jruby/RubyIO.java @@ -4278,25 +4278,27 @@ public static IRubyObject read(ThreadContext context, IRubyObject recv, IRubyObj } // rb_io_s_binwrite - @JRubyMethod(meta = true, required = 2, optional = 2, checkArity = false) + @JRubyMethod(meta = true, required = 2, optional = 2, checkArity = false, keywords = true) public static IRubyObject binwrite(ThreadContext context, IRubyObject recv, IRubyObject[] args) { return ioStaticWrite(context, recv, args, true); } // MRI: rb_io_s_write - @JRubyMethod(name = "write", meta = true, required = 2, optional = 2, checkArity = false) + @JRubyMethod(name = "write", meta = true, required = 2, optional = 2, checkArity = false, keywords = true) public static IRubyObject write(ThreadContext context, IRubyObject recv, IRubyObject[] argv) { return (ioStaticWrite(context, recv, argv, false)); } // MRI: io_s_write public static IRubyObject ioStaticWrite(ThreadContext context, IRubyObject recv, IRubyObject[] argv, boolean binary) { + boolean keywords = hasKeywords(ThreadContext.resetCallInfo(context)); final Ruby runtime = context.runtime; IRubyObject string, offset, opt; string = offset = opt = context.nil; switch (argv.length) { case 4: + if (!keywords) throw runtime.newArgumentError(argv.length, 2, 3); opt = argv[3].convertToHash(); offset = argv[2]; string = argv[1]; diff --git a/spec/tags/ruby/core/io/binwrite_tags.txt b/spec/tags/ruby/core/io/binwrite_tags.txt index c4b6883ab74..869162f3e9c 100644 --- a/spec/tags/ruby/core/io/binwrite_tags.txt +++ b/spec/tags/ruby/core/io/binwrite_tags.txt @@ -1,3 +1,3 @@ windows:IO.binwrite doesn't truncate the file and writes the given string if an offset is given windows:IO.binwrite doesn't truncate and writes at the given offset after passing empty opts -fails:IO.binwrite accepts options as a keyword argument + diff --git a/spec/tags/ruby/core/io/write_tags.txt b/spec/tags/ruby/core/io/write_tags.txt index 2963ea1c5fc..d1bef4e9feb 100644 --- a/spec/tags/ruby/core/io/write_tags.txt +++ b/spec/tags/ruby/core/io/write_tags.txt @@ -2,4 +2,4 @@ windows:IO.write doesn't truncate the file and writes the given string if an off windows:IO.write doesn't truncate and writes at the given offset after passing empty opts windows:IO#write on Windows normalizes line endings in text mode fails:IO#write on STDOUT raises SignalException SIGPIPE if the stream is closed instead of Errno::EPIPE like other IOs -fails:IO.write accepts options as a keyword argument + From 4ea0c219c054e92ac7d32c9f7736de85c671f961 Mon Sep 17 00:00:00 2001 From: "Thomas E. Enebo" Date: Thu, 29 Feb 2024 14:12:26 -0500 Subject: [PATCH 25/33] Another passing spec from this PR --- spec/tags/ruby/core/file/new_tags.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/tags/ruby/core/file/new_tags.txt b/spec/tags/ruby/core/file/new_tags.txt index fc248808761..a7f9223cff7 100644 --- a/spec/tags/ruby/core/file/new_tags.txt +++ b/spec/tags/ruby/core/file/new_tags.txt @@ -1,3 +1,3 @@ windows:File.new can't alter mode or permissions when opening a file windows:File.new opens directories -fails:File.new accepts options as a keyword argument + From e7001424e77cee927891553ed0917606d8592185 Mon Sep 17 00:00:00 2001 From: "Thomas E. Enebo" Date: Thu, 29 Feb 2024 14:20:19 -0500 Subject: [PATCH 26/33] Fix IO.read kwargs spec --- core/src/main/java/org/jruby/RubyIO.java | 5 +++-- spec/tags/ruby/core/io/read_tags.txt | 1 - 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/org/jruby/RubyIO.java b/core/src/main/java/org/jruby/RubyIO.java index 9cd275fee28..684d5696d36 100644 --- a/core/src/main/java/org/jruby/RubyIO.java +++ b/core/src/main/java/org/jruby/RubyIO.java @@ -4226,8 +4226,9 @@ public static IRubyObject binread(ThreadContext context, IRubyObject recv, IRuby } // Enebo: annotation processing forced me to do pangea method here... - @JRubyMethod(name = "read", meta = true, required = 1, optional = 3, checkArity = false) + @JRubyMethod(name = "read", meta = true, required = 1, optional = 3, checkArity = false, keywords = true) public static IRubyObject read(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block unusedBlock) { + boolean keywords = hasKeywords(ThreadContext.resetCallInfo(context)); int argc = Arity.checkArgumentCount(context, args, 1, 4); Ruby runtime = context.runtime; @@ -4237,7 +4238,7 @@ public static IRubyObject read(ThreadContext context, IRubyObject recv, IRubyObj { // rb_scan_args logic, basically if (argc > 3) { - if (!(args[3] instanceof RubyHash)) throw runtime.newTypeError("Must be a hash"); + if (!keywords) throw runtime.newArgumentError(args.length, 1, 4); options = (RubyHash) args[3]; offset = args[2]; length = args[1]; diff --git a/spec/tags/ruby/core/io/read_tags.txt b/spec/tags/ruby/core/io/read_tags.txt index 00e6cc06b17..7dccd01a3b7 100644 --- a/spec/tags/ruby/core/io/read_tags.txt +++ b/spec/tags/ruby/core/io/read_tags.txt @@ -5,4 +5,3 @@ windows:IO#read expands the buffer when too small windows:IO#read overwrites the buffer windows:IO#read truncates the buffer when too big windows:IO#read on Windows normalizes line endings in text mode -fails:IO.read accepts options as keyword arguments From c398ff1cee1cf8200016a79184c90f2a5631f9e6 Mon Sep 17 00:00:00 2001 From: "Thomas E. Enebo" Date: Thu, 29 Feb 2024 14:22:17 -0500 Subject: [PATCH 27/33] More kwargs specs passing from this PR --- spec/tags/ruby/core/io/initialize_tags.txt | 1 - spec/tags/ruby/core/io/new_tags.txt | 2 -- 2 files changed, 3 deletions(-) delete mode 100644 spec/tags/ruby/core/io/initialize_tags.txt delete mode 100644 spec/tags/ruby/core/io/new_tags.txt diff --git a/spec/tags/ruby/core/io/initialize_tags.txt b/spec/tags/ruby/core/io/initialize_tags.txt deleted file mode 100644 index bf476127ba7..00000000000 --- a/spec/tags/ruby/core/io/initialize_tags.txt +++ /dev/null @@ -1 +0,0 @@ -fails:IO#initialize accepts options as keyword arguments diff --git a/spec/tags/ruby/core/io/new_tags.txt b/spec/tags/ruby/core/io/new_tags.txt deleted file mode 100644 index c39219a21ed..00000000000 --- a/spec/tags/ruby/core/io/new_tags.txt +++ /dev/null @@ -1,2 +0,0 @@ -fails:IO.new accepts options as keyword arguments - From fb910e610fda0dada00bf652202d8e38bf5f70df Mon Sep 17 00:00:00 2001 From: "Thomas E. Enebo" Date: Fri, 1 Mar 2024 15:14:22 -0500 Subject: [PATCH 28/33] Redo java commandline calculation to work with newer Java's The old mechanism (which is still in this) only works for Java 8 and earlier. It walks all ClassLoaders and will cast to a unpublished type to ask for the URL for the jar the classloader represents. Java 9+ cannot do this. This fix only addresses the main Java jar by asking for a Resource for our Main class then getting a URI which we can make into a valid path to our jar. What this does not do is walk all CLs. It instead assumes all cp passed into the original Java process will work for a nested one. This may not work for 9+ but it is already broken if so. Java 8 continues to work the same way it always has. --- .../org/jruby/util/ClasspathLauncher.java | 84 ++++++++++++++----- 1 file changed, 65 insertions(+), 19 deletions(-) diff --git a/core/src/main/java/org/jruby/util/ClasspathLauncher.java b/core/src/main/java/org/jruby/util/ClasspathLauncher.java index 5f2c8400be6..80962fc1db3 100644 --- a/core/src/main/java/org/jruby/util/ClasspathLauncher.java +++ b/core/src/main/java/org/jruby/util/ClasspathLauncher.java @@ -1,36 +1,82 @@ package org.jruby.util; import java.io.File; +import java.net.MalformedURLException; +import java.net.URISyntaxException; import java.net.URL; import java.net.URLClassLoader; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.List; +import org.jruby.Main; import org.jruby.Ruby; public class ClasspathLauncher { - - public static String jrubyCommand(ClassLoader classLoader) { - String javaHome = SafePropertyAccessor.getProperty("java.home", ""); - // java.home is a JRE - String javaCmd = javaHome + "/bin/java"; - if (!new File(javaCmd).exists()) { - // java.home is a JDK - javaCmd = javaHome + "/jre/bin/java"; - } - if (!new File(javaCmd).exists()) { - // can't find it, hope it's in path - javaCmd = "java"; + + // Try and return reasonable java command which can be launched as a process. + private static String getJavaCommand() { + String home = SafePropertyAccessor.getProperty("java.home", ""); + String command = home + "/bin/java"; // java.home is JRE + + if (!new File(command).exists()) command = home + "/jre/bin/java"; // java.home is JDK + if (!new File(command).exists()) command = "java"; // hope java is in path + + return command; + } + + // This only retrieves the name of JRuby jar used (which seemingly only ever gets hit for + // jruby-complete.jar. + // Approach from: https://www.baeldung.com/java-full-path-of-jar-from-class + private static String getJRubyJar() { + Class
clazz = Main.class; + URL classResource = clazz.getResource(clazz.getSimpleName() + ".class"); + + if (classResource == null) return null; + + String jarPath = classResource.toString().replaceAll("^jar:(file:.*[.]jar)!/.*", "$1"); + + try { + return Paths.get(new URL(jarPath).toURI()).toString(); + } catch (URISyntaxException | MalformedURLException e) { + return null; } - StringBuilder command = new StringBuilder().append(javaCmd).append(" -cp "); + } + + public static String jrubyCommand(ClassLoader classLoader) { + StringBuilder command = new StringBuilder().append(getJavaCommand()).append(" -cp "); + String mainJar = getJRubyJar(); + if (classLoader instanceof URLClassLoader) { - for(URL url : ((URLClassLoader) classLoader).getURLs()) { - String path = URLUtil.getPlatformPath(url); + getClassPathEntriesJava8AndBelow((URLClassLoader) classLoader, command, mainJar); + } else { + // We fail back to just using what is set by the system property. This might be missing entries + // otherwise added during runtime. This might be fine since if we loaded them once from previous + // execution we probably will again in the new execution. + String path = SafePropertyAccessor.getProperty("java.class.path"); + if (mainJar != null) { + command.append(mainJar); if (path != null) command.append(File.pathSeparatorChar).append(path); + } else { + command.append(path); } - } else { - command.append(File.pathSeparatorChar).append(SafePropertyAccessor.getProperty("java.class.path")); } - command.append(" org.jruby.Main"); - return command.toString(); + + return command.append(" org.jruby.Main").toString(); + } + + // FIXME: Java 8 is capable of building up complete list of jars from classloaders but Java 9+ is not without + // the use of the instrumentation APIs. + private static void getClassPathEntriesJava8AndBelow(URLClassLoader classLoader, StringBuilder command, String mainJar) { + List entries = new ArrayList<>(); + if (mainJar != null) entries.add(mainJar); + + for(URL url : classLoader.getURLs()) { + String path = URLUtil.getPlatformPath(url); + if (path != null) entries.add(path); + } + + command.append(String.join(File.pathSeparator, entries)); } public static String jrubyCommand(Ruby runtime) { From 4b2e0477639220e420c3dd4e95345f72837b9ab8 Mon Sep 17 00:00:00 2001 From: "Thomas E. Enebo" Date: Tue, 5 Mar 2024 16:06:31 -0500 Subject: [PATCH 29/33] Add-Opens for complete -jar runs as expected in later Java's --- maven/jruby-complete/pom.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/maven/jruby-complete/pom.rb b/maven/jruby-complete/pom.rb index 704c76d2ef4..711f2f04769 100644 --- a/maven/jruby-complete/pom.rb +++ b/maven/jruby-complete/pom.rb @@ -41,7 +41,8 @@ :mainClass => 'org.jruby.Main' }, manifestEntries: { - 'Automatic-Module-Name' => 'org.jruby.complete' + 'Automatic-Module-Name' => 'org.jruby.complete', + 'Add-Opens' => 'java.base/java.io java.base/java.nio.channels java.base/sun.nio.ch java.management/sun.management' } }, :instructions => { From 46e67033e8e5df0bc38f12f6c0d40c15c52fdd3f Mon Sep 17 00:00:00 2001 From: "Thomas E. Enebo" Date: Wed, 6 Mar 2024 12:45:02 -0500 Subject: [PATCH 30/33] Allow extended DateTime to still be constructed using DateTime --- core/src/main/java/org/jruby/RubyModule.java | 6 +++++- .../main/java/org/jruby/ext/date/RubyDate.java | 18 +++++++++++------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/org/jruby/RubyModule.java b/core/src/main/java/org/jruby/RubyModule.java index e98dbfd8a4d..c4e24d337d1 100644 --- a/core/src/main/java/org/jruby/RubyModule.java +++ b/core/src/main/java/org/jruby/RubyModule.java @@ -303,7 +303,7 @@ public boolean isKindOf(IRubyObject obj, RubyModule type) { // Not sure how but this happens in test_objects_are_released_by_cache_map if (cl == null) return false; - return cl.searchAncestor(type.getDelegate().getOrigin()) != null; + return cl.hasAncestor(type); } } @@ -324,6 +324,10 @@ public boolean isInstance(IRubyObject object) { return kindOf.isKindOf(object, this); } + public boolean hasAncestor(RubyModule type) { + return searchAncestor(type.getDelegate().getOrigin()) != null; + } + public Map getConstantMap() { return getOrigin().constants; } diff --git a/core/src/main/java/org/jruby/ext/date/RubyDate.java b/core/src/main/java/org/jruby/ext/date/RubyDate.java index 90ec12e50c8..e8cbc3f6dc0 100644 --- a/core/src/main/java/org/jruby/ext/date/RubyDate.java +++ b/core/src/main/java/org/jruby/ext/date/RubyDate.java @@ -130,6 +130,10 @@ static RubyClass getDateTime(final Ruby runtime) { return (RubyClass) runtime.getObject().getConstantAt("DateTime"); } + static boolean isDateTime(final Ruby runtime, final IRubyObject type) { + return ((RubyModule) type).hasAncestor(getDateTime(runtime)); + } + protected RubyDate(Ruby runtime, RubyClass klass) { this(runtime, klass, defaultDateTime); } @@ -292,7 +296,7 @@ public IRubyObject initialize_copy(IRubyObject original) { */ @JRubyMethod(name = "new!", meta = true, visibility = Visibility.PRIVATE) public static RubyDate new_(ThreadContext context, IRubyObject self) { - if (self == getDateTime(context.runtime)) { + if (isDateTime(context.runtime, self)) { return new RubyDateTime(context.runtime, 0, CHRONO_ITALY_UTC); } return new RubyDate(context.runtime, 0, CHRONO_ITALY_UTC); @@ -304,12 +308,12 @@ public static RubyDate new_(ThreadContext context, IRubyObject self) { @JRubyMethod(name = "new!", meta = true, visibility = Visibility.PRIVATE) public static RubyDate new_(ThreadContext context, IRubyObject self, IRubyObject ajd) { if (ajd instanceof JavaProxy) { // backwards - compatibility with JRuby's date.rb - if (self == getDateTime(context.runtime)) { - return new RubyDateTime(context.runtime, (RubyClass) self, (DateTime) JavaUtil.unwrapJavaValue(ajd)); + if (isDateTime(context.runtime, self)) { + return new RubyDateTime(context.runtime, (RubyClass) self, JavaUtil.unwrapJavaValue(ajd)); } - return new RubyDate(context.runtime, (RubyClass) self, (DateTime) JavaUtil.unwrapJavaValue(ajd)); + return new RubyDate(context.runtime, (RubyClass) self, JavaUtil.unwrapJavaValue(ajd)); } - if (self == getDateTime(context.runtime)) { + if (isDateTime(context.runtime, self)) { return new RubyDateTime(context, (RubyClass) self, ajd, CHRONO_ITALY_UTC, 0); } return new RubyDate(context, (RubyClass) self, ajd, CHRONO_ITALY_UTC, 0); @@ -320,7 +324,7 @@ public static RubyDate new_(ThreadContext context, IRubyObject self, IRubyObject */ @JRubyMethod(name = "new!", meta = true, visibility = Visibility.PRIVATE) public static RubyDate new_(ThreadContext context, IRubyObject self, IRubyObject ajd, IRubyObject of) { - if (self == getDateTime(context.runtime)) { + if (isDateTime(context.runtime, self)) { return new RubyDateTime(context.runtime, (RubyClass) self).initialize(context, ajd, of); } return new RubyDate(context.runtime, (RubyClass) self).initialize(context, ajd, of); @@ -331,7 +335,7 @@ public static RubyDate new_(ThreadContext context, IRubyObject self, IRubyObject */ @JRubyMethod(name = "new!", meta = true, visibility = Visibility.PRIVATE) public static RubyDate new_(ThreadContext context, IRubyObject self, IRubyObject ajd, IRubyObject of, IRubyObject sg) { - if (self == getDateTime(context.runtime)) { + if (isDateTime(context.runtime, self)) { return new RubyDateTime(context.runtime, (RubyClass) self).initialize(context, ajd, of, sg); } return new RubyDate(context.runtime, (RubyClass) self).initialize(context, ajd, of, sg); From 4114fc5a539d92f1d5f692cd1b2974a29f44429e Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Tue, 12 Mar 2024 00:34:23 -0500 Subject: [PATCH 31/33] Backport cat19 name change to support StringIO migration See https://github.com/ruby/stringio/issues/83 --- core/src/main/java/org/jruby/RubyString.java | 23 +++++++++++++++---- .../java/org/jruby/ir/targets/JVMVisitor.java | 2 +- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/org/jruby/RubyString.java b/core/src/main/java/org/jruby/RubyString.java index f34cb91e960..ad15aafd7ae 100644 --- a/core/src/main/java/org/jruby/RubyString.java +++ b/core/src/main/java/org/jruby/RubyString.java @@ -1404,9 +1404,17 @@ public final RubyString cat(byte[] str, int beg, int len) { return this; } - // // rb_str_buf_append against VALUE + // Needs to remain in place until StringIO has migrated to the new methods + // See https://github.com/ruby/stringio/issues/83 + @Deprecated public final RubyString cat19(RubyString str2) { - int str2_cr = cat19(str2.getByteList(), str2.getCodeRange()); + return catWithCodeRange(str2); + } + + // // rb_str_buf_append against VALUE + public final RubyString catWithCodeRange(RubyString str2) { + ByteList other = str2.getByteList(); + int str2_cr = catWithCodeRange(other, str2.getCodeRange()); str2.setCodeRange(str2_cr); @@ -1414,12 +1422,19 @@ public final RubyString cat19(RubyString str2) { } public final RubyString cat(ByteList other, int codeRange) { - cat19(other, codeRange); + catWithCodeRange(other, codeRange); return this; } - // rb_str_buf_append against ptr + // Needs to remain in place until StringIO has migrated to the new methods + // See https://github.com/ruby/stringio/issues/83 + @Deprecated public final int cat19(ByteList other, int codeRange) { + return catWithCodeRange(other, codeRange); + } + + // rb_str_buf_append against ptr + public final int catWithCodeRange(ByteList other, int codeRange) { return EncodingUtils.encCrStrBufCat(metaClass.runtime, this, other, other.getEncoding(), codeRange); } diff --git a/core/src/main/java/org/jruby/ir/targets/JVMVisitor.java b/core/src/main/java/org/jruby/ir/targets/JVMVisitor.java index 55135633a8e..d28820a0dc3 100644 --- a/core/src/main/java/org/jruby/ir/targets/JVMVisitor.java +++ b/core/src/main/java/org/jruby/ir/targets/JVMVisitor.java @@ -1179,7 +1179,7 @@ public void BuildCompoundStringInstr(BuildCompoundStringInstr compoundstring) { // we have bytelist and CR in hand, go straight to cat logic FrozenString str = (FrozenString) p; jvmMethod().getValueCompiler().pushFrozenString(str.getByteList(), str.getCodeRange(), str.getFile(), str.getLine()); - jvmAdapter().invokevirtual(p(RubyString.class), "cat19", sig(RubyString.class, RubyString.class)); + jvmAdapter().invokevirtual(p(RubyString.class), "catWithCodeRange", sig(RubyString.class, RubyString.class)); } else if (p instanceof StringLiteral) { StringLiteral str = (StringLiteral) p; jvmMethod().getValueCompiler().pushByteList(str.getByteList()); From 2476e8b6779cf3c689a236bebdf5c485f88b33fb Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Tue, 12 Mar 2024 00:44:57 -0500 Subject: [PATCH 32/33] Migrate all callers of cat19 to new names See https://github.com/ruby/stringio/issues/83 --- core/src/main/java/org/jruby/RubyArray.java | 10 +++---- .../main/java/org/jruby/RubyEnumerator.java | 6 ++-- core/src/main/java/org/jruby/RubyHash.java | 4 +-- core/src/main/java/org/jruby/RubyKernel.java | 3 +- core/src/main/java/org/jruby/RubyMethod.java | 10 +++---- core/src/main/java/org/jruby/RubyModule.java | 13 ++++---- core/src/main/java/org/jruby/RubyString.java | 29 +++++++++--------- core/src/main/java/org/jruby/RubyStruct.java | 6 ++-- .../main/java/org/jruby/ext/set/RubySet.java | 2 +- .../jruby/java/proxies/ArrayJavaProxy.java | 2 +- .../org/jruby/java/proxies/MapJavaProxy.java | 3 +- .../org/jruby/javasupport/ext/JavaLang.java | 2 +- .../org/jruby/javasupport/ext/JavaUtil.java | 2 +- .../jruby/specialized/RubyArrayOneObject.java | 3 +- .../jruby/specialized/RubyArrayTwoObject.java | 5 ++-- .../main/java/org/jruby/util/Inspector.java | 3 +- .../org/jruby/util/RubyStringBuilder.java | 30 +++++++++---------- .../java/org/jruby/util/io/EncodingUtils.java | 6 ++-- 18 files changed, 69 insertions(+), 70 deletions(-) diff --git a/core/src/main/java/org/jruby/RubyArray.java b/core/src/main/java/org/jruby/RubyArray.java index 40c69a3ee5e..761f31c3726 100644 --- a/core/src/main/java/org/jruby/RubyArray.java +++ b/core/src/main/java/org/jruby/RubyArray.java @@ -41,7 +41,6 @@ import java.io.IOException; import java.lang.reflect.Array; import java.math.BigInteger; -import java.util.ArrayList; import java.util.Arrays; import java.util.BitSet; import java.util.Collection; @@ -59,7 +58,6 @@ import org.jruby.ast.util.ArgsUtil; import org.jruby.common.IRubyWarnings.ID; import org.jruby.exceptions.RaiseException; -import org.jruby.exceptions.RangeError; import org.jruby.java.util.ArrayUtils; import org.jruby.javasupport.JavaUtil; import org.jruby.runtime.Arity; @@ -1851,7 +1849,7 @@ protected IRubyObject inspectAry(ThreadContext context) { } else { EncodingUtils.encAssociateIndex(str, s.getEncoding()); } - str.cat19(s); + str.catWithCodeRange(s); } str.cat((byte) ']'); @@ -2088,7 +2086,7 @@ protected int joinStrings(RubyString sep, int max, RubyString result) { for (i = 0; i < max; i++) { IRubyObject val = eltInternal(i); if (!(val instanceof RubyString)) break; - if (i > 0 && sep != null) result.cat19(sep); + if (i > 0 && sep != null) result.catWithCodeRange(sep); result.append(val); } } catch (ArrayIndexOutOfBoundsException e) { @@ -2106,7 +2104,7 @@ private RubyString joinAny(ThreadContext context, RubyString sep, int i, RubyStr JavaSites.CheckedSites to_ary_checked = null; for (; i < realLength; i++) { - if (i > 0 && sep != null) result.cat19(sep); + if (i > 0 && sep != null) result.catWithCodeRange(sep); IRubyObject val = eltOk(i); @@ -2137,7 +2135,7 @@ private RubyString joinAny(ThreadContext context, RubyString sep, int i, RubyStr // MRI: ary_join_1, str_join label private static void strJoin(RubyString result, RubyString val, boolean[] first) { - result.cat19(val); + result.catWithCodeRange(val); if (first[0]) { result.setEncoding(val.getEncoding()); first[0] = false; diff --git a/core/src/main/java/org/jruby/RubyEnumerator.java b/core/src/main/java/org/jruby/RubyEnumerator.java index 32b16066daa..7d5ebbf5fbc 100644 --- a/core/src/main/java/org/jruby/RubyEnumerator.java +++ b/core/src/main/java/org/jruby/RubyEnumerator.java @@ -367,14 +367,14 @@ private IRubyObject inspect(ThreadContext context, boolean recurse) { if (recurse) { return result.catString("...>"); } else { - result.cat19(RubyObject.inspect(context, object)); + result.catWithCodeRange(RubyObject.inspect(context, object)); result.cat(':'); - result.cat19(getMethod().asString()); + result.catWithCodeRange(getMethod().asString()); if (methodArgs.length > 0) { result.cat('('); for (int i= 0; i < methodArgs.length; i++) { if (methodArgsHasKeywords && i == 0) break; - result.cat19(RubyObject.inspect(context, methodArgs[i])); + result.catWithCodeRange(RubyObject.inspect(context, methodArgs[i])); if (i < methodArgs.length - 1) { result.catString(", "); } else { diff --git a/core/src/main/java/org/jruby/RubyHash.java b/core/src/main/java/org/jruby/RubyHash.java index 51a29f73ea1..c974ed8d6be 100644 --- a/core/src/main/java/org/jruby/RubyHash.java +++ b/core/src/main/java/org/jruby/RubyHash.java @@ -928,9 +928,9 @@ public void visit(ThreadContext context, RubyHash self, IRubyObject key, IRubyOb if (index > 0) bytes.append((byte) ',').append((byte) ' '); - str.cat19(keyStr); + str.catWithCodeRange(keyStr); bytes.append((byte) '=').append((byte) '>'); - str.cat19(valStr); + str.catWithCodeRange(valStr); } }; diff --git a/core/src/main/java/org/jruby/RubyKernel.java b/core/src/main/java/org/jruby/RubyKernel.java index 8235951c5a4..7b9dc54190d 100644 --- a/core/src/main/java/org/jruby/RubyKernel.java +++ b/core/src/main/java/org/jruby/RubyKernel.java @@ -1625,7 +1625,8 @@ public static IRubyObject trace_var(ThreadContext context, IRubyObject recv, IRu proc = RubyProc.newProc(context.runtime, block, Block.Type.PROC); } else if (argc == 2) { if (args[1] instanceof RubyString) { - RubyString s = context.runtime.newString("proc {").cat19(((RubyString) args[1])).cat('}'); + RubyString rubyString = context.runtime.newString("proc {"); + RubyString s = rubyString.catWithCodeRange(((RubyString) args[1])).cat('}'); proc = (RubyProc) evalCommon(context, recv, new IRubyObject[] { s }); } else { proc = (RubyProc) TypeConverter.convertToType(args[1], context.runtime.getProc(), "to_proc", true); diff --git a/core/src/main/java/org/jruby/RubyMethod.java b/core/src/main/java/org/jruby/RubyMethod.java index 2725b565a9a..2bc9e876dad 100644 --- a/core/src/main/java/org/jruby/RubyMethod.java +++ b/core/src/main/java/org/jruby/RubyMethod.java @@ -47,10 +47,8 @@ import org.jruby.runtime.JavaSites; import org.jruby.runtime.MethodBlockBody; import org.jruby.runtime.ObjectAllocator; -import org.jruby.runtime.PositionAware; import org.jruby.runtime.Signature; import org.jruby.runtime.ThreadContext; -import org.jruby.runtime.backtrace.TraceType; import org.jruby.runtime.builtin.IRubyObject; import org.jruby.runtime.callsite.CacheEntry; @@ -282,14 +280,14 @@ public IRubyObject inspect() { if (mklass.isSingleton()) { IRubyObject attached = ((MetaClass) mklass).getAttached(); if (receiver == null) { - str.cat19(inspect(context, mklass).convertToString()); + str.catWithCodeRange(inspect(context, mklass).convertToString()); } else if (receiver == attached) { - str.cat19(inspect(context, attached).convertToString()); + str.catWithCodeRange(inspect(context, attached).convertToString()); sharp = "."; } else { - str.cat19(inspect(context, receiver).convertToString()); + str.catWithCodeRange(inspect(context, receiver).convertToString()); str.catString("("); - str.cat19(inspect(context, attached).convertToString()); + str.catWithCodeRange(inspect(context, attached).convertToString()); str.catString(")"); sharp = "."; } diff --git a/core/src/main/java/org/jruby/RubyModule.java b/core/src/main/java/org/jruby/RubyModule.java index c4e24d337d1..239e70274cd 100644 --- a/core/src/main/java/org/jruby/RubyModule.java +++ b/core/src/main/java/org/jruby/RubyModule.java @@ -713,9 +713,10 @@ private RubyString calculateRubyName() { RubyString fullName = runtime.newString(); // newString creates empty ByteList which ends up as fullName.setEncoding(USASCIIEncoding.INSTANCE); // ASCII-8BIT. 8BIT is unfriendly to string concats. for (RubyString parent: parents) { - fullName.cat19(parent).cat19(colons); + RubyString rubyString = fullName.catWithCodeRange(parent); + rubyString.catWithCodeRange(colons); } - fullName.cat19(rubyBaseName()); + fullName.catWithCodeRange(rubyBaseName()); fullName.setFrozen(true); @@ -2786,9 +2787,9 @@ public RubyString to_s() { RubyString buffer = runtime.newString("#', buffer.getEncoding()); @@ -2800,9 +2801,9 @@ public RubyString to_s() { if (refinedClass != null) { RubyString buffer = runtime.newString("#', buffer.getEncoding()); return buffer; diff --git a/core/src/main/java/org/jruby/RubyString.java b/core/src/main/java/org/jruby/RubyString.java index ad15aafd7ae..e53b7d51d69 100644 --- a/core/src/main/java/org/jruby/RubyString.java +++ b/core/src/main/java/org/jruby/RubyString.java @@ -1439,7 +1439,8 @@ public final int catWithCodeRange(ByteList other, int codeRange) { } public final RubyString catString(String str) { - cat19(encodeBytelist(str, getEncoding()), CR_UNKNOWN); + ByteList other = encodeBytelist(str, getEncoding()); + catWithCodeRange(other, CR_UNKNOWN); return this; } @@ -2381,7 +2382,7 @@ public IRubyObject insert(ThreadContext context, IRubyObject indexArg, IRubyObje int index = RubyNumeric.num2int(indexArg); if (index == -1) { modifyCheck(); - return cat19(str); + return catWithCodeRange(str); } if (index < 0) index++; replaceInternal19(index, 0, str); @@ -2676,18 +2677,18 @@ public RubyString append(IRubyObject other) { modifyCheck(); if (other instanceof RubyFloat) { - return cat19((RubyString) ((RubyFloat) other).to_s()); + return catWithCodeRange((RubyString) ((RubyFloat) other).to_s()); } else if (other instanceof RubySymbol) { - cat19(((RubySymbol) other).getBytes(), CR_UNKNOWN); + catWithCodeRange(((RubySymbol) other).getBytes(), CR_UNKNOWN); return this; } - return cat19(other.convertToString()); + return catWithCodeRange(other.convertToString()); } public RubyString append(RubyString other) { modifyCheck(); - return cat19(other); + return catWithCodeRange(other); } @Deprecated @@ -2705,19 +2706,19 @@ public RubyString appendAsDynamicString(IRubyObject other) { modifyCheck(); if (other instanceof RubyFloat) { - return cat19((RubyString) ((RubyFloat) other).to_s()); + return catWithCodeRange((RubyString) ((RubyFloat) other).to_s()); } else if (other instanceof RubySymbol) { - cat19(((RubySymbol) other).getBytes(), 0); + catWithCodeRange(((RubySymbol) other).getBytes(), 0); return this; } - return cat19(other.asString()); + return catWithCodeRange(other.asString()); } // NOTE: append(RubyString) should pbly just do the encoding aware cat final RubyString append19(RubyString other) { modifyCheck(); - return cat19(other); + return catWithCodeRange(other); } /** rb_str_concat @@ -2745,7 +2746,7 @@ public RubyString concatSingle(ThreadContext context, IRubyObject other) { } if (other instanceof RubyFloat) { modifyCheck(); - return cat19((RubyString) ((RubyFloat) other).to_s()); + return catWithCodeRange((RubyString) ((RubyFloat) other).to_s()); } if (other instanceof RubySymbol) throw context.runtime.newTypeError("can't convert Symbol into String"); @@ -2776,7 +2777,7 @@ public RubyString concat(ThreadContext context, IRubyObject[] objs) { tmp.concatSingle(context, obj); } - cat19(tmp); + catWithCodeRange(tmp); } return this; @@ -3321,7 +3322,7 @@ private IRubyObject gsubCommon(ThreadContext context, Block block, RubyString re int len = begz - offset; if (len != 0) dest.cat(spBytes, cp, len, str_enc); - dest.cat19(val); + dest.catWithCodeRange(val); offset = endz; if (begz == endz) { if (spLen <= endz) break; @@ -3413,7 +3414,7 @@ private IRubyObject gsubCommon(ThreadContext context, Block block, RubyString re int len = begz - offset; if (len != 0) dest.cat(spBytes, cp, len, str_enc); - dest.cat19(val); + dest.catWithCodeRange(val); offset = endz; if (begz == endz) { if (spLen <= endz) break; diff --git a/core/src/main/java/org/jruby/RubyStruct.java b/core/src/main/java/org/jruby/RubyStruct.java index 1907568acb5..b2ffa7d9fa5 100644 --- a/core/src/main/java/org/jruby/RubyStruct.java +++ b/core/src/main/java/org/jruby/RubyStruct.java @@ -683,12 +683,12 @@ else if (first != '#') { } RubySymbol slot = (RubySymbol) member.eltInternal(i); if (slot.validLocalVariableName() || slot.validConstantName()) { - buffer.cat19(RubyString.objAsString(context, slot)); + buffer.catWithCodeRange(RubyString.objAsString(context, slot)); } else { - buffer.cat19(((RubyString) slot.inspect(context))); + buffer.catWithCodeRange(((RubyString) slot.inspect(context))); } buffer.cat('='); - buffer.cat19(inspect(context, values[i])); + buffer.catWithCodeRange(inspect(context, values[i])); } buffer.cat('>'); diff --git a/core/src/main/java/org/jruby/ext/set/RubySet.java b/core/src/main/java/org/jruby/ext/set/RubySet.java index 8420328d964..b49e344175e 100644 --- a/core/src/main/java/org/jruby/ext/set/RubySet.java +++ b/core/src/main/java/org/jruby/ext/set/RubySet.java @@ -1215,7 +1215,7 @@ private void inspectSet(final ThreadContext context, final RubyString str) { final RubyString s = inspect(context, elem); if ( notFirst ) str.cat((byte) ',').cat((byte) ' '); else str.setEncoding( s.getEncoding() ); notFirst = true; - str.cat19( s ); + str.catWithCodeRange(s); } str.cat((byte) '}'); diff --git a/core/src/main/java/org/jruby/java/proxies/ArrayJavaProxy.java b/core/src/main/java/org/jruby/java/proxies/ArrayJavaProxy.java index f7c32da91ed..d5a6c4d0fb0 100644 --- a/core/src/main/java/org/jruby/java/proxies/ArrayJavaProxy.java +++ b/core/src/main/java/org/jruby/java/proxies/ArrayJavaProxy.java @@ -540,7 +540,7 @@ public RubyString inspect(ThreadContext context) { } else { buf.setEncoding(s.getEncoding()); } - buf.cat19(s); + buf.catWithCodeRange(s); } RubyStringBuilder.cat(runtime, buf, END_BRACKET); // ] } finally { diff --git a/core/src/main/java/org/jruby/java/proxies/MapJavaProxy.java b/core/src/main/java/org/jruby/java/proxies/MapJavaProxy.java index 5f2652e81de..4224c8ed7bf 100644 --- a/core/src/main/java/org/jruby/java/proxies/MapJavaProxy.java +++ b/core/src/main/java/org/jruby/java/proxies/MapJavaProxy.java @@ -41,7 +41,6 @@ import org.jruby.anno.JRubyMethod; import org.jruby.exceptions.RaiseException; import org.jruby.javasupport.JavaUtil; -import org.jruby.runtime.Arity; import org.jruby.runtime.Block; import org.jruby.runtime.ThreadContext; import org.jruby.runtime.Visibility; @@ -136,7 +135,7 @@ public IRubyObject inspect(ThreadContext context) { } else { try { runtime.registerInspecting(map); - buf.cat19(inspectHash(context)); + buf.catWithCodeRange(inspectHash(context)); } finally { runtime.unregisterInspecting(map); } diff --git a/core/src/main/java/org/jruby/javasupport/ext/JavaLang.java b/core/src/main/java/org/jruby/javasupport/ext/JavaLang.java index 65aeea85427..976de652d9e 100644 --- a/core/src/main/java/org/jruby/javasupport/ext/JavaLang.java +++ b/core/src/main/java/org/jruby/javasupport/ext/JavaLang.java @@ -825,7 +825,7 @@ public static IRubyObject inspect(final ThreadContext context, final IRubyObject RubyString buf = inspectPrefix(context, self.getMetaClass()); RubyStringBuilder.cat(context.runtime, buf, SPACE); - buf.cat19(RubyString.newString(context.runtime, str).inspect()); + buf.catWithCodeRange(RubyString.newString(context.runtime, str).inspect()); RubyStringBuilder.cat(context.runtime, buf, GT); // > return buf; diff --git a/core/src/main/java/org/jruby/javasupport/ext/JavaUtil.java b/core/src/main/java/org/jruby/javasupport/ext/JavaUtil.java index 4b8e9222f95..018abb3ac7a 100644 --- a/core/src/main/java/org/jruby/javasupport/ext/JavaUtil.java +++ b/core/src/main/java/org/jruby/javasupport/ext/JavaUtil.java @@ -294,7 +294,7 @@ static void inspectElements(final ThreadContext context, final RubyString buf, f } else { buf.setEncoding(s.getEncoding()); } - buf.cat19(s); + buf.catWithCodeRange(s); } } diff --git a/core/src/main/java/org/jruby/specialized/RubyArrayOneObject.java b/core/src/main/java/org/jruby/specialized/RubyArrayOneObject.java index d4e3a938672..e30c1eab14e 100644 --- a/core/src/main/java/org/jruby/specialized/RubyArrayOneObject.java +++ b/core/src/main/java/org/jruby/specialized/RubyArrayOneObject.java @@ -1,6 +1,5 @@ package org.jruby.specialized; -import org.jcodings.Encoding; import org.jcodings.specific.USASCIIEncoding; import org.jruby.Ruby; import org.jruby.RubyArray; @@ -141,7 +140,7 @@ protected IRubyObject inspectAry(ThreadContext context) { RubyString s = inspect(context, value); EncodingUtils.encAssociateIndex(str, s.getEncoding()); - str.cat19(s); + str.catWithCodeRange(s); str.cat((byte) ']'); diff --git a/core/src/main/java/org/jruby/specialized/RubyArrayTwoObject.java b/core/src/main/java/org/jruby/specialized/RubyArrayTwoObject.java index 07410013519..187f3c3e891 100644 --- a/core/src/main/java/org/jruby/specialized/RubyArrayTwoObject.java +++ b/core/src/main/java/org/jruby/specialized/RubyArrayTwoObject.java @@ -1,6 +1,5 @@ package org.jruby.specialized; -import org.jcodings.Encoding; import org.jcodings.specific.USASCIIEncoding; import org.jruby.Ruby; import org.jruby.RubyArray; @@ -158,12 +157,12 @@ protected IRubyObject inspectAry(ThreadContext context) { RubyString s1 = inspect(context, car); RubyString s2 = inspect(context, cdr); EncodingUtils.encAssociateIndex(str, s1.getEncoding()); - str.cat19(s1); + str.catWithCodeRange(s1); ByteList bytes = str.getByteList(); bytes.append((byte) ',').append((byte) ' '); - str.cat19(s2); + str.catWithCodeRange(s2); str.cat((byte) ']'); diff --git a/core/src/main/java/org/jruby/util/Inspector.java b/core/src/main/java/org/jruby/util/Inspector.java index 9f299bc4fb8..a2bdff28444 100644 --- a/core/src/main/java/org/jruby/util/Inspector.java +++ b/core/src/main/java/org/jruby/util/Inspector.java @@ -52,7 +52,8 @@ public static RubyString inspectPrefixTypeOnly(final ThreadContext context, fina RubyString name = RubyStringBuilder.types(context, type); // minimal: "#" RubyString buf = RubyString.newStringLight(context.runtime, 2 + name.length() + 3 + 8 + 1, USASCIIEncoding.INSTANCE); - buf.cat('#').cat('<').cat19(name); + RubyString rubyString = buf.cat('#').cat('<'); + rubyString.catWithCodeRange(name); return buf; } diff --git a/core/src/main/java/org/jruby/util/RubyStringBuilder.java b/core/src/main/java/org/jruby/util/RubyStringBuilder.java index eb2028a2efd..ff2b74c34a4 100644 --- a/core/src/main/java/org/jruby/util/RubyStringBuilder.java +++ b/core/src/main/java/org/jruby/util/RubyStringBuilder.java @@ -175,7 +175,7 @@ public static String str(Ruby runtime, IRubyObject value, String message) { public static String str(Ruby runtime, String message, IRubyObject value) { RubyString buf = runtime.newString(message); - buf.cat19(value.asString()); + buf.catWithCodeRange(value.asString()); return buf.toString(); } @@ -183,7 +183,7 @@ public static String str(Ruby runtime, String message, IRubyObject value) { public static String str(Ruby runtime, String messageBegin, IRubyObject value, String messageEnd) { RubyString buf = runtime.newString(messageBegin); - buf.cat19(value.asString()); + buf.catWithCodeRange(value.asString()); cat(runtime, buf, messageEnd); return buf.toString(); @@ -193,7 +193,7 @@ public static String str(Ruby runtime, IRubyObject value, String message, IRubyO RubyString buf = (RubyString) value.asString().dup(); cat(runtime, buf, message); - buf.cat19(value2.asString()); + buf.catWithCodeRange(value2.asString()); return buf.toString(); } @@ -202,7 +202,7 @@ public static String str(Ruby runtime, IRubyObject value, String message, IRubyO RubyString buf = (RubyString) value.asString().dup(); cat(runtime, buf, message); - buf.cat19(value2.asString()); + buf.catWithCodeRange(value2.asString()); cat(runtime, buf, message2); return buf.toString(); @@ -211,9 +211,9 @@ public static String str(Ruby runtime, IRubyObject value, String message, IRubyO public static String str(Ruby runtime, String messageBegin, IRubyObject value, String messageMiddle, IRubyObject value2) { RubyString buf = runtime.newString(messageBegin); - buf.cat19(value.asString()); + buf.catWithCodeRange(value.asString()); cat(runtime, buf, messageMiddle); - buf.cat19(value2.asString()); + buf.catWithCodeRange(value2.asString()); return buf.toString(); } @@ -221,9 +221,9 @@ public static String str(Ruby runtime, String messageBegin, IRubyObject value, S public static String str(Ruby runtime, String messageBegin, IRubyObject value, String messageMiddle, IRubyObject value2, String messageEnd) { RubyString buf = runtime.newString(messageBegin); - buf.cat19(value.asString()); + buf.catWithCodeRange(value.asString()); cat(runtime, buf, messageMiddle); - buf.cat19(value2.asString()); + buf.catWithCodeRange(value2.asString()); cat(runtime, buf, messageEnd); return buf.toString(); @@ -233,11 +233,11 @@ public static String str(Ruby runtime, String messageBegin, IRubyObject value, S String messageMiddle2, IRubyObject value3, String messageEnd) { RubyString buf = runtime.newString(messageBegin); - buf.cat19(value.asString()); + buf.catWithCodeRange(value.asString()); cat(runtime, buf, messageMiddle); - buf.cat19(value2.asString()); + buf.catWithCodeRange(value2.asString()); cat(runtime, buf, messageMiddle2); - buf.cat19(value3.asString()); + buf.catWithCodeRange(value3.asString()); cat(runtime, buf, messageEnd); return buf.toString(); @@ -247,13 +247,13 @@ public static String str(Ruby runtime, String messageBegin, IRubyObject value, S String messageMiddle2, IRubyObject value3, String messageMiddle3, RubyString value4, String messageEnd) { RubyString buf = runtime.newString(messageBegin); - buf.cat19(value.asString()); + buf.catWithCodeRange(value.asString()); cat(runtime, buf, messageMiddle); - buf.cat19(value2); + buf.catWithCodeRange(value2); cat(runtime, buf, messageMiddle2); - buf.cat19(value3.asString()); + buf.catWithCodeRange(value3.asString()); cat(runtime, buf, messageMiddle3); - buf.cat19(value4); + buf.catWithCodeRange(value4); cat(runtime, buf, messageEnd); return buf.toString(); diff --git a/core/src/main/java/org/jruby/util/io/EncodingUtils.java b/core/src/main/java/org/jruby/util/io/EncodingUtils.java index 81d01d02561..717b6ddd104 100644 --- a/core/src/main/java/org/jruby/util/io/EncodingUtils.java +++ b/core/src/main/java/org/jruby/util/io/EncodingUtils.java @@ -400,7 +400,8 @@ public static RubyString newExternalStringWithEncoding(Ruby runtime, String stri /* when the conversion failed for some reason, just ignore the * default_internal and result in the given encoding as-is. */ try { - convertedString.cat19(encodeBytelist(string, encoding), CR_UNKNOWN); + ByteList other = encodeBytelist(string, encoding); + convertedString.catWithCodeRange(other, CR_UNKNOWN); } catch (org.jruby.exceptions.EncodingError.CompatibilityError ce) { return newString(runtime, string, encoding); } @@ -435,7 +436,8 @@ public static RubyString newExternalStringWithEncoding(Ruby runtime, ByteList by /* when the conversion failed for some reason, just ignore the * default_internal and result in the given encoding as-is. */ try { - convertedString.cat19(encodeBytelist(bytelist, encoding), CR_UNKNOWN); + ByteList other = encodeBytelist(bytelist, encoding); + convertedString.catWithCodeRange(other, CR_UNKNOWN); } catch (org.jruby.exceptions.EncodingError.CompatibilityError ce) { return newString(runtime, bytelist, encoding); } From 4fdce77fa6e1f0fbba6c4771b4d1e9fc7e92ee3a Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Wed, 13 Mar 2024 09:52:52 -0500 Subject: [PATCH 33/33] Backport two more names from versioned method removal See ruby/stringio#84 and ruby/stringio#88 for info on this transition. --- .../main/java/org/jruby/RubyConverter.java | 4 +- core/src/main/java/org/jruby/RubyString.java | 45 ++++++++++++------- .../java/org/jruby/ext/date/RubyDate.java | 2 +- .../java/org/jruby/ext/ripper/RubyRipper.java | 2 +- .../java/org/jruby/util/io/EncodingUtils.java | 2 +- 5 files changed, 34 insertions(+), 21 deletions(-) diff --git a/core/src/main/java/org/jruby/RubyConverter.java b/core/src/main/java/org/jruby/RubyConverter.java index b9662d0ee22..9ade805888b 100644 --- a/core/src/main/java/org/jruby/RubyConverter.java +++ b/core/src/main/java/org/jruby/RubyConverter.java @@ -287,12 +287,12 @@ public IRubyObject primitive_convert(ThreadContext context, IRubyObject[] args) inBytes = new ByteList(); } else { input = args[0].convertToString(); - input.modify19(); + input.modifyAndClearCodeRange(); inBytes = input.getByteList(); } output = args[1].convertToString(); - output.modify19(); + output.modifyAndClearCodeRange(); outBytes = output.getByteList(); Ptr inPtr = new Ptr(); diff --git a/core/src/main/java/org/jruby/RubyString.java b/core/src/main/java/org/jruby/RubyString.java index e53b7d51d69..c1ac9cf810d 100644 --- a/core/src/main/java/org/jruby/RubyString.java +++ b/core/src/main/java/org/jruby/RubyString.java @@ -983,7 +983,12 @@ public final void modify() { value.invalidate(); } + @Deprecated public final void modify19() { + modifyAndClearCodeRange(); + } + + public final void modifyAndClearCodeRange() { modify(); clearCodeRange(); } @@ -2636,7 +2641,7 @@ public char charAt(int offset) { @Override public CharSequence subSequence(int start, int end) { - IRubyObject subStr = substr19(getRuntime(), start, end - start); + IRubyObject subStr = substrEnc(getRuntime(), start, end - start); if (subStr.isNil()) { throw new StringIndexOutOfBoundsException("String index out of range: <" + start + ", " + end + ")"); } @@ -3132,7 +3137,7 @@ private RubyString subBangCommon(ThreadContext context, final int beg, final int if (replSize > plen) { modifyExpand(value.getRealSize() + replSize - plen); } else { - modify19(); + modifyAndClearCodeRange(); } final ByteList value = this.value; @@ -3689,7 +3694,12 @@ private IRubyObject byteARef(Ruby runtime, IRubyObject idx) { return obj; } + @Deprecated public final IRubyObject substr19(Ruby runtime, int beg, int len) { + return substrEnc(runtime, beg, len); + } + + public final IRubyObject substrEnc(Ruby runtime, int beg, int len) { if (len < 0) return runtime.getNil(); int length = value.getRealSize(); if (length == 0) len = 0; @@ -3816,7 +3826,7 @@ public IRubyObject op_aref(ThreadContext context, IRubyObject arg) { } else if (arg instanceof RubyRange) { int len = strLength(); int[] begLen = ((RubyRange) arg).begLenInt(len, 0); - return begLen == null ? context.nil : substr19(runtime, begLen[0], begLen[1]); + return begLen == null ? context.nil : substrEnc(runtime, begLen[0], begLen[1]); } else { StringSites sites = sites(context); if (RubyRange.isRangeLike(context, arg, sites.respond_to_begin, sites.respond_to_end)) { @@ -3824,7 +3834,7 @@ public IRubyObject op_aref(ThreadContext context, IRubyObject arg) { RubyRange range = RubyRange.rangeFromRangeLike(context, arg, sites.begin, sites.end, sites.exclude_end); int[] begLen = range.begLenInt(len, 0); - return begLen == null ? context.nil : substr19(runtime, begLen[0], begLen[1]); + return begLen == null ? context.nil : substrEnc(runtime, begLen[0], begLen[1]); } } return op_aref(runtime, RubyNumeric.num2int(arg)); @@ -3834,7 +3844,8 @@ public IRubyObject op_aref(ThreadContext context, IRubyObject arg) { public IRubyObject op_aref(ThreadContext context, IRubyObject arg1, IRubyObject arg2) { Ruby runtime = context.runtime; if (arg1 instanceof RubyRegexp) return subpat(context, (RubyRegexp) arg1, arg2); - return substr19(runtime, RubyNumeric.num2int(arg1), RubyNumeric.num2int(arg2)); + int beg = RubyNumeric.num2int(arg1); + return substrEnc(runtime, beg, RubyNumeric.num2int(arg2)); } @JRubyMethod @@ -3848,7 +3859,7 @@ public IRubyObject byteslice(ThreadContext context, IRubyObject arg) { } private IRubyObject op_aref(Ruby runtime, int idx) { - IRubyObject str = substr19(runtime, idx, 1); + IRubyObject str = substrEnc(runtime, idx, 1); return !str.isNil() && ((RubyString) str).value.getRealSize() == 0 ? runtime.getNil() : str; } @@ -4244,7 +4255,7 @@ public RubyBoolean include_p(ThreadContext context, IRubyObject obj) { @JRubyMethod public IRubyObject chr(ThreadContext context) { - return substr19(context.runtime, 0, 1); + return substrEnc(context.runtime, 0, 1); } @JRubyMethod @@ -4264,7 +4275,7 @@ public IRubyObject setbyte(ThreadContext context, IRubyObject index, IRubyObject IRubyObject w = v.modulo(context, (long)256); int b = RubyNumeric.num2int(w) & 0xff; - modify19(); + modifyAndClearCodeRange(); value.getUnsafeBytes()[normalizedIndex] = (byte)b; return val; } @@ -5386,10 +5397,12 @@ public IRubyObject rpartition(ThreadContext context, IRubyObject arg) { if (pos < 0) return rpartitionMismatch(runtime); } + int beg = pos + sep.strLength(); + int len = value.getRealSize(); return RubyArray.newArrayNoCopy(runtime, new IRubyObject[] { - substr19(runtime, 0, pos), + substrEnc(runtime, 0, pos), sep, - substr19(runtime, pos + sep.strLength(), value.getRealSize()) + substrEnc(runtime, beg, len) }); } @@ -6616,28 +6629,28 @@ public IRubyObject encoding(ThreadContext context) { @JRubyMethod(name = "encode!") public IRubyObject encode_bang(ThreadContext context) { - modify19(); + modifyAndClearCodeRange(); return EncodingUtils.strTranscode(context, this, RubyString::updateFromTranscode); } @JRubyMethod(name = "encode!") public IRubyObject encode_bang(ThreadContext context, IRubyObject arg0) { - modify19(); + modifyAndClearCodeRange(); return EncodingUtils.strTranscode(context, arg0, this, RubyString::updateFromTranscode); } @JRubyMethod(name = "encode!") public IRubyObject encode_bang(ThreadContext context, IRubyObject arg0, IRubyObject arg1) { - modify19(); + modifyAndClearCodeRange(); return EncodingUtils.strTranscode(context, arg0, arg1, this, RubyString::updateFromTranscode); } @JRubyMethod(name = "encode!") public IRubyObject encode_bang(ThreadContext context, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2) { - modify19(); + modifyAndClearCodeRange(); return EncodingUtils.strTranscode(context, arg0, arg1, arg2, this, RubyString::updateFromTranscode); } @@ -6682,7 +6695,7 @@ public IRubyObject force_encoding(ThreadContext context, IRubyObject enc) { private IRubyObject force_encoding(Encoding encoding) { modifyCheck(); - modify19(); + modifyAndClearCodeRange(); associateEncoding(encoding); clearCodeRange(); return this; @@ -7270,7 +7283,7 @@ public RubyArray unpack(IRubyObject obj) { public IRubyObject encode_bang(ThreadContext context, IRubyObject[] args) { Arity.checkArgumentCount(context, args, 0, 2); - modify19(); + modifyAndClearCodeRange(); return EncodingUtils.strTranscode(context, args, this, RubyString::updateFromTranscode); } diff --git a/core/src/main/java/org/jruby/ext/date/RubyDate.java b/core/src/main/java/org/jruby/ext/date/RubyDate.java index e8cbc3f6dc0..8042ff83d03 100644 --- a/core/src/main/java/org/jruby/ext/date/RubyDate.java +++ b/core/src/main/java/org/jruby/ext/date/RubyDate.java @@ -2410,7 +2410,7 @@ private static IRubyObject s3e(ThreadContext context, final RubyHash hash, int ep = skipDigits(y, s); if (ep != y.strLength()) { oy = y; y = d; - d = (RubyString) oy.substr19(context.runtime, bp, ep - bp); + d = (RubyString) oy.substrEnc(context.runtime, bp, ep - bp); } } diff --git a/core/src/main/java/org/jruby/ext/ripper/RubyRipper.java b/core/src/main/java/org/jruby/ext/ripper/RubyRipper.java index b5beab8510e..18f4d10f86d 100644 --- a/core/src/main/java/org/jruby/ext/ripper/RubyRipper.java +++ b/core/src/main/java/org/jruby/ext/ripper/RubyRipper.java @@ -371,7 +371,7 @@ public IRubyObject yydebug_set(ThreadContext context, IRubyObject arg) { public static IRubyObject dedent_string(ThreadContext context, IRubyObject self, IRubyObject _input, IRubyObject _width) { RubyString input = _input.convertToString(); int wid = _width.convertToInteger().getIntValue(); - input.modify19(); + input.modifyAndClearCodeRange(); int col = LexingCommon.dedent_string(input.getByteList(), wid); return context.runtime.newFixnum(col); } diff --git a/core/src/main/java/org/jruby/util/io/EncodingUtils.java b/core/src/main/java/org/jruby/util/io/EncodingUtils.java index 717b6ddd104..0364816020a 100644 --- a/core/src/main/java/org/jruby/util/io/EncodingUtils.java +++ b/core/src/main/java/org/jruby/util/io/EncodingUtils.java @@ -880,7 +880,7 @@ public static RubyString encodedDup(ThreadContext context, RubyString str, Encod // set to same superclass newstr.setMetaClass(str.getMetaClass()); } - newstr.modify19(); + newstr.modifyAndClearCodeRange(); return strEncodeAssociate(newstr, encindex); }