From 4fbb9aa3cb6c31ec128bfb31f59efa66d66adba4 Mon Sep 17 00:00:00 2001 From: eregon Date: Sat, 28 Apr 2018 19:50:06 +0000 Subject: Update to ruby/spec@6f38a82 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63293 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- spec/ruby/.rubocop_todo.yml | 23 +- spec/ruby/.travis.yml | 13 +- spec/ruby/README.md | 10 +- spec/ruby/command_line/dash_upper_i_spec.rb | 38 ++ spec/ruby/command_line/frozen_strings_spec.rb | 38 +- spec/ruby/core/argf/close_spec.rb | 19 +- spec/ruby/core/argf/read_nonblock_spec.rb | 8 +- spec/ruby/core/argf/readpartial_spec.rb | 16 +- spec/ruby/core/array/bsearch_index_spec.rb | 118 +++--- spec/ruby/core/array/dig_spec.rb | 96 +++-- spec/ruby/core/array/flatten_spec.rb | 10 +- spec/ruby/core/array/pack/j_spec.rb | 306 ++++++++------- spec/ruby/core/array/shared/delete_if.rb | 24 +- spec/ruby/core/array/shared/inspect.rb | 21 +- spec/ruby/core/comparable/equal_value_spec.rb | 37 +- spec/ruby/core/dir/close_spec.rb | 20 +- spec/ruby/core/dir/shared/glob.rb | 9 + spec/ruby/core/enumerable/chunk_spec.rb | 33 +- spec/ruby/core/enumerable/chunk_while_spec.rb | 60 ++- spec/ruby/core/enumerable/grep_v_spec.rb | 56 ++- spec/ruby/core/enumerable/slice_before_spec.rb | 31 +- spec/ruby/core/enumerator/lazy/grep_v_spec.rb | 118 +++--- spec/ruby/core/enumerator/lazy/uniq_spec.rb | 6 +- .../core/exception/backtrace_locations_spec.rb | 39 ++ spec/ruby/core/exception/fixtures/common.rb | 10 +- spec/ruby/core/exception/full_message_spec.rb | 38 ++ spec/ruby/core/exception/name_spec.rb | 36 +- spec/ruby/core/exception/receiver_spec.rb | 90 +++-- spec/ruby/core/file/mkfifo_spec.rb | 72 ++-- spec/ruby/core/file/open_spec.rb | 64 ++-- spec/ruby/core/file/shared/unlink.rb | 16 +- spec/ruby/core/file/stat/ino_spec.rb | 18 +- spec/ruby/core/hash/compare_by_identity_spec.rb | 2 +- spec/ruby/core/hash/dig_spec.rb | 106 +++--- spec/ruby/core/hash/fetch_values_spec.rb | 38 +- spec/ruby/core/hash/fixtures/classes.rb | 7 + spec/ruby/core/hash/gt_spec.rb | 60 ++- spec/ruby/core/hash/gte_spec.rb | 60 ++- spec/ruby/core/hash/initialize_spec.rb | 23 +- spec/ruby/core/hash/lt_spec.rb | 60 ++- spec/ruby/core/hash/lte_spec.rb | 60 ++- spec/ruby/core/hash/shared/to_s.rb | 21 +- spec/ruby/core/hash/to_proc_spec.rb | 118 +++--- spec/ruby/core/io/binread_spec.rb | 6 +- spec/ruby/core/io/close_on_exec_spec.rb | 24 +- spec/ruby/core/io/close_read_spec.rb | 32 +- spec/ruby/core/io/close_spec.rb | 15 +- spec/ruby/core/io/close_write_spec.rb | 32 +- spec/ruby/core/io/each_codepoint_spec.rb | 6 +- spec/ruby/core/io/read_nonblock_spec.rb | 24 +- spec/ruby/core/io/write_nonblock_spec.rb | 10 +- .../core/kernel/define_singleton_method_spec.rb | 18 +- spec/ruby/core/kernel/loop_spec.rb | 16 +- spec/ruby/core/kernel/require_relative_spec.rb | 42 +++ spec/ruby/core/kernel/shared/require.rb | 16 +- spec/ruby/core/main/using_spec.rb | 215 ++++++----- spec/ruby/core/module/autoload_spec.rb | 77 ++-- spec/ruby/core/module/define_method_spec.rb | 20 +- spec/ruby/core/module/deprecate_constant_spec.rb | 74 ++-- spec/ruby/core/module/prepend_spec.rb | 10 +- spec/ruby/core/module/private_spec.rb | 58 ++- spec/ruby/core/numeric/negative_spec.rb | 56 ++- spec/ruby/core/numeric/positive_spec.rb | 56 ++- spec/ruby/core/objectspace/each_object_spec.rb | 21 +- spec/ruby/core/process/status/exitstatus_spec.rb | 14 +- spec/ruby/core/process/status/termsig_spec.rb | 12 + spec/ruby/core/random/urandom_spec.rb | 2 +- spec/ruby/core/signal/signame_spec.rb | 12 +- spec/ruby/core/string/crypt_spec.rb | 6 +- spec/ruby/core/string/new_spec.rb | 10 +- spec/ruby/core/string/shared/each_line.rb | 23 +- spec/ruby/core/string/uminus_spec.rb | 64 ++-- spec/ruby/core/string/unpack/j_spec.rb | 414 ++++++++++----------- spec/ruby/core/string/uplus_spec.rb | 30 +- spec/ruby/core/struct/dig_spec.rb | 62 ++- spec/ruby/core/thread/name_spec.rb | 102 +++-- spec/ruby/core/time/at_spec.rb | 2 +- spec/ruby/core/tracepoint/disable_spec.rb | 2 +- spec/ruby/core/tracepoint/enable_spec.rb | 2 +- spec/ruby/core/tracepoint/new_spec.rb | 2 +- spec/ruby/language/block_spec.rb | 12 +- spec/ruby/language/class_spec.rb | 8 +- spec/ruby/language/constants_spec.rb | 30 +- spec/ruby/language/ensure_spec.rb | 40 ++ spec/ruby/language/fixtures/ensure.rb | 44 +++ spec/ruby/language/fixtures/super.rb | 32 ++ spec/ruby/language/heredoc_spec.rb | 58 ++- spec/ruby/language/optional_assignments_spec.rb | 46 +++ .../fixtures/toplevel_binding_dynamic.rb | 4 + .../fixtures/toplevel_binding_dynamic_required.rb | 2 + .../predefined/fixtures/toplevel_binding_id.rb | 4 + .../fixtures/toplevel_binding_id_required.rb | 1 + .../fixtures/toplevel_binding_required_before.rb | 2 + .../predefined/fixtures/toplevel_binding_values.rb | 9 + .../fixtures/toplevel_binding_variables.rb | 4 + .../toplevel_binding_variables_required.rb | 2 + .../language/predefined/toplevel_binding_spec.rb | 34 ++ spec/ruby/language/rescue_spec.rb | 20 +- spec/ruby/language/safe_navigator_spec.rb | 142 ++++--- spec/ruby/language/string_spec.rb | 32 +- spec/ruby/language/super_spec.rb | 14 + spec/ruby/language/yield_spec.rb | 2 +- spec/ruby/library/base64/urlsafe_decode64_spec.rb | 12 +- spec/ruby/library/base64/urlsafe_encode64_spec.rb | 8 +- spec/ruby/library/bigdecimal/BigDecimal_spec.rb | 109 ++++++ spec/ruby/library/bigdecimal/divmod_spec.rb | 6 +- spec/ruby/library/bigdecimal/inspect_spec.rb | 2 +- spec/ruby/library/bigdecimal/limit_spec.rb | 10 + spec/ruby/library/bigdecimal/new_spec.rb | 109 ------ spec/ruby/library/bigdecimal/shared/eql.rb | 4 +- spec/ruby/library/bigdecimal/shared/modulo.rb | 6 +- spec/ruby/library/bigdecimal/to_r_spec.rb | 2 +- spec/ruby/library/bigdecimal/to_s_spec.rb | 24 +- spec/ruby/library/coverage/peek_result_spec.rb | 102 +++-- spec/ruby/library/date/minus_month_spec.rb | 12 +- spec/ruby/library/net/ftp/default_passive_spec.rb | 8 +- spec/ruby/library/net/ftp/passive_spec.rb | 12 +- .../library/net/http/http/open_timeout_spec.rb | 21 +- spec/ruby/library/rexml/element/namespaces_spec.rb | 1 + .../library/securerandom/random_number_spec.rb | 46 ++- spec/ruby/library/socket/basicsocket/recv_spec.rb | 26 +- spec/ruby/library/socket/shared/recv_nonblock.rb | 16 +- .../library/socket/socket/accept_nonblock_spec.rb | 6 +- .../library/socket/socket/connect_nonblock_spec.rb | 6 +- .../socket/tcpserver/accept_nonblock_spec.rb | 6 +- .../library/socket/tcpsocket/recv_nonblock_spec.rb | 8 +- .../socket/unixserver/accept_nonblock_spec.rb | 6 +- spec/ruby/library/stringio/close_read_spec.rb | 7 +- spec/ruby/library/stringio/close_spec.rb | 15 +- spec/ruby/library/stringio/close_write_spec.rb | 7 +- .../library/stringio/external_encoding_spec.rb | 16 +- spec/ruby/library/stringio/read_nonblock_spec.rb | 9 + spec/ruby/library/thread/queue/close_spec.rb | 6 +- spec/ruby/library/thread/queue/closed_spec.rb | 6 +- spec/ruby/library/thread/sizedqueue/close_spec.rb | 6 +- spec/ruby/library/thread/sizedqueue/closed_spec.rb | 6 +- spec/ruby/optional/capi/class_spec.rb | 36 +- spec/ruby/optional/capi/time_spec.rb | 60 ++- spec/ruby/security/cve_2014_8080_spec.rb | 6 +- spec/ruby/security/cve_2017_17742_spec.rb | 40 ++ spec/ruby/security/cve_2018_6914_spec.rb | 59 +++ spec/ruby/security/cve_2018_8778_spec.rb | 12 + spec/ruby/security/cve_2018_8779_spec.rb | 30 ++ spec/ruby/security/cve_2018_8780_spec.rb | 53 +++ spec/ruby/shared/basicobject/method_missing.rb | 16 +- 145 files changed, 2693 insertions(+), 2442 deletions(-) create mode 100644 spec/ruby/core/exception/backtrace_locations_spec.rb create mode 100644 spec/ruby/core/exception/full_message_spec.rb create mode 100644 spec/ruby/language/predefined/fixtures/toplevel_binding_dynamic.rb create mode 100644 spec/ruby/language/predefined/fixtures/toplevel_binding_dynamic_required.rb create mode 100644 spec/ruby/language/predefined/fixtures/toplevel_binding_id.rb create mode 100644 spec/ruby/language/predefined/fixtures/toplevel_binding_id_required.rb create mode 100644 spec/ruby/language/predefined/fixtures/toplevel_binding_required_before.rb create mode 100644 spec/ruby/language/predefined/fixtures/toplevel_binding_values.rb create mode 100644 spec/ruby/language/predefined/fixtures/toplevel_binding_variables.rb create mode 100644 spec/ruby/language/predefined/fixtures/toplevel_binding_variables_required.rb create mode 100644 spec/ruby/language/predefined/toplevel_binding_spec.rb create mode 100644 spec/ruby/library/bigdecimal/BigDecimal_spec.rb delete mode 100644 spec/ruby/library/bigdecimal/new_spec.rb create mode 100644 spec/ruby/security/cve_2017_17742_spec.rb create mode 100644 spec/ruby/security/cve_2018_6914_spec.rb create mode 100644 spec/ruby/security/cve_2018_8778_spec.rb create mode 100644 spec/ruby/security/cve_2018_8779_spec.rb create mode 100644 spec/ruby/security/cve_2018_8780_spec.rb diff --git a/spec/ruby/.rubocop_todo.yml b/spec/ruby/.rubocop_todo.yml index 5fc8c91a85..9484078c8e 100644 --- a/spec/ruby/.rubocop_todo.yml +++ b/spec/ruby/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2017-12-15 22:14:22 +0900 using RuboCop version 0.52.0. +# on 2018-04-03 22:23:59 +0900 using RuboCop version 0.54.0. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -20,11 +20,6 @@ Lint/DuplicateMethods: - 'core/unboundmethod/fixtures/classes.rb' - 'fixtures/class.rb' -# Offense count: 4 -Lint/EmptyWhen: - Exclude: - - 'language/case_spec.rb' - # Offense count: 5 Lint/EnsureReturn: Exclude: @@ -43,7 +38,7 @@ Lint/FormatParameterMismatch: - 'core/kernel/shared/sprintf.rb' - 'core/string/modulo_spec.rb' -# Offense count: 28 +# Offense count: 29 Lint/HandleExceptions: Enabled: false @@ -59,7 +54,7 @@ Lint/IneffectiveAccessModifier: - 'core/module/fixtures/classes.rb' - 'language/fixtures/private.rb' -# Offense count: 5 +# Offense count: 6 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle. # SupportedStyles: runtime_error, standard_error @@ -69,13 +64,13 @@ Lint/InheritException: - 'core/exception/fixtures/common.rb' - 'core/module/fixtures/autoload_ex1.rb' -# Offense count: 3 +# Offense count: 5 # Cop supports --auto-correct. Lint/LiteralInInterpolation: Exclude: + - 'core/module/refine_spec.rb' - 'language/defined_spec.rb' - 'language/fixtures/squiggly_heredoc.rb' - - 'core/module/refine_spec.rb' # Offense count: 16 Lint/Loop: @@ -105,7 +100,7 @@ Lint/RedundantWithIndex: Exclude: - 'core/enumerator/with_index_spec.rb' -# Offense count: 24 +# Offense count: 26 Lint/RescueException: Exclude: - 'command_line/fixtures/debug_info.rb' @@ -200,3 +195,9 @@ Lint/UselessAccessModifier: - 'core/module/module_function_spec.rb' - 'core/module/private_class_method_spec.rb' - 'language/fixtures/send.rb' + +# Offense count: 6186 +# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. +# URISchemes: http, https +Metrics/LineLength: + Max: 588 diff --git a/spec/ruby/.travis.yml b/spec/ruby/.travis.yml index f79cd22aca..dab9d9297c 100644 --- a/spec/ruby/.travis.yml +++ b/spec/ruby/.travis.yml @@ -6,18 +6,17 @@ script: - ../mspec/bin/mspec $MSPEC_OPTS matrix: include: - - rvm: 2.5.0 + - rvm: 2.5.1 env: MSPEC_OPTS="-R2 -ff" - - rvm: 2.2.9 - - rvm: 2.3.6 - - rvm: 2.4.3 - - rvm: 2.5.0 + - rvm: 2.3.7 + - rvm: 2.4.4 + - rvm: 2.5.1 env: CHECK_LEAKS=true - rvm: ruby-head - env: RUBOCOP=true - rvm: 2.4.3 + rvm: 2.4.4 script: - - gem install rubocop -v 0.52.0 + - gem install rubocop -v 0.54.0 - rubocop allow_failures: - rvm: ruby-head diff --git a/spec/ruby/README.md b/spec/ruby/README.md index 9f01c324b1..d4a55ea9c1 100644 --- a/spec/ruby/README.md +++ b/spec/ruby/README.md @@ -25,16 +25,20 @@ The language specs are grouped by keyword while the core and standard library sp ruby/spec is known to be tested in these implementations for every commit: * [MRI](http://rubyci.org/) on 30 platforms and 4 versions * [JRuby](https://github.com/jruby/jruby/tree/master/spec/ruby) for both 1.7 and 9.x -* [TruffleRuby](https://github.com/oracle/truffleruby) +* [TruffleRuby](https://github.com/oracle/truffleruby/tree/master/spec/ruby) * [Opal](https://github.com/opal/opal/tree/master/spec) -ruby/spec describes the behavior of Ruby 2.2 and more recent Ruby versions. +The specs are synchronized both ways around once a month by @eregon between ruby/spec, MRI, JRuby and TruffleRuby. +Each of these repositories has a full copy of the files to ease editing specs. + +ruby/spec describes the behavior of Ruby 2.3 and more recent Ruby versions. More precisely, every latest stable MRI release [passes](https://rubyci.org/) all specs of ruby/spec -(latest 2.2.x, 2.3.x, 2.4.x, etc). +(2.3.x, 2.4.x, 2.5.x, etc). For older specs try these commits: * Ruby 2.0.0-p647 - [Suite](https://github.com/ruby/spec/commit/245862558761d5abc676843ef74f86c9bcc8ea8d) using [MSpec](https://github.com/ruby/mspec/commit/f90efa068791064f955de7a843e96e2d7d3041c2) (may encounter 2 failures) * Ruby 2.1.9 - [Suite](https://github.com/ruby/spec/commit/f029e65241374386077ac500add557ae65069b55) using [MSpec](https://github.com/ruby/mspec/commit/55568ea3918c6380e64db8c567d732fa5781efed) +* Ruby 2.2.10 - [Suite](https://github.com/ruby/spec/commit/cbaa0e412270c944df0c2532fc500c920dba0e92) using [MSpec](https://github.com/ruby/mspec/commit/d84d7668449e96856c5f6bac8cb1526b6d357ce3) ### Running the specs diff --git a/spec/ruby/command_line/dash_upper_i_spec.rb b/spec/ruby/command_line/dash_upper_i_spec.rb index f256a4351b..5d7109b6b6 100644 --- a/spec/ruby/command_line/dash_upper_i_spec.rb +++ b/spec/ruby/command_line/dash_upper_i_spec.rb @@ -8,4 +8,42 @@ describe "The -I command line option" do it "adds the path to the load path ($:)" do ruby_exe(@script, options: "-I fixtures").should include("fixtures") end + + it "adds the path at the front of $LOAD_PATH" do + lines = ruby_exe(@script, options: "-I fixtures").lines + if File.basename(ruby_exe[0]) == "miniruby" + # In a MRI checkout, $PWD ends up as the first entry in $LOAD_PATH. + # So just assert that it's at the beginning. + idx = lines.index { |l| l.include?("fixtures") } + idx.should < 2 + idx.should < lines.size-1 + else + lines[0].should include("fixtures") + end + end + + it "adds the path expanded from CWD to $LOAD_PATH" do + ruby_exe(@script, options: "-I fixtures").lines.should include "#{Dir.pwd}/fixtures\n" + end + + it "expands a path from CWD even if it does not exist" do + ruby_exe(@script, options: "-I not_exist/not_exist").lines.should include "#{Dir.pwd}/not_exist/not_exist\n" + end +end + +describe "The -I command line option" do + before :each do + @script = fixture __FILE__, "loadpath.rb" + @fixtures = File.dirname(@script) + @symlink = tmp("loadpath_symlink") + File.symlink(@fixtures, @symlink) + end + + after :each do + rm_r @symlink + end + + it "does not expand symlinks" do + ruby_exe(@script, options: "-I #{@symlink}").lines.should include "#{@symlink}\n" + end end diff --git a/spec/ruby/command_line/frozen_strings_spec.rb b/spec/ruby/command_line/frozen_strings_spec.rb index f0ceb53504..b2631a4c76 100644 --- a/spec/ruby/command_line/frozen_strings_spec.rb +++ b/spec/ruby/command_line/frozen_strings_spec.rb @@ -1,30 +1,28 @@ require_relative '../spec_helper' -ruby_version_is "2.3" do - describe "The --enable-frozen-string-literal flag causes string literals to" do +describe "The --enable-frozen-string-literal flag causes string literals to" do - it "produce the same object each time" do - ruby_exe(fixture(__FILE__, "freeze_flag_one_literal.rb"), options: "--enable-frozen-string-literal").chomp.should == "true" - end + it "produce the same object each time" do + ruby_exe(fixture(__FILE__, "freeze_flag_one_literal.rb"), options: "--enable-frozen-string-literal").chomp.should == "true" + end - it "produce the same object for literals with the same content" do - ruby_exe(fixture(__FILE__, "freeze_flag_two_literals.rb"), options: "--enable-frozen-string-literal").chomp.should == "true" - end + it "produce the same object for literals with the same content" do + ruby_exe(fixture(__FILE__, "freeze_flag_two_literals.rb"), options: "--enable-frozen-string-literal").chomp.should == "true" + end - it "produce the same object for literals with the same content in different files" do - ruby_exe(fixture(__FILE__, "freeze_flag_across_files.rb"), options: "--enable-frozen-string-literal").chomp.should == "true" - end + it "produce the same object for literals with the same content in different files" do + ruby_exe(fixture(__FILE__, "freeze_flag_across_files.rb"), options: "--enable-frozen-string-literal").chomp.should == "true" + end - it "produce different objects for literals with the same content in different files if they have different encodings" do - ruby_exe(fixture(__FILE__, "freeze_flag_across_files_diff_enc.rb"), options: "--enable-frozen-string-literal").chomp.should == "true" - end + it "produce different objects for literals with the same content in different files if they have different encodings" do + ruby_exe(fixture(__FILE__, "freeze_flag_across_files_diff_enc.rb"), options: "--enable-frozen-string-literal").chomp.should == "true" end +end - describe "The --debug flag produces" do - it "debugging info on attempted frozen string modification" do - error_str = ruby_exe(fixture(__FILE__, 'debug_info.rb'), options: '--debug', args: "2>&1") - error_str.should include("can't modify frozen String, created at ") - error_str.should include("command_line/fixtures/debug_info.rb:2") - end +describe "The --debug flag produces" do + it "debugging info on attempted frozen string modification" do + error_str = ruby_exe(fixture(__FILE__, 'debug_info.rb'), options: '--debug', args: "2>&1") + error_str.should include("can't modify frozen String, created at ") + error_str.should include("command_line/fixtures/debug_info.rb:2") end end diff --git a/spec/ruby/core/argf/close_spec.rb b/spec/ruby/core/argf/close_spec.rb index 0fc9a1894a..56faf30664 100644 --- a/spec/ruby/core/argf/close_spec.rb +++ b/spec/ruby/core/argf/close_spec.rb @@ -20,21 +20,10 @@ describe "ARGF.close" do end end - ruby_version_is ""..."2.3" do - it "raises an IOError if called on a closed stream" do - argf [@file1_name] do - lambda { @argf.close }.should_not raise_error - lambda { @argf.close }.should raise_error(IOError) - end - end - end - - ruby_version_is "2.3" do - it "doesn't raise an IOError if called on a closed stream" do - argf [@file1_name] do - lambda { @argf.close }.should_not raise_error - lambda { @argf.close }.should_not raise_error - end + it "doesn't raise an IOError if called on a closed stream" do + argf [@file1_name] do + lambda { @argf.close }.should_not raise_error + lambda { @argf.close }.should_not raise_error end end end diff --git a/spec/ruby/core/argf/read_nonblock_spec.rb b/spec/ruby/core/argf/read_nonblock_spec.rb index 51201421a5..466264119f 100644 --- a/spec/ruby/core/argf/read_nonblock_spec.rb +++ b/spec/ruby/core/argf/read_nonblock_spec.rb @@ -70,11 +70,9 @@ platform_is_not :windows do end end - ruby_version_is "2.3" do - it 'returns :wait_readable when the :exception is set to false' do - argf ['-'] do - @argf.read_nonblock(4, nil, exception: false).should == :wait_readable - end + it 'returns :wait_readable when the :exception is set to false' do + argf ['-'] do + @argf.read_nonblock(4, nil, exception: false).should == :wait_readable end end end diff --git a/spec/ruby/core/argf/readpartial_spec.rb b/spec/ruby/core/argf/readpartial_spec.rb index 70b0312261..4e697683dc 100644 --- a/spec/ruby/core/argf/readpartial_spec.rb +++ b/spec/ruby/core/argf/readpartial_spec.rb @@ -54,15 +54,13 @@ describe "ARGF.readpartial" do end end - ruby_version_is "2.3" do - it "raises an EOFError if the exception was raised while reading the last file" do - argf [@file1_name, @file2_name] do - @argf.readpartial(@file1.size) - @argf.readpartial(1) - @argf.readpartial(@file2.size) - lambda { @argf.readpartial(1) }.should raise_error(EOFError) - lambda { @argf.readpartial(1) }.should raise_error(EOFError) - end + it "raises an EOFError if the exception was raised while reading the last file" do + argf [@file1_name, @file2_name] do + @argf.readpartial(@file1.size) + @argf.readpartial(1) + @argf.readpartial(@file2.size) + lambda { @argf.readpartial(1) }.should raise_error(EOFError) + lambda { @argf.readpartial(1) }.should raise_error(EOFError) end end diff --git a/spec/ruby/core/array/bsearch_index_spec.rb b/spec/ruby/core/array/bsearch_index_spec.rb index 49c9d9ea34..a075d06ed3 100644 --- a/spec/ruby/core/array/bsearch_index_spec.rb +++ b/spec/ruby/core/array/bsearch_index_spec.rb @@ -1,86 +1,84 @@ require_relative '../../spec_helper' require_relative '../enumerable/shared/enumeratorized' -ruby_version_is "2.3" do - describe "Array#bsearch_index" do - context "when not passed a block" do - before :each do - @enum = [1, 2, 42, 100, 666].bsearch_index - end +describe "Array#bsearch_index" do + context "when not passed a block" do + before :each do + @enum = [1, 2, 42, 100, 666].bsearch_index + end - it "returns an Enumerator" do - @enum.should be_an_instance_of(Enumerator) - end + it "returns an Enumerator" do + @enum.should be_an_instance_of(Enumerator) + end - it "returns an Enumerator with unknown size" do - @enum.size.should be_nil - end + it "returns an Enumerator with unknown size" do + @enum.size.should be_nil + end - it "returns index of element when block condition is satisfied" do - @enum.each { |x| x >= 33 }.should == 2 - end + it "returns index of element when block condition is satisfied" do + @enum.each { |x| x >= 33 }.should == 2 end + end + + it "raises a TypeError when block returns a String" do + lambda { [1, 2, 3].bsearch_index { "not ok" } }.should raise_error(TypeError) + end - it "raises a TypeError when block returns a String" do - lambda { [1, 2, 3].bsearch_index { "not ok" } }.should raise_error(TypeError) + it "returns nil when block is empty" do + [1, 2, 3].bsearch_index {}.should be_nil + end + + context "minimum mode" do + before :each do + @array = [0, 4, 7, 10, 12] end - it "returns nil when block is empty" do - [1, 2, 3].bsearch_index {}.should be_nil + it "returns index of first element which satisfies the block" do + @array.bsearch_index { |x| x >= 4 }.should == 1 + @array.bsearch_index { |x| x >= 6 }.should == 2 + @array.bsearch_index { |x| x >= -1 }.should == 0 end - context "minimum mode" do - before :each do - @array = [0, 4, 7, 10, 12] - end + it "returns nil when block condition is never satisfied" do + @array.bsearch_index { false }.should be_nil + @array.bsearch_index { |x| x >= 100 }.should be_nil + end + end - it "returns index of first element which satisfies the block" do - @array.bsearch_index { |x| x >= 4 }.should == 1 - @array.bsearch_index { |x| x >= 6 }.should == 2 - @array.bsearch_index { |x| x >= -1 }.should == 0 - end + context "find any mode" do + before :each do + @array = [0, 4, 7, 10, 12] + end - it "returns nil when block condition is never satisfied" do - @array.bsearch_index { false }.should be_nil - @array.bsearch_index { |x| x >= 100 }.should be_nil - end + it "returns the index of any matched elements where element is between 4 <= x < 8" do + [1, 2].should include(@array.bsearch_index { |x| 1 - x / 4 }) end - context "find any mode" do - before :each do - @array = [0, 4, 7, 10, 12] - end + it "returns the index of any matched elements where element is between 8 <= x < 10" do + @array.bsearch_index { |x| 4 - x / 2 }.should be_nil + end - it "returns the index of any matched elements where element is between 4 <= x < 8" do - [1, 2].should include(@array.bsearch_index { |x| 1 - x / 4 }) - end + it "returns nil when block never returns 0" do + @array.bsearch_index { |x| 1 }.should be_nil + @array.bsearch_index { |x| -1 }.should be_nil + end - it "returns the index of any matched elements where element is between 8 <= x < 10" do - @array.bsearch_index { |x| 4 - x / 2 }.should be_nil - end + it "returns the middle element when block always returns zero" do + @array.bsearch_index { |x| 0 }.should == 2 + end - it "returns nil when block never returns 0" do - @array.bsearch_index { |x| 1 }.should be_nil - @array.bsearch_index { |x| -1 }.should be_nil + context "magnitude does not effect the result" do + it "returns the index of any matched elements where element is between 4n <= xn < 8n" do + [1, 2].should include(@array.bsearch_index { |x| (1 - x / 4) * (2**100) }) end - it "returns the middle element when block always returns zero" do - @array.bsearch_index { |x| 0 }.should == 2 + it "returns nil when block never returns 0" do + @array.bsearch_index { |x| 1 * (2**100) }.should be_nil + @array.bsearch_index { |x| (-1) * (2**100) }.should be_nil end - context "magnitude does not effect the result" do - it "returns the index of any matched elements where element is between 4n <= xn < 8n" do - [1, 2].should include(@array.bsearch_index { |x| (1 - x / 4) * (2**100) }) - end - - it "returns nil when block never returns 0" do - @array.bsearch_index { |x| 1 * (2**100) }.should be_nil - @array.bsearch_index { |x| (-1) * (2**100) }.should be_nil - end - - it "handles values from Bignum#coerce" do - [1, 2].should include(@array.bsearch_index { |x| (2**100).coerce((1 - x / 4) * (2**100)).first }) - end + it "handles values from Bignum#coerce" do + [1, 2].should include(@array.bsearch_index { |x| (2**100).coerce((1 - x / 4) * (2**100)).first }) end end end diff --git a/spec/ruby/core/array/dig_spec.rb b/spec/ruby/core/array/dig_spec.rb index 0a47eb0b13..1ace4893ee 100644 --- a/spec/ruby/core/array/dig_spec.rb +++ b/spec/ruby/core/array/dig_spec.rb @@ -1,54 +1,52 @@ require_relative '../../spec_helper' -ruby_version_is '2.3' do - describe "Array#dig" do - - it "returns #at with one arg" do - ['a'].dig(0).should == 'a' - ['a'].dig(1).should be_nil - end - - it "recurses array elements" do - a = [ [ 1, [2, '3'] ] ] - a.dig(0, 0).should == 1 - a.dig(0, 1, 1).should == '3' - a.dig(0, -1, 0).should == 2 - end - - it "returns the nested value specified if the sequence includes a key" do - a = [42, { foo: :bar }] - a.dig(1, :foo).should == :bar - end - - it "raises a TypeError for a non-numeric index" do - lambda { - ['a'].dig(:first) - }.should raise_error(TypeError) - end - - it "raises a TypeError if any intermediate step does not respond to #dig" do - a = [1, 2] - lambda { - a.dig(0, 1) - }.should raise_error(TypeError) - end - - it "raises an ArgumentError if no arguments provided" do - lambda { - [10].dig() - }.should raise_error(ArgumentError) - end - - it "returns nil if any intermediate step is nil" do - a = [[1, [2, 3]]] - a.dig(1, 2, 3).should == nil - end - - it "calls #dig on the result of #at with the remaining arguments" do - h = [[nil, [nil, nil, 42]]] - h[0].should_receive(:dig).with(1, 2).and_return(42) - h.dig(0, 1, 2).should == 42 - end +describe "Array#dig" do + it "returns #at with one arg" do + ['a'].dig(0).should == 'a' + ['a'].dig(1).should be_nil end + + it "recurses array elements" do + a = [ [ 1, [2, '3'] ] ] + a.dig(0, 0).should == 1 + a.dig(0, 1, 1).should == '3' + a.dig(0, -1, 0).should == 2 + end + + it "returns the nested value specified if the sequence includes a key" do + a = [42, { foo: :bar }] + a.dig(1, :foo).should == :bar + end + + it "raises a TypeError for a non-numeric index" do + lambda { + ['a'].dig(:first) + }.should raise_error(TypeError) + end + + it "raises a TypeError if any intermediate step does not respond to #dig" do + a = [1, 2] + lambda { + a.dig(0, 1) + }.should raise_error(TypeError) + end + + it "raises an ArgumentError if no arguments provided" do + lambda { + [10].dig() + }.should raise_error(ArgumentError) + end + + it "returns nil if any intermediate step is nil" do + a = [[1, [2, 3]]] + a.dig(1, 2, 3).should == nil + end + + it "calls #dig on the result of #at with the remaining arguments" do + h = [[nil, [nil, nil, 42]]] + h[0].should_receive(:dig).with(1, 2).and_return(42) + h.dig(0, 1, 2).should == 42 + end + end diff --git a/spec/ruby/core/array/flatten_spec.rb b/spec/ruby/core/array/flatten_spec.rb index a274a01d89..1b7361552a 100644 --- a/spec/ruby/core/array/flatten_spec.rb +++ b/spec/ruby/core/array/flatten_spec.rb @@ -69,12 +69,10 @@ describe "Array#flatten" do [1, z, 6].flatten.should == [1, 2, 3, 4, 5, 6] end - ruby_version_is "2.3" do - it "does not call #to_ary on elements beyond the given level" do - obj = mock("1") - obj.should_not_receive(:to_ary) - [[obj]].flatten(1) - end + it "does not call #to_ary on elements beyond the given level" do + obj = mock("1") + obj.should_not_receive(:to_ary) + [[obj]].flatten(1) end it "returns subclass instance for Array subclasses" do diff --git a/spec/ruby/core/array/pack/j_spec.rb b/spec/ruby/core/array/pack/j_spec.rb index 3a38ef6db7..7b62d5efdf 100644 --- a/spec/ruby/core/array/pack/j_spec.rb +++ b/spec/ruby/core/array/pack/j_spec.rb @@ -4,216 +4,214 @@ require_relative 'shared/basic' require_relative 'shared/numeric_basic' require_relative 'shared/integer' -ruby_version_is '2.3' do - platform_is pointer_size: 64 do - describe "Array#pack with format 'J'" do - it_behaves_like :array_pack_basic, 'J' - it_behaves_like :array_pack_basic_non_float, 'J' - it_behaves_like :array_pack_arguments, 'J' - it_behaves_like :array_pack_numeric_basic, 'J' - it_behaves_like :array_pack_integer, 'J' - end - - describe "Array#pack with format 'j'" do - it_behaves_like :array_pack_basic, 'j' - it_behaves_like :array_pack_basic_non_float, 'j' - it_behaves_like :array_pack_arguments, 'j' - it_behaves_like :array_pack_numeric_basic, 'j' - it_behaves_like :array_pack_integer, 'j' - end +platform_is pointer_size: 64 do + describe "Array#pack with format 'J'" do + it_behaves_like :array_pack_basic, 'J' + it_behaves_like :array_pack_basic_non_float, 'J' + it_behaves_like :array_pack_arguments, 'J' + it_behaves_like :array_pack_numeric_basic, 'J' + it_behaves_like :array_pack_integer, 'J' + end - little_endian do - describe "Array#pack with format 'J'" do - describe "with modifier '_'" do - it_behaves_like :array_pack_64bit_le, 'J_' - end + describe "Array#pack with format 'j'" do + it_behaves_like :array_pack_basic, 'j' + it_behaves_like :array_pack_basic_non_float, 'j' + it_behaves_like :array_pack_arguments, 'j' + it_behaves_like :array_pack_numeric_basic, 'j' + it_behaves_like :array_pack_integer, 'j' + end - describe "with modifier '!'" do - it_behaves_like :array_pack_64bit_le, 'J!' - end + little_endian do + describe "Array#pack with format 'J'" do + describe "with modifier '_'" do + it_behaves_like :array_pack_64bit_le, 'J_' end - describe "Array#pack with format 'j'" do - describe "with modifier '_'" do - it_behaves_like :array_pack_64bit_le, 'j_' - end - - describe "with modifier '!'" do - it_behaves_like :array_pack_64bit_le, 'j!' - end + describe "with modifier '!'" do + it_behaves_like :array_pack_64bit_le, 'J!' end end - big_endian do - describe "Array#pack with format 'J'" do - describe "with modifier '_'" do - it_behaves_like :array_pack_64bit_be, 'J_' - end - - describe "with modifier '!'" do - it_behaves_like :array_pack_64bit_be, 'J!' - end + describe "Array#pack with format 'j'" do + describe "with modifier '_'" do + it_behaves_like :array_pack_64bit_le, 'j_' end - describe "Array#pack with format 'j'" do - describe "with modifier '_'" do - it_behaves_like :array_pack_64bit_be, 'j_' - end - - describe "with modifier '!'" do - it_behaves_like :array_pack_64bit_be, 'j!' - end + describe "with modifier '!'" do + it_behaves_like :array_pack_64bit_le, 'j!' end end + end + big_endian do describe "Array#pack with format 'J'" do - describe "with modifier '<' and '_'" do - it_behaves_like :array_pack_64bit_le, 'J<_' - it_behaves_like :array_pack_64bit_le, 'J_<' - end - - describe "with modifier '<' and '!'" do - it_behaves_like :array_pack_64bit_le, 'J' and '_'" do - it_behaves_like :array_pack_64bit_be, 'J>_' - it_behaves_like :array_pack_64bit_be, 'J_>' - end - - describe "with modifier '>' and '!'" do - it_behaves_like :array_pack_64bit_be, 'J>!' - it_behaves_like :array_pack_64bit_be, 'J!>' + describe "with modifier '!'" do + it_behaves_like :array_pack_64bit_be, 'J!' end end describe "Array#pack with format 'j'" do - describe "with modifier '<' and '_'" do - it_behaves_like :array_pack_64bit_le, 'j<_' - it_behaves_like :array_pack_64bit_le, 'j_<' + describe "with modifier '_'" do + it_behaves_like :array_pack_64bit_be, 'j_' end - describe "with modifier '<' and '!'" do - it_behaves_like :array_pack_64bit_le, 'j' and '_'" do - it_behaves_like :array_pack_64bit_be, 'j>_' - it_behaves_like :array_pack_64bit_be, 'j_>' - end + describe "Array#pack with format 'J'" do + describe "with modifier '<' and '_'" do + it_behaves_like :array_pack_64bit_le, 'J<_' + it_behaves_like :array_pack_64bit_le, 'J_<' + end - describe "with modifier '>' and '!'" do - it_behaves_like :array_pack_64bit_be, 'j>!' - it_behaves_like :array_pack_64bit_be, 'j!>' - end + describe "with modifier '<' and '!'" do + it_behaves_like :array_pack_64bit_le, 'J' and '_'" do + it_behaves_like :array_pack_64bit_be, 'J>_' + it_behaves_like :array_pack_64bit_be, 'J_>' end - describe "Array#pack with format 'j'" do - it_behaves_like :array_pack_basic, 'j' - it_behaves_like :array_pack_basic_non_float, 'j' - it_behaves_like :array_pack_arguments, 'j' - it_behaves_like :array_pack_numeric_basic, 'j' - it_behaves_like :array_pack_integer, 'j' + describe "with modifier '>' and '!'" do + it_behaves_like :array_pack_64bit_be, 'J>!' + it_behaves_like :array_pack_64bit_be, 'J!>' end + end - big_endian do - describe "Array#pack with format 'J'" do - describe "with modifier '_'" do - it_behaves_like :array_pack_32bit_be, 'J_' - end + describe "Array#pack with format 'j'" do + describe "with modifier '<' and '_'" do + it_behaves_like :array_pack_64bit_le, 'j<_' + it_behaves_like :array_pack_64bit_le, 'j_<' + end - describe "with modifier '!'" do - it_behaves_like :array_pack_32bit_be, 'J!' - end - end + describe "with modifier '<' and '!'" do + it_behaves_like :array_pack_64bit_le, 'j' and '_'" do + it_behaves_like :array_pack_64bit_be, 'j>_' + it_behaves_like :array_pack_64bit_be, 'j_>' + end - describe "with modifier '!'" do - it_behaves_like :array_pack_32bit_be, 'j!' - end - end + describe "with modifier '>' and '!'" do + it_behaves_like :array_pack_64bit_be, 'j>!' + it_behaves_like :array_pack_64bit_be, 'j!>' end + end +end - little_endian do - describe "Array#pack with format 'J'" do - describe "with modifier '_'" do - it_behaves_like :array_pack_32bit_le, 'J_' - end +platform_is pointer_size: 32 do + describe "Array#pack with format 'J'" do + it_behaves_like :array_pack_basic, 'J' + it_behaves_like :array_pack_basic_non_float, 'J' + it_behaves_like :array_pack_arguments, 'J' + it_behaves_like :array_pack_numeric_basic, 'J' + it_behaves_like :array_pack_integer, 'J' + end - describe "with modifier '!'" do - it_behaves_like :array_pack_32bit_le, 'J!' - end - end + describe "Array#pack with format 'j'" do + it_behaves_like :array_pack_basic, 'j' + it_behaves_like :array_pack_basic_non_float, 'j' + it_behaves_like :array_pack_arguments, 'j' + it_behaves_like :array_pack_numeric_basic, 'j' + it_behaves_like :array_pack_integer, 'j' + end - describe "Array#pack with format 'j'" do - describe "with modifier '_'" do - it_behaves_like :array_pack_32bit_le, 'j_' - end + big_endian do + describe "Array#pack with format 'J'" do + describe "with modifier '_'" do + it_behaves_like :array_pack_32bit_be, 'J_' + end - describe "with modifier '!'" do - it_behaves_like :array_pack_32bit_le, 'j!' - end + describe "with modifier '!'" do + it_behaves_like :array_pack_32bit_be, 'J!' end end - describe "Array#pack with format 'J'" do - describe "with modifier '<' and '_'" do - it_behaves_like :array_pack_32bit_le, 'J<_' - it_behaves_like :array_pack_32bit_le, 'J_<' + describe "Array#pack with format 'j'" do + describe "with modifier '_'" do + it_behaves_like :array_pack_32bit_be, 'j_' end - describe "with modifier '<' and '!'" do - it_behaves_like :array_pack_32bit_le, 'J' and '_'" do - it_behaves_like :array_pack_32bit_be, 'J>_' - it_behaves_like :array_pack_32bit_be, 'J_>' + little_endian do + describe "Array#pack with format 'J'" do + describe "with modifier '_'" do + it_behaves_like :array_pack_32bit_le, 'J_' end - describe "with modifier '>' and '!'" do - it_behaves_like :array_pack_32bit_be, 'J>!' - it_behaves_like :array_pack_32bit_be, 'J!>' + describe "with modifier '!'" do + it_behaves_like :array_pack_32bit_le, 'J!' end end describe "Array#pack with format 'j'" do - describe "with modifier '<' and '_'" do - it_behaves_like :array_pack_32bit_le, 'j<_' - it_behaves_like :array_pack_32bit_le, 'j_<' + describe "with modifier '_'" do + it_behaves_like :array_pack_32bit_le, 'j_' end - describe "with modifier '<' and '!'" do - it_behaves_like :array_pack_32bit_le, 'j' and '_'" do - it_behaves_like :array_pack_32bit_be, 'j>_' - it_behaves_like :array_pack_32bit_be, 'j_>' - end + describe "Array#pack with format 'J'" do + describe "with modifier '<' and '_'" do + it_behaves_like :array_pack_32bit_le, 'J<_' + it_behaves_like :array_pack_32bit_le, 'J_<' + end - describe "with modifier '>' and '!'" do - it_behaves_like :array_pack_32bit_be, 'j>!' - it_behaves_like :array_pack_32bit_be, 'j!>' - end + describe "with modifier '<' and '!'" do + it_behaves_like :array_pack_32bit_le, 'J' and '_'" do + it_behaves_like :array_pack_32bit_be, 'J>_' + it_behaves_like :array_pack_32bit_be, 'J_>' + end + + describe "with modifier '>' and '!'" do + it_behaves_like :array_pack_32bit_be, 'J>!' + it_behaves_like :array_pack_32bit_be, 'J!>' + end + end + + describe "Array#pack with format 'j'" do + describe "with modifier '<' and '_'" do + it_behaves_like :array_pack_32bit_le, 'j<_' + it_behaves_like :array_pack_32bit_le, 'j_<' + end + + describe "with modifier '<' and '!'" do + it_behaves_like :array_pack_32bit_le, 'j' and '_'" do + it_behaves_like :array_pack_32bit_be, 'j>_' + it_behaves_like :array_pack_32bit_be, 'j_>' + end + + describe "with modifier '>' and '!'" do + it_behaves_like :array_pack_32bit_be, 'j>!' + it_behaves_like :array_pack_32bit_be, 'j!>' end end end diff --git a/spec/ruby/core/array/shared/delete_if.rb b/spec/ruby/core/array/shared/delete_if.rb index a9fb57e0d9..a3fdcf4fac 100644 --- a/spec/ruby/core/array/shared/delete_if.rb +++ b/spec/ruby/core/array/shared/delete_if.rb @@ -3,25 +3,11 @@ describe :delete_if, shared: true do @object = [1,2,3] end - ruby_version_is "2.3" do - it "updates the receiver after all blocks" do - @object.send(@method) do |e| - @object.length.should == 3 - true - end - @object.length.should == 0 - end - end - - ruby_version_is ""..."2.3" do - it "updates the receiver after each true block" do - count = 0 - @object.send(@method) do |e| - @object.length.should == (3 - count) - count += 1 - true - end - @object.length.should == 0 + it "updates the receiver after all blocks" do + @object.send(@method) do |e| + @object.length.should == 3 + true end + @object.length.should == 0 end end diff --git a/spec/ruby/core/array/shared/inspect.rb b/spec/ruby/core/array/shared/inspect.rb index 0cf5035b37..1bcc9f9ca8 100644 --- a/spec/ruby/core/array/shared/inspect.rb +++ b/spec/ruby/core/array/shared/inspect.rb @@ -121,24 +121,11 @@ describe :array_inspect, shared: true do array.send(@method).encoding.name.should == "US-ASCII" end - ruby_version_is ''...'2.3' do - it "raises if inspected result is not default external encoding" do - utf_16be = mock("utf_16be") - utf_16be.should_receive(:inspect).and_return(%<"utf_16be \u3042">.encode!(Encoding::UTF_16BE)) - - lambda { - [utf_16be].send(@method) - }.should raise_error(Encoding::CompatibilityError) - end - end - - ruby_version_is '2.3' do - it "does not raise if inspected result is not default external encoding" do - utf_16be = mock("utf_16be") - utf_16be.should_receive(:inspect).and_return(%<"utf_16be \u3042">.encode!(Encoding::UTF_16BE)) + it "does not raise if inspected result is not default external encoding" do + utf_16be = mock("utf_16be") + utf_16be.should_receive(:inspect).and_return(%<"utf_16be \u3042">.encode!(Encoding::UTF_16BE)) - [utf_16be].send(@method).should == '["utf_16be \u3042"]' - end + [utf_16be].send(@method).should == '["utf_16be \u3042"]' end end end diff --git a/spec/ruby/core/comparable/equal_value_spec.rb b/spec/ruby/core/comparable/equal_value_spec.rb index 24d9fec2fb..53c83aa2d3 100644 --- a/spec/ruby/core/comparable/equal_value_spec.rb +++ b/spec/ruby/core/comparable/equal_value_spec.rb @@ -48,16 +48,8 @@ describe "Comparable#==" do a.should_receive(:<=>).once.and_return("abc") end - ruby_version_is ""..."2.3" do - it "returns false" do - (a == b).should be_false - end - end - - ruby_version_is "2.3" do - it "raises an ArgumentError" do - lambda { (a == b) }.should raise_error(ArgumentError) - end + it "raises an ArgumentError" do + lambda { (a == b) }.should raise_error(ArgumentError) end end @@ -67,17 +59,8 @@ describe "Comparable#==" do a.should_receive(:<=>).once.and_raise(StandardError) end - ruby_version_is ""..."2.3" do - # Behaviour confirmed by MRI test suite - it "returns false" do - (a == b).should be_false - end - end - - ruby_version_is "2.3" do - it "lets it go through" do - lambda { (a == b) }.should raise_error(StandardError) - end + it "lets it go through" do + lambda { (a == b) }.should raise_error(StandardError) end end @@ -87,16 +70,8 @@ describe "Comparable#==" do a.should_receive(:<=>).once.and_raise(TypeError) end - ruby_version_is ""..."2.3" do - it "returns false" do - (a == b).should be_false - end - end - - ruby_version_is "2.3" do - it "lets it go through" do - lambda { (a == b) }.should raise_error(TypeError) - end + it "lets it go through" do + lambda { (a == b) }.should raise_error(TypeError) end end diff --git a/spec/ruby/core/dir/close_spec.rb b/spec/ruby/core/dir/close_spec.rb index 1cf1f1d029..64d87140ae 100644 --- a/spec/ruby/core/dir/close_spec.rb +++ b/spec/ruby/core/dir/close_spec.rb @@ -1,9 +1,5 @@ require_relative '../../spec_helper' require_relative 'fixtures/common' -ruby_version_is ''...'2.3' do - require_relative 'shared/closed' -end - describe "Dir#close" do before :all do DirSpecs.create_mock_dirs @@ -13,17 +9,11 @@ describe "Dir#close" do DirSpecs.delete_mock_dirs end - ruby_version_is ''...'2.3' do - it_behaves_like :dir_closed, :close - end - - ruby_version_is '2.3' do - it "does not raise an IOError even if the Dir instance is closed" do - dir = Dir.open DirSpecs.mock_dir + it "does not raise an IOError even if the Dir instance is closed" do + dir = Dir.open DirSpecs.mock_dir + dir.close + lambda { dir.close - lambda { - dir.close - }.should_not raise_error(IOError) - end + }.should_not raise_error(IOError) end end diff --git a/spec/ruby/core/dir/shared/glob.rb b/spec/ruby/core/dir/shared/glob.rb index 2fe22ac6c3..88ceb82c50 100644 --- a/spec/ruby/core/dir/shared/glob.rb +++ b/spec/ruby/core/dir/shared/glob.rb @@ -32,6 +32,15 @@ describe :dir_glob, shared: true do end end + ruby_version_is "2.6" do + it "splits the string on \\0 if there is only one string given and warns" do + -> { + Dir.send(@method, "file_o*\0file_t*").should == + %w!file_one.ext file_two.ext! + }.should complain(/warning: use glob patterns list instead of nul-separated patterns/) + end + end + it "matches non-dotfiles with '*'" do expected = %w[ brace diff --git a/spec/ruby/core/enumerable/chunk_spec.rb b/spec/ruby/core/enumerable/chunk_spec.rb index 9215d97fef..34fa651b33 100644 --- a/spec/ruby/core/enumerable/chunk_spec.rb +++ b/spec/ruby/core/enumerable/chunk_spec.rb @@ -62,34 +62,11 @@ describe "Enumerable#chunk" do lambda { e.chunk { |x| :_arbitrary }.to_a }.should raise_error(RuntimeError) end - ruby_version_is ""..."2.3" do - describe "with [initial_state]" do - it "yields an element and an object value-equal but not identical to the object passed to #chunk" do - e = EnumerableSpecs::Numerous.new(1) - value = "value" - - e.chunk(value) do |x, v| - x.should == 1 - v.should == value - v.should_not equal(value) - end.to_a - end - - it "does not yield the object passed to #chunk if it is nil" do - e = EnumerableSpecs::Numerous.new(1) - e.chunk(nil) { |*x| ScratchPad << x }.to_a - ScratchPad.recorded.should == [[1]] - end - end - end - - ruby_version_is "2.3" do - it "does not accept arguments" do - e = EnumerableSpecs::Numerous.new(1, 2, 3) - lambda { - e.chunk(1) {} - }.should raise_error(ArgumentError) - end + it "does not accept arguments" do + e = EnumerableSpecs::Numerous.new(1, 2, 3) + lambda { + e.chunk(1) {} + }.should raise_error(ArgumentError) end it 'returned Enumerator size returns nil' do diff --git a/spec/ruby/core/enumerable/chunk_while_spec.rb b/spec/ruby/core/enumerable/chunk_while_spec.rb index 29645da1fe..88d6d2983f 100644 --- a/spec/ruby/core/enumerable/chunk_while_spec.rb +++ b/spec/ruby/core/enumerable/chunk_while_spec.rb @@ -1,44 +1,42 @@ require_relative '../../spec_helper' require_relative 'fixtures/classes' -ruby_version_is "2.3" do - describe "Enumerable#chunk_while" do - before :each do - ary = [10, 9, 7, 6, 4, 3, 2, 1] - @enum = EnumerableSpecs::Numerous.new(*ary) - @result = @enum.chunk_while { |i, j| i - 1 == j } - @enum_length = ary.length - end +describe "Enumerable#chunk_while" do + before :each do + ary = [10, 9, 7, 6, 4, 3, 2, 1] + @enum = EnumerableSpecs::Numerous.new(*ary) + @result = @enum.chunk_while { |i, j| i - 1 == j } + @enum_length = ary.length + end - context "when given a block" do - it "returns an enumerator" do - @result.should be_an_instance_of(Enumerator) - end + context "when given a block" do + it "returns an enumerator" do + @result.should be_an_instance_of(Enumerator) + end - it "splits chunks between adjacent elements i and j where the block returns false" do - @result.to_a.should == [[10, 9], [7, 6], [4, 3, 2, 1]] - end + it "splits chunks between adjacent elements i and j where the block returns false" do + @result.to_a.should == [[10, 9], [7, 6], [4, 3, 2, 1]] + end - it "calls the block for length of the receiver enumerable minus one times" do - times_called = 0 - @enum.chunk_while do |i, j| - times_called += 1 - i - 1 == j - end.to_a - times_called.should == (@enum_length - 1) - end + it "calls the block for length of the receiver enumerable minus one times" do + times_called = 0 + @enum.chunk_while do |i, j| + times_called += 1 + i - 1 == j + end.to_a + times_called.should == (@enum_length - 1) end + end - context "when not given a block" do - it "raises an ArgumentError" do - lambda { @enum.chunk_while }.should raise_error(ArgumentError) - end + context "when not given a block" do + it "raises an ArgumentError" do + lambda { @enum.chunk_while }.should raise_error(ArgumentError) end + end - context "on a single-element array" do - it "ignores the block and returns an enumerator that yields [element]" do - [1].chunk_while {|x| x.even?}.to_a.should == [[1]] - end + context "on a single-element array" do + it "ignores the block and returns an enumerator that yields [element]" do + [1].chunk_while {|x| x.even?}.to_a.should == [[1]] end end end diff --git a/spec/ruby/core/enumerable/grep_v_spec.rb b/spec/ruby/core/enumerable/grep_v_spec.rb index 8d8bc28d5e..2268005dee 100644 --- a/spec/ruby/core/enumerable/grep_v_spec.rb +++ b/spec/ruby/core/enumerable/grep_v_spec.rb @@ -1,43 +1,41 @@ require_relative '../../spec_helper' require_relative 'fixtures/classes' -ruby_version_is "2.3" do - describe "Enumerable#grep_v" do - before :each do - @numerous = EnumerableSpecs::Numerous.new(*(0..9).to_a) - def (@odd_matcher = BasicObject.new).===(obj) - obj.odd? - end +describe "Enumerable#grep_v" do + before :each do + @numerous = EnumerableSpecs::Numerous.new(*(0..9).to_a) + def (@odd_matcher = BasicObject.new).===(obj) + obj.odd? end + end - describe "without block" do - it "returns an Array of matched elements" do - @numerous.grep_v(@odd_matcher).should == [0, 2, 4, 6, 8] - end + describe "without block" do + it "returns an Array of matched elements" do + @numerous.grep_v(@odd_matcher).should == [0, 2, 4, 6, 8] + end - it "compares pattern with gathered array when yielded with multiple arguments" do - (unmatcher = Object.new).stub!(:===).and_return(false) - EnumerableSpecs::YieldsMixed2.new.grep_v(unmatcher).should == EnumerableSpecs::YieldsMixed2.gathered_yields - end + it "compares pattern with gathered array when yielded with multiple arguments" do + (unmatcher = Object.new).stub!(:===).and_return(false) + EnumerableSpecs::YieldsMixed2.new.grep_v(unmatcher).should == EnumerableSpecs::YieldsMixed2.gathered_yields + end - it "raises an ArgumentError when not given a pattern" do - -> { @numerous.grep_v }.should raise_error(ArgumentError) - end + it "raises an ArgumentError when not given a pattern" do + -> { @numerous.grep_v }.should raise_error(ArgumentError) end + end - describe "with block" do - it "returns an Array of matched elements that mapped by the block" do - @numerous.grep_v(@odd_matcher) { |n| n * 2 }.should == [0, 4, 8, 12, 16] - end + describe "with block" do + it "returns an Array of matched elements that mapped by the block" do + @numerous.grep_v(@odd_matcher) { |n| n * 2 }.should == [0, 4, 8, 12, 16] + end - it "calls the block with gathered array when yielded with multiple arguments" do - (unmatcher = Object.new).stub!(:===).and_return(false) - EnumerableSpecs::YieldsMixed2.new.grep_v(unmatcher){ |e| e }.should == EnumerableSpecs::YieldsMixed2.gathered_yields - end + it "calls the block with gathered array when yielded with multiple arguments" do + (unmatcher = Object.new).stub!(:===).and_return(false) + EnumerableSpecs::YieldsMixed2.new.grep_v(unmatcher){ |e| e }.should == EnumerableSpecs::YieldsMixed2.gathered_yields + end - it "raises an ArgumentError when not given a pattern" do - -> { @numerous.grep_v { |e| e } }.should raise_error(ArgumentError) - end + it "raises an ArgumentError when not given a pattern" do + -> { @numerous.grep_v { |e| e } }.should raise_error(ArgumentError) end end end diff --git a/spec/ruby/core/enumerable/slice_before_spec.rb b/spec/ruby/core/enumerable/slice_before_spec.rb index 932d06072a..ad730be245 100644 --- a/spec/ruby/core/enumerable/slice_before_spec.rb +++ b/spec/ruby/core/enumerable/slice_before_spec.rb @@ -40,33 +40,10 @@ describe "Enumerable#slice_before" do end end - ruby_version_is ""..."2.3" do - describe "and an argument" do - it "calls the block with a copy of that argument" do - arg = [:foo] - first = nil - e = @enum.slice_before(arg) do |i, init| - init.should == arg - init.should_not equal(arg) - first = init - i == 6 || i == 2 - end - e.should be_an_instance_of(Enumerator) - e.to_a.should == [[7], [6, 5, 4, 3], [2, 1]] - e = @enum.slice_before(arg) do |i, init| - init.should_not equal(first) - end - e.to_a - end - end - end - - ruby_version_is "2.3" do - it "does not accept arguments" do - lambda { - @enum.slice_before(1) {} - }.should raise_error(ArgumentError) - end + it "does not accept arguments" do + lambda { + @enum.slice_before(1) {} + }.should raise_error(ArgumentError) end end diff --git a/spec/ruby/core/enumerator/lazy/grep_v_spec.rb b/spec/ruby/core/enumerator/lazy/grep_v_spec.rb index 79f8760055..a0ec819505 100644 --- a/spec/ruby/core/enumerator/lazy/grep_v_spec.rb +++ b/spec/ruby/core/enumerator/lazy/grep_v_spec.rb @@ -1,86 +1,84 @@ require_relative '../../../spec_helper' require_relative 'fixtures/classes' -ruby_version_is "2.3" do - describe "Enumerator::Lazy#grep_v" do - before(:each) do - @yieldsmixed = EnumeratorLazySpecs::YieldsMixed.new.to_enum.lazy - @eventsmixed = EnumeratorLazySpecs::EventsMixed.new.to_enum.lazy - ScratchPad.record [] - end +describe "Enumerator::Lazy#grep_v" do + before(:each) do + @yieldsmixed = EnumeratorLazySpecs::YieldsMixed.new.to_enum.lazy + @eventsmixed = EnumeratorLazySpecs::EventsMixed.new.to_enum.lazy + ScratchPad.record [] + end - after(:each) do - ScratchPad.clear - end + after(:each) do + ScratchPad.clear + end + + it "requires an argument" do + Enumerator::Lazy.instance_method(:grep_v).arity.should == 1 + end + + it "returns a new instance of Enumerator::Lazy" do + ret = @yieldsmixed.grep_v(Object) {} + ret.should be_an_instance_of(Enumerator::Lazy) + ret.should_not equal(@yieldsmixed) - it "requires an argument" do - Enumerator::Lazy.instance_method(:grep_v).arity.should == 1 + ret = @yieldsmixed.grep_v(Object) + ret.should be_an_instance_of(Enumerator::Lazy) + ret.should_not equal(@yieldsmixed) + end + + it "sets #size to nil" do + Enumerator::Lazy.new(Object.new, 100) {}.grep_v(Object) {}.size.should == nil + Enumerator::Lazy.new(Object.new, 100) {}.grep_v(Object).size.should == nil + end + + describe "when the returned lazy enumerator is evaluated by Enumerable#first" do + it "stops after specified times when not given a block" do + (0..Float::INFINITY).lazy.grep_v(3..5).first(3).should == [0, 1, 2] + + @eventsmixed.grep_v(Symbol).first(1) + ScratchPad.recorded.should == [:before_yield] end - it "returns a new instance of Enumerator::Lazy" do - ret = @yieldsmixed.grep_v(Object) {} - ret.should be_an_instance_of(Enumerator::Lazy) - ret.should_not equal(@yieldsmixed) + it "stops after specified times when given a block" do + (0..Float::INFINITY).lazy.grep_v(4..8, &:succ).first(3).should == [1, 2, 3] - ret = @yieldsmixed.grep_v(Object) - ret.should be_an_instance_of(Enumerator::Lazy) - ret.should_not equal(@yieldsmixed) + @eventsmixed.grep_v(Symbol) {}.first(1) + ScratchPad.recorded.should == [:before_yield] end + end + + it "calls the block with a gathered array when yield with multiple arguments" do + yields = [] + @yieldsmixed.grep_v(Array) { |v| yields << v }.force + yields.should == EnumeratorLazySpecs::YieldsMixed.gathered_non_array_yields + @yieldsmixed.grep_v(Array).force.should == yields + end + + describe "on a nested Lazy" do it "sets #size to nil" do - Enumerator::Lazy.new(Object.new, 100) {}.grep_v(Object) {}.size.should == nil - Enumerator::Lazy.new(Object.new, 100) {}.grep_v(Object).size.should == nil + Enumerator::Lazy.new(Object.new, 100) {}.grep_v(Object).grep_v(Object) {}.size.should == nil + Enumerator::Lazy.new(Object.new, 100) {}.grep_v(Object).grep_v(Object).size.should == nil end describe "when the returned lazy enumerator is evaluated by Enumerable#first" do it "stops after specified times when not given a block" do - (0..Float::INFINITY).lazy.grep_v(3..5).first(3).should == [0, 1, 2] + (0..Float::INFINITY).lazy.grep_v(3..5).grep_v(6..10).first(3).should == [0, 1, 2] - @eventsmixed.grep_v(Symbol).first(1) + @eventsmixed.grep_v(Symbol).grep_v(String).first(1) ScratchPad.recorded.should == [:before_yield] end it "stops after specified times when given a block" do - (0..Float::INFINITY).lazy.grep_v(4..8, &:succ).first(3).should == [1, 2, 3] + (0..Float::INFINITY).lazy + .grep_v(1..2) { |n| n > 3 ? n : false } + .grep_v(false) { |n| n.even? ? n : false } + .first(3) + .should == [4, false, 6] - @eventsmixed.grep_v(Symbol) {}.first(1) + @eventsmixed.grep_v(Symbol) {}.grep_v(String) {}.first(1) ScratchPad.recorded.should == [:before_yield] end end - - it "calls the block with a gathered array when yield with multiple arguments" do - yields = [] - @yieldsmixed.grep_v(Array) { |v| yields << v }.force - yields.should == EnumeratorLazySpecs::YieldsMixed.gathered_non_array_yields - - @yieldsmixed.grep_v(Array).force.should == yields - end - - describe "on a nested Lazy" do - it "sets #size to nil" do - Enumerator::Lazy.new(Object.new, 100) {}.grep_v(Object).grep_v(Object) {}.size.should == nil - Enumerator::Lazy.new(Object.new, 100) {}.grep_v(Object).grep_v(Object).size.should == nil - end - - describe "when the returned lazy enumerator is evaluated by Enumerable#first" do - it "stops after specified times when not given a block" do - (0..Float::INFINITY).lazy.grep_v(3..5).grep_v(6..10).first(3).should == [0, 1, 2] - - @eventsmixed.grep_v(Symbol).grep_v(String).first(1) - ScratchPad.recorded.should == [:before_yield] - end - - it "stops after specified times when given a block" do - (0..Float::INFINITY).lazy - .grep_v(1..2) { |n| n > 3 ? n : false } - .grep_v(false) { |n| n.even? ? n : false } - .first(3) - .should == [4, false, 6] - - @eventsmixed.grep_v(Symbol) {}.grep_v(String) {}.first(1) - ScratchPad.recorded.should == [:before_yield] - end - end - end end end diff --git a/spec/ruby/core/enumerator/lazy/uniq_spec.rb b/spec/ruby/core/enumerator/lazy/uniq_spec.rb index 3c9acdc453..fea2bec637 100644 --- a/spec/ruby/core/enumerator/lazy/uniq_spec.rb +++ b/spec/ruby/core/enumerator/lazy/uniq_spec.rb @@ -13,7 +13,7 @@ ruby_version_is '2.4' do @lazy.force.should == [0, 1] end - ruby_bug "#14495", "2.4"..."2.5.1" do + ruby_bug "#14495", "2.4"..."2.5.2" do it 'return same value after rewind' do @lazy.force.should == [0, 1] @lazy.force.should == [0, 1] @@ -35,7 +35,7 @@ ruby_version_is '2.4' do @lazy.force.should == [0, 1] end - ruby_bug "#14495", "2.4"..."2.5.1" do + ruby_bug "#14495", "2.4"..."2.5.2" do it 'return same value after rewind' do @lazy.force.should == [0, 1] @lazy.force.should == [0, 1] @@ -60,7 +60,7 @@ ruby_version_is '2.4' do @lazy = enum.lazy end - ruby_bug "#14495", "2.4"..."2.5.1" do + ruby_bug "#14495", "2.4"..."2.5.2" do it 'return same value after rewind' do enum = @lazy.uniq { |_, label| label.downcase } enum.force.should == [[0, 'foo'], [2, 'bar']] diff --git a/spec/ruby/core/exception/backtrace_locations_spec.rb b/spec/ruby/core/exception/backtrace_locations_spec.rb new file mode 100644 index 0000000000..86eb9d3413 --- /dev/null +++ b/spec/ruby/core/exception/backtrace_locations_spec.rb @@ -0,0 +1,39 @@ +require_relative '../../spec_helper' +require_relative 'fixtures/common' + +describe "Exception#backtrace_locations" do + before :each do + @backtrace = ExceptionSpecs::Backtrace.backtrace_locations + end + + it "returns nil if no backtrace was set" do + Exception.new.backtrace_locations.should be_nil + end + + it "returns an Array" do + @backtrace.should be_an_instance_of(Array) + end + + it "sets each element to a Thread::Backtrace::Location" do + @backtrace.each {|l| l.should be_an_instance_of(Thread::Backtrace::Location)} + end + + it "produces a backtrace for an exception captured using $!" do + exception = begin + raise + rescue RuntimeError + $! + end + + exception.backtrace_locations.first.path.should =~ /backtrace_locations_spec/ + end + + it "returns an Array that can be updated" do + begin + raise + rescue RuntimeError => e + e.backtrace_locations.unshift "backtrace first" + e.backtrace_locations[0].should == "backtrace first" + end + end +end diff --git a/spec/ruby/core/exception/fixtures/common.rb b/spec/ruby/core/exception/fixtures/common.rb index e1ba102197..9ddabace11 100644 --- a/spec/ruby/core/exception/fixtures/common.rb +++ b/spec/ruby/core/exception/fixtures/common.rb @@ -4,11 +4,19 @@ module ExceptionSpecs class Backtrace def self.backtrace begin - raise # Do not move this line or update backtrace_spec.rb + raise # If you move this line, update backtrace_spec.rb rescue RuntimeError => e e.backtrace end end + + def self.backtrace_locations + begin + raise + rescue RuntimeError => e + e.backtrace_locations + end + end end class UnExceptional < Exception diff --git a/spec/ruby/core/exception/full_message_spec.rb b/spec/ruby/core/exception/full_message_spec.rb new file mode 100644 index 0000000000..f56282d67b --- /dev/null +++ b/spec/ruby/core/exception/full_message_spec.rb @@ -0,0 +1,38 @@ +require_relative '../../spec_helper' + +ruby_version_is "2.5" do + describe "Exception#full_message" do + it "returns formatted string of exception using the same format that is used to print an uncaught exceptions to stderr" do + e = RuntimeError.new("Some runtime error") + e.set_backtrace(["a.rb:1", "b.rb:2"]) + + full_message = e.full_message + full_message.should include "RuntimeError" + full_message.should include "Some runtime error" + full_message.should include "a.rb:1" + full_message.should include "b.rb:2" + end + + ruby_version_is "2.5.1" do + it "supports :highlight option and adds escape sequences to highlight some strings" do + e = RuntimeError.new("Some runtime error") + + full_message = e.full_message(highlight: true, order: :bottom) + full_message.should include "\e[1mTraceback\e[m (most recent call last)" + full_message.should include "\e[1mSome runtime error (\e[1;4mRuntimeError\e[m\e[1m)" + + full_message = e.full_message(highlight: false, order: :bottom) + full_message.should include "Traceback (most recent call last)" + full_message.should include "Some runtime error (RuntimeError)" + end + + it "supports :order option and places the error message and the backtrace at the top or the bottom" do + e = RuntimeError.new("Some runtime error") + e.set_backtrace(["a.rb:1", "b.rb:2"]) + + e.full_message(order: :top, highlight: false).should =~ /a.rb:1.*b.rb:2/m + e.full_message(order: :bottom, highlight: false).should =~ /b.rb:2.*a.rb:1/m + end + end + end +end diff --git a/spec/ruby/core/exception/name_spec.rb b/spec/ruby/core/exception/name_spec.rb index 5380432ddf..d1def51f24 100644 --- a/spec/ruby/core/exception/name_spec.rb +++ b/spec/ruby/core/exception/name_spec.rb @@ -27,35 +27,19 @@ describe "NameError#name" do }.should raise_error(NameError) { |e| e.name.should == :@@doesnt_exist } end - ruby_version_is ""..."2.3" do - it "always returns a symbol when a NameError is raised from #instance_variable_get" do - -> { - Object.new.instance_variable_get("invalid_ivar_name") - }.should raise_error(NameError) { |e| e.name.should == :invalid_ivar_name } - end + it "returns the first argument passed to the method when a NameError is raised from #instance_variable_get" do + invalid_ivar_name = "invalid_ivar_name" - it "always returns a symbol when a NameError is raised from #class_variable_get" do - -> { - Object.class_variable_get("invalid_cvar_name") - }.should raise_error(NameError) { |e| e.name.should == :invalid_cvar_name } - end + -> { + Object.new.instance_variable_get(invalid_ivar_name) + }.should raise_error(NameError) {|e| e.name.should equal(invalid_ivar_name) } end - ruby_version_is "2.3" do - it "returns the first argument passed to the method when a NameError is raised from #instance_variable_get" do - invalid_ivar_name = "invalid_ivar_name" - - -> { - Object.new.instance_variable_get(invalid_ivar_name) - }.should raise_error(NameError) {|e| e.name.should equal(invalid_ivar_name) } - end - - it "returns the first argument passed to the method when a NameError is raised from #class_variable_get" do - invalid_cvar_name = "invalid_cvar_name" + it "returns the first argument passed to the method when a NameError is raised from #class_variable_get" do + invalid_cvar_name = "invalid_cvar_name" - -> { - Object.class_variable_get(invalid_cvar_name) - }.should raise_error(NameError) {|e| e.name.should equal(invalid_cvar_name) } - end + -> { + Object.class_variable_get(invalid_cvar_name) + }.should raise_error(NameError) {|e| e.name.should equal(invalid_cvar_name) } end end diff --git a/spec/ruby/core/exception/receiver_spec.rb b/spec/ruby/core/exception/receiver_spec.rb index c5fca7d73a..7c57d63c3e 100644 --- a/spec/ruby/core/exception/receiver_spec.rb +++ b/spec/ruby/core/exception/receiver_spec.rb @@ -1,62 +1,60 @@ require_relative '../../spec_helper' require_relative 'fixtures/common' -ruby_version_is "2.3" do - describe "NameError#receiver" do - class ::ReceiverClass - def call_undefined_class_variable; @@doesnt_exist end - end +describe "NameError#receiver" do + class ::ReceiverClass + def call_undefined_class_variable; @@doesnt_exist end + end - it "returns the object that raised the exception" do - receiver = Object.new + it "returns the object that raised the exception" do + receiver = Object.new - -> { - receiver.doesnt_exist - }.should raise_error(NameError) {|e| e.receiver.should equal(receiver) } - end + -> { + receiver.doesnt_exist + }.should raise_error(NameError) {|e| e.receiver.should equal(receiver) } + end - it "returns the Object class when an undefined constant is called without namespace" do - -> { - DoesntExist - }.should raise_error(NameError) {|e| e.receiver.should equal(Object) } - end + it "returns the Object class when an undefined constant is called without namespace" do + -> { + DoesntExist + }.should raise_error(NameError) {|e| e.receiver.should equal(Object) } + end - it "returns a class when an undefined constant is called" do - -> { - NameErrorSpecs::ReceiverClass::DoesntExist - }.should raise_error(NameError) {|e| e.receiver.should equal(NameErrorSpecs::ReceiverClass) } - end + it "returns a class when an undefined constant is called" do + -> { + NameErrorSpecs::ReceiverClass::DoesntExist + }.should raise_error(NameError) {|e| e.receiver.should equal(NameErrorSpecs::ReceiverClass) } + end - it "returns the Object class when an undefined class variable is called" do + it "returns the Object class when an undefined class variable is called" do + -> { -> { - -> { - @@doesnt_exist - }.should complain(/class variable access from toplevel/) - }.should raise_error(NameError) {|e| e.receiver.should equal(Object) } - end + @@doesnt_exist + }.should complain(/class variable access from toplevel/) + }.should raise_error(NameError) {|e| e.receiver.should equal(Object) } + end - it "returns a class when an undefined class variable is called in a subclass' namespace" do - -> { - NameErrorSpecs::ReceiverClass.new.call_undefined_class_variable - }.should raise_error(NameError) {|e| e.receiver.should equal(NameErrorSpecs::ReceiverClass) } - end + it "returns a class when an undefined class variable is called in a subclass' namespace" do + -> { + NameErrorSpecs::ReceiverClass.new.call_undefined_class_variable + }.should raise_error(NameError) {|e| e.receiver.should equal(NameErrorSpecs::ReceiverClass) } + end - it "returns the receiver when raised from #instance_variable_get" do - receiver = Object.new + it "returns the receiver when raised from #instance_variable_get" do + receiver = Object.new - -> { - receiver.instance_variable_get("invalid_ivar_name") - }.should raise_error(NameError) {|e| e.receiver.should equal(receiver) } - end + -> { + receiver.instance_variable_get("invalid_ivar_name") + }.should raise_error(NameError) {|e| e.receiver.should equal(receiver) } + end - it "returns the receiver when raised from #class_variable_get" do - -> { - Object.class_variable_get("invalid_cvar_name") - }.should raise_error(NameError) {|e| e.receiver.should equal(Object) } - end + it "returns the receiver when raised from #class_variable_get" do + -> { + Object.class_variable_get("invalid_cvar_name") + }.should raise_error(NameError) {|e| e.receiver.should equal(Object) } + end - it "raises an ArgumentError when the receiver is none" do - -> { NameError.new.receiver }.should raise_error(ArgumentError) - end + it "raises an ArgumentError when the receiver is none" do + -> { NameError.new.receiver }.should raise_error(ArgumentError) end end diff --git a/spec/ruby/core/file/mkfifo_spec.rb b/spec/ruby/core/file/mkfifo_spec.rb index f8842418af..a6db87a12e 100644 --- a/spec/ruby/core/file/mkfifo_spec.rb +++ b/spec/ruby/core/file/mkfifo_spec.rb @@ -1,53 +1,51 @@ require_relative '../../spec_helper' -ruby_version_is "2.3" do - describe "File.mkfifo" do - platform_is_not :windows do - before do - @path = tmp('fifo') - end +describe "File.mkfifo" do + platform_is_not :windows do + before do + @path = tmp('fifo') + end - after do - rm_r(@path) - end + after do + rm_r(@path) + end - context "when path passed responds to :to_path" do - it "creates a FIFO file at the path specified" do - File.mkfifo(@path) - File.ftype(@path).should == "fifo" - end + context "when path passed responds to :to_path" do + it "creates a FIFO file at the path specified" do + File.mkfifo(@path) + File.ftype(@path).should == "fifo" end + end - context "when path passed is not a String value" do - it "raises a TypeError" do - lambda { File.mkfifo(:"/tmp/fifo") }.should raise_error(TypeError) - end + context "when path passed is not a String value" do + it "raises a TypeError" do + lambda { File.mkfifo(:"/tmp/fifo") }.should raise_error(TypeError) end + end - context "when path does not exist" do - it "raises an Errno::ENOENT exception" do - lambda { File.mkfifo("/bogus/path") }.should raise_error(Errno::ENOENT) - end + context "when path does not exist" do + it "raises an Errno::ENOENT exception" do + lambda { File.mkfifo("/bogus/path") }.should raise_error(Errno::ENOENT) end + end - it "creates a FIFO file at the passed path" do - File.mkfifo(@path.to_s) - File.ftype(@path).should == "fifo" - end + it "creates a FIFO file at the passed path" do + File.mkfifo(@path.to_s) + File.ftype(@path).should == "fifo" + end - it "creates a FIFO file with passed mode & ~umask" do - File.mkfifo(@path, 0755) - File.stat(@path).mode.should == 010755 & ~File.umask - end + it "creates a FIFO file with passed mode & ~umask" do + File.mkfifo(@path, 0755) + File.stat(@path).mode.should == 010755 & ~File.umask + end - it "creates a FIFO file with a default mode of 0666 & ~umask" do - File.mkfifo(@path) - File.stat(@path).mode.should == 010666 & ~File.umask - end + it "creates a FIFO file with a default mode of 0666 & ~umask" do + File.mkfifo(@path) + File.stat(@path).mode.should == 010666 & ~File.umask + end - it "returns 0 after creating the FIFO file" do - File.mkfifo(@path).should == 0 - end + it "returns 0 after creating the FIFO file" do + File.mkfifo(@path).should == 0 end end end diff --git a/spec/ruby/core/file/open_spec.rb b/spec/ruby/core/file/open_spec.rb index b5add5dff4..6ccac75a9a 100644 --- a/spec/ruby/core/file/open_spec.rb +++ b/spec/ruby/core/file/open_spec.rb @@ -524,28 +524,26 @@ describe "File.open" do File.size(@file).should == 0 end - ruby_version_is "2.3" do - platform_is :linux do - guard -> { defined?(File::TMPFILE) } do - it "creates an unnamed temporary file with File::TMPFILE" do - dir = tmp("tmpfilespec") - mkdir_p dir - begin + platform_is :linux do + guard -> { defined?(File::TMPFILE) } do + it "creates an unnamed temporary file with File::TMPFILE" do + dir = tmp("tmpfilespec") + mkdir_p dir + begin + Dir["#{dir}/*"].should == [] + File.open(dir, "r+", flags: File::TMPFILE) do |io| + io.write("ruby") + io.flush + io.rewind + io.read.should == "ruby" Dir["#{dir}/*"].should == [] - File.open(dir, "r+", flags: File::TMPFILE) do |io| - io.write("ruby") - io.flush - io.rewind - io.read.should == "ruby" - Dir["#{dir}/*"].should == [] - end - rescue Errno::EOPNOTSUPP, Errno::EINVAL - # EOPNOTSUPP: no support from the filesystem - # EINVAL: presumably bug in glibc - 1.should == 1 - ensure - rm_r dir end + rescue Errno::EOPNOTSUPP, Errno::EINVAL + # EOPNOTSUPP: no support from the filesystem + # EINVAL: presumably bug in glibc + 1.should == 1 + ensure + rm_r dir end end end @@ -586,22 +584,20 @@ describe "File.open" do @fh = File.open(@file, options) end - ruby_version_is "2.3" do - it "accepts extra flags as a keyword argument and combine with a string mode" do - lambda { - File.open(@file, "w", flags: File::EXCL) { } - }.should raise_error(Errno::EEXIST) + it "accepts extra flags as a keyword argument and combine with a string mode" do + lambda { + File.open(@file, "w", flags: File::EXCL) { } + }.should raise_error(Errno::EEXIST) - lambda { - File.open(@file, mode: "w", flags: File::EXCL) { } - }.should raise_error(Errno::EEXIST) - end + lambda { + File.open(@file, mode: "w", flags: File::EXCL) { } + }.should raise_error(Errno::EEXIST) + end - it "accepts extra flags as a keyword argument and combine with an integer mode" do - lambda { - File.open(@file, File::WRONLY | File::CREAT, flags: File::EXCL) { } - }.should raise_error(Errno::EEXIST) - end + it "accepts extra flags as a keyword argument and combine with an integer mode" do + lambda { + File.open(@file, File::WRONLY | File::CREAT, flags: File::EXCL) { } + }.should raise_error(Errno::EEXIST) end platform_is_not :windows do diff --git a/spec/ruby/core/file/shared/unlink.rb b/spec/ruby/core/file/shared/unlink.rb index 7b0413b76b..42b6a77c5d 100644 --- a/spec/ruby/core/file/shared/unlink.rb +++ b/spec/ruby/core/file/shared/unlink.rb @@ -48,16 +48,14 @@ describe :file_unlink, shared: true do File.send(@method, mock_to_path(@file1)).should == 1 end - ruby_version_is "2.3" do - platform_is :windows do - it "allows deleting an open file with File::SHARE_DELETE" do - path = tmp("share_delete.txt") - File.open(path, mode: File::CREAT | File::WRONLY | File::BINARY | File::SHARE_DELETE) do |f| - File.exist?(path).should be_true - File.send(@method, path) - end - File.exist?(path).should be_false + platform_is :windows do + it "allows deleting an open file with File::SHARE_DELETE" do + path = tmp("share_delete.txt") + File.open(path, mode: File::CREAT | File::WRONLY | File::BINARY | File::SHARE_DELETE) do |f| + File.exist?(path).should be_true + File.send(@method, path) end + File.exist?(path).should be_false end end end diff --git a/spec/ruby/core/file/stat/ino_spec.rb b/spec/ruby/core/file/stat/ino_spec.rb index 3ae2a7d439..42370aecb7 100644 --- a/spec/ruby/core/file/stat/ino_spec.rb +++ b/spec/ruby/core/file/stat/ino_spec.rb @@ -19,20 +19,10 @@ describe "File::Stat#ino" do end platform_is :windows do - ruby_version_is ""..."2.3" do - it "returns 0" do - st = File.stat(@file) - st.ino.should be_kind_of(Integer) - st.ino.should == 0 - end - end - - ruby_version_is "2.3" do - it "returns BY_HANDLE_FILE_INFORMATION.nFileIndexHigh/Low of a File::Stat object" do - st = File.stat(@file) - st.ino.should be_kind_of(Integer) - st.ino.should > 0 - end + it "returns BY_HANDLE_FILE_INFORMATION.nFileIndexHigh/Low of a File::Stat object" do + st = File.stat(@file) + st.ino.should be_kind_of(Integer) + st.ino.should > 0 end end end diff --git a/spec/ruby/core/hash/compare_by_identity_spec.rb b/spec/ruby/core/hash/compare_by_identity_spec.rb index cf15649739..e463c311be 100644 --- a/spec/ruby/core/hash/compare_by_identity_spec.rb +++ b/spec/ruby/core/hash/compare_by_identity_spec.rb @@ -108,7 +108,7 @@ describe "Hash#compare_by_identity" do @idh.keys.first.should equal foo end - ruby_bug "#12855", "2.2.0"..."2.4.1" do + ruby_bug "#12855", ""..."2.4.1" do it "gives different identity for string literals" do @idh['foo'] = 1 @idh['foo'] = 2 diff --git a/spec/ruby/core/hash/dig_spec.rb b/spec/ruby/core/hash/dig_spec.rb index 91639f4213..dcba049ac4 100644 --- a/spec/ruby/core/hash/dig_spec.rb +++ b/spec/ruby/core/hash/dig_spec.rb @@ -1,68 +1,66 @@ require_relative '../../spec_helper' -ruby_version_is '2.3' do - describe "Hash#dig" do +describe "Hash#dig" do - it "returns #[] with one arg" do - h = { 0 => false, a: 1 } - h.dig(:a).should == 1 - h.dig(0).should be_false - h.dig(1).should be_nil - end + it "returns #[] with one arg" do + h = { 0 => false, a: 1 } + h.dig(:a).should == 1 + h.dig(0).should be_false + h.dig(1).should be_nil + end - it "returns the nested value specified by the sequence of keys" do - h = { foo: { bar: { baz: 1 } } } - h.dig(:foo, :bar, :baz).should == 1 - h.dig(:foo, :bar, :nope).should be_nil - h.dig(:foo, :baz).should be_nil - h.dig(:bar, :baz, :foo).should be_nil - end + it "returns the nested value specified by the sequence of keys" do + h = { foo: { bar: { baz: 1 } } } + h.dig(:foo, :bar, :baz).should == 1 + h.dig(:foo, :bar, :nope).should be_nil + h.dig(:foo, :baz).should be_nil + h.dig(:bar, :baz, :foo).should be_nil + end - it "returns the nested value specified if the sequence includes an index" do - h = { foo: [1, 2, 3] } - h.dig(:foo, 2).should == 3 - end + it "returns the nested value specified if the sequence includes an index" do + h = { foo: [1, 2, 3] } + h.dig(:foo, 2).should == 3 + end - it "returns nil if any intermediate step is nil" do - h = { foo: { bar: { baz: 1 } } } - h.dig(:foo, :zot, :xyz).should == nil - end + it "returns nil if any intermediate step is nil" do + h = { foo: { bar: { baz: 1 } } } + h.dig(:foo, :zot, :xyz).should == nil + end - it "raises an ArgumentError if no arguments provided" do - lambda { { the: 'borg' }.dig() }.should raise_error(ArgumentError) - end + it "raises an ArgumentError if no arguments provided" do + lambda { { the: 'borg' }.dig() }.should raise_error(ArgumentError) + end - it "handles type-mixed deep digging" do - h = {} - h[:foo] = [ { bar: [ 1 ] }, [ obj = Object.new, 'str' ] ] - def obj.dig(*args); [ 42 ] end + it "handles type-mixed deep digging" do + h = {} + h[:foo] = [ { bar: [ 1 ] }, [ obj = Object.new, 'str' ] ] + def obj.dig(*args); [ 42 ] end - h.dig(:foo, 0, :bar).should == [ 1 ] - h.dig(:foo, 0, :bar, 0).should == 1 - h.dig(:foo, 1, 1).should == 'str' - # MRI does not recurse values returned from `obj.dig` - h.dig(:foo, 1, 0, 0).should == [ 42 ] - h.dig(:foo, 1, 0, 0, 10).should == [ 42 ] - end + h.dig(:foo, 0, :bar).should == [ 1 ] + h.dig(:foo, 0, :bar, 0).should == 1 + h.dig(:foo, 1, 1).should == 'str' + # MRI does not recurse values returned from `obj.dig` + h.dig(:foo, 1, 0, 0).should == [ 42 ] + h.dig(:foo, 1, 0, 0, 10).should == [ 42 ] + end - it "raises TypeError if an intermediate element does not respond to #dig" do - h = {} - h[:foo] = [ { bar: [ 1 ] }, [ nil, 'str' ] ] - lambda { h.dig(:foo, 0, :bar, 0, 0) }.should raise_error(TypeError) - lambda { h.dig(:foo, 1, 1, 0) }.should raise_error(TypeError) - end + it "raises TypeError if an intermediate element does not respond to #dig" do + h = {} + h[:foo] = [ { bar: [ 1 ] }, [ nil, 'str' ] ] + lambda { h.dig(:foo, 0, :bar, 0, 0) }.should raise_error(TypeError) + lambda { h.dig(:foo, 1, 1, 0) }.should raise_error(TypeError) + end - it "calls #dig on the result of #[] with the remaining arguments" do - h = { foo: { bar: { baz: 42 } } } - h[:foo].should_receive(:dig).with(:bar, :baz).and_return(42) - h.dig(:foo, :bar, :baz).should == 42 - end + it "calls #dig on the result of #[] with the remaining arguments" do + h = { foo: { bar: { baz: 42 } } } + h[:foo].should_receive(:dig).with(:bar, :baz).and_return(42) + h.dig(:foo, :bar, :baz).should == 42 + end - it "respects Hash's default" do - default = {bar: 42} - h = Hash.new(default) - h.dig(:foo).should equal default - h.dig(:foo, :bar).should == 42 - end + it "respects Hash's default" do + default = {bar: 42} + h = Hash.new(default) + h.dig(:foo).should equal default + h.dig(:foo, :bar).should == 42 end end diff --git a/spec/ruby/core/hash/fetch_values_spec.rb b/spec/ruby/core/hash/fetch_values_spec.rb index 1b093f4aa9..a4af153bf7 100644 --- a/spec/ruby/core/hash/fetch_values_spec.rb +++ b/spec/ruby/core/hash/fetch_values_spec.rb @@ -2,32 +2,30 @@ require_relative '../../spec_helper' require_relative 'fixtures/classes' require_relative '../../shared/hash/key_error' -ruby_version_is "2.3" do - describe "Hash#fetch_values" do - before :each do - @hash = { a: 1, b: 2, c: 3 } - end +describe "Hash#fetch_values" do + before :each do + @hash = { a: 1, b: 2, c: 3 } + end - describe "with matched keys" do - it "returns the values for keys" do - @hash.fetch_values(:a).should == [1] - @hash.fetch_values(:a, :c).should == [1, 3] - end + describe "with matched keys" do + it "returns the values for keys" do + @hash.fetch_values(:a).should == [1] + @hash.fetch_values(:a, :c).should == [1, 3] end + end - describe "with unmatched keys" do - it_behaves_like :key_error, ->(obj, key) { obj.fetch_values(key) }, Hash.new(a: 5) + describe "with unmatched keys" do + it_behaves_like :key_error, ->(obj, key) { obj.fetch_values(key) }, Hash.new(a: 5) - it "returns the default value from block" do - @hash.fetch_values(:z) { |key| "`#{key}' is not found" }.should == ["`z' is not found"] - @hash.fetch_values(:a, :z) { |key| "`#{key}' is not found" }.should == [1, "`z' is not found"] - end + it "returns the default value from block" do + @hash.fetch_values(:z) { |key| "`#{key}' is not found" }.should == ["`z' is not found"] + @hash.fetch_values(:a, :z) { |key| "`#{key}' is not found" }.should == [1, "`z' is not found"] end + end - describe "without keys" do - it "returns an empty Array" do - @hash.fetch_values.should == [] - end + describe "without keys" do + it "returns an empty Array" do + @hash.fetch_values.should == [] end end end diff --git a/spec/ruby/core/hash/fixtures/classes.rb b/spec/ruby/core/hash/fixtures/classes.rb index 3d3df576cf..ae907aaff6 100644 --- a/spec/ruby/core/hash/fixtures/classes.rb +++ b/spec/ruby/core/hash/fixtures/classes.rb @@ -17,6 +17,13 @@ module HashSpecs end end + class SubHashSettingInInitialize < Hash + def initialize(*args, &block) + self[:foo] = :bar + super(*args, &block) + end + end + class DefaultHash < Hash def default(key) 100 diff --git a/spec/ruby/core/hash/gt_spec.rb b/spec/ruby/core/hash/gt_spec.rb index 58878e94fc..cd541d4d83 100644 --- a/spec/ruby/core/hash/gt_spec.rb +++ b/spec/ruby/core/hash/gt_spec.rb @@ -2,43 +2,41 @@ require_relative '../../spec_helper' require_relative 'shared/comparison' require_relative 'shared/greater_than' -ruby_version_is "2.3" do - describe "Hash#>" do - it_behaves_like :hash_comparison, :> - it_behaves_like :hash_greater_than, :> +describe "Hash#>" do + it_behaves_like :hash_comparison, :> + it_behaves_like :hash_greater_than, :> - it "returns false if both hashes are identical" do - h = { a: 1, b: 2 } - (h > h).should be_false - end + it "returns false if both hashes are identical" do + h = { a: 1, b: 2 } + (h > h).should be_false end +end - describe "Hash#>" do - before :each do - @hash = {a:1, b:2} - @bigger = {a:1, b:2, c:3} - @unrelated = {c:3, d:4} - @similar = {a:2, b:3} - end +describe "Hash#>" do + before :each do + @hash = {a:1, b:2} + @bigger = {a:1, b:2, c:3} + @unrelated = {c:3, d:4} + @similar = {a:2, b:3} + end - it "returns false when receiver size is smaller than argument" do - (@hash > @bigger).should == false - (@unrelated > @bigger).should == false - end + it "returns false when receiver size is smaller than argument" do + (@hash > @bigger).should == false + (@unrelated > @bigger).should == false + end - it "returns false when receiver size is the same as argument" do - (@hash > @hash).should == false - (@hash > @unrelated).should == false - (@unrelated > @hash).should == false - end + it "returns false when receiver size is the same as argument" do + (@hash > @hash).should == false + (@hash > @unrelated).should == false + (@unrelated > @hash).should == false + end - it "returns true when argument is a subset of receiver" do - (@bigger > @hash).should == true - end + it "returns true when argument is a subset of receiver" do + (@bigger > @hash).should == true + end - it "returns false when keys match but values don't" do - (@hash > @similar).should == false - (@similar > @hash).should == false - end + it "returns false when keys match but values don't" do + (@hash > @similar).should == false + (@similar > @hash).should == false end end diff --git a/spec/ruby/core/hash/gte_spec.rb b/spec/ruby/core/hash/gte_spec.rb index bbb86edc7d..99b89e7217 100644 --- a/spec/ruby/core/hash/gte_spec.rb +++ b/spec/ruby/core/hash/gte_spec.rb @@ -2,43 +2,41 @@ require_relative '../../spec_helper' require_relative 'shared/comparison' require_relative 'shared/greater_than' -ruby_version_is "2.3" do - describe "Hash#>=" do - it_behaves_like :hash_comparison, :>= - it_behaves_like :hash_greater_than, :>= +describe "Hash#>=" do + it_behaves_like :hash_comparison, :>= + it_behaves_like :hash_greater_than, :>= - it "returns true if both hashes are identical" do - h = { a: 1, b: 2 } - (h >= h).should be_true - end + it "returns true if both hashes are identical" do + h = { a: 1, b: 2 } + (h >= h).should be_true end +end - describe "Hash#>=" do - before :each do - @hash = {a:1, b:2} - @bigger = {a:1, b:2, c:3} - @unrelated = {c:3, d:4} - @similar = {a:2, b:3} - end +describe "Hash#>=" do + before :each do + @hash = {a:1, b:2} + @bigger = {a:1, b:2, c:3} + @unrelated = {c:3, d:4} + @similar = {a:2, b:3} + end - it "returns false when receiver size is smaller than argument" do - (@hash >= @bigger).should == false - (@unrelated >= @bigger).should == false - end + it "returns false when receiver size is smaller than argument" do + (@hash >= @bigger).should == false + (@unrelated >= @bigger).should == false + end - it "returns false when argument is not a subset or not equals to receiver" do - (@hash >= @unrelated).should == false - (@unrelated >= @hash).should == false - end + it "returns false when argument is not a subset or not equals to receiver" do + (@hash >= @unrelated).should == false + (@unrelated >= @hash).should == false + end - it "returns true when argument is a subset of receiver or equals to receiver" do - (@bigger >= @hash).should == true - (@hash >= @hash).should == true - end + it "returns true when argument is a subset of receiver or equals to receiver" do + (@bigger >= @hash).should == true + (@hash >= @hash).should == true + end - it "returns false when keys match but values don't" do - (@hash >= @similar).should == false - (@similar >= @hash).should == false - end + it "returns false when keys match but values don't" do + (@hash >= @similar).should == false + (@similar >= @hash).should == false end end diff --git a/spec/ruby/core/hash/initialize_spec.rb b/spec/ruby/core/hash/initialize_spec.rb index ed7163db48..344571631a 100644 --- a/spec/ruby/core/hash/initialize_spec.rb +++ b/spec/ruby/core/hash/initialize_spec.rb @@ -9,16 +9,37 @@ describe "Hash#initialize" do it "can be used to reset default_proc" do h = { "foo" => 1, "bar" => 2 } h.default_proc.should == nil - h.instance_eval { initialize { |_, k| k * 2 } } + h.send(:initialize) { |_, k| k * 2 } h.default_proc.should_not == nil h["a"].should == "aa" end + it "can be used to reset the default value" do + h = {} + h.default = 42 + h.default.should == 42 + h.send(:initialize, 1) + h.default.should == 1 + h.send(:initialize) + h.default.should == nil + end + it "receives the arguments passed to Hash#new" do HashSpecs::NewHash.new(:one, :two)[0].should == :one HashSpecs::NewHash.new(:one, :two)[1].should == :two end + it "does not change the storage, only the default value or proc" do + h = HashSpecs::SubHashSettingInInitialize.new + h.to_a.should == [[:foo, :bar]] + + h = HashSpecs::SubHashSettingInInitialize.new(:default) + h.to_a.should == [[:foo, :bar]] + + h = HashSpecs::SubHashSettingInInitialize.new { :default_block } + h.to_a.should == [[:foo, :bar]] + end + it "returns self" do h = Hash.new h.send(:initialize).should equal(h) diff --git a/spec/ruby/core/hash/lt_spec.rb b/spec/ruby/core/hash/lt_spec.rb index 88f1120e86..2219615880 100644 --- a/spec/ruby/core/hash/lt_spec.rb +++ b/spec/ruby/core/hash/lt_spec.rb @@ -2,43 +2,41 @@ require_relative '../../spec_helper' require_relative 'shared/comparison' require_relative 'shared/less_than' -ruby_version_is "2.3" do - describe "Hash#<" do - it_behaves_like :hash_comparison, :< - it_behaves_like :hash_less_than, :< +describe "Hash#<" do + it_behaves_like :hash_comparison, :< + it_behaves_like :hash_less_than, :< - it "returns false if both hashes are identical" do - h = { a: 1, b: 2 } - (h < h).should be_false - end + it "returns false if both hashes are identical" do + h = { a: 1, b: 2 } + (h < h).should be_false end +end - describe "Hash#<" do - before :each do - @hash = {a:1, b:2} - @bigger = {a:1, b:2, c:3} - @unrelated = {c:3, d:4} - @similar = {a:2, b:3} - end +describe "Hash#<" do + before :each do + @hash = {a:1, b:2} + @bigger = {a:1, b:2, c:3} + @unrelated = {c:3, d:4} + @similar = {a:2, b:3} + end - it "returns false when receiver size is larger than argument" do - (@bigger < @hash).should == false - (@bigger < @unrelated).should == false - end + it "returns false when receiver size is larger than argument" do + (@bigger < @hash).should == false + (@bigger < @unrelated).should == false + end - it "returns false when receiver size is the same as argument" do - (@hash < @hash).should == false - (@hash < @unrelated).should == false - (@unrelated < @hash).should == false - end + it "returns false when receiver size is the same as argument" do + (@hash < @hash).should == false + (@hash < @unrelated).should == false + (@unrelated < @hash).should == false + end - it "returns true when receiver is a subset of argument" do - (@hash < @bigger).should == true - end + it "returns true when receiver is a subset of argument" do + (@hash < @bigger).should == true + end - it "returns false when keys match but values don't" do - (@hash < @similar).should == false - (@similar < @hash).should == false - end + it "returns false when keys match but values don't" do + (@hash < @similar).should == false + (@similar < @hash).should == false end end diff --git a/spec/ruby/core/hash/lte_spec.rb b/spec/ruby/core/hash/lte_spec.rb index 1463c263d0..a166e5bca4 100644 --- a/spec/ruby/core/hash/lte_spec.rb +++ b/spec/ruby/core/hash/lte_spec.rb @@ -2,43 +2,41 @@ require_relative '../../spec_helper' require_relative 'shared/comparison' require_relative 'shared/less_than' -ruby_version_is "2.3" do - describe "Hash#<=" do - it_behaves_like :hash_comparison, :<= - it_behaves_like :hash_less_than, :<= +describe "Hash#<=" do + it_behaves_like :hash_comparison, :<= + it_behaves_like :hash_less_than, :<= - it "returns true if both hashes are identical" do - h = { a: 1, b: 2 } - (h <= h).should be_true - end + it "returns true if both hashes are identical" do + h = { a: 1, b: 2 } + (h <= h).should be_true end +end - describe "Hash#<=" do - before :each do - @hash = {a:1, b:2} - @bigger = {a:1, b:2, c:3} - @unrelated = {c:3, d:4} - @similar = {a:2, b:3} - end +describe "Hash#<=" do + before :each do + @hash = {a:1, b:2} + @bigger = {a:1, b:2, c:3} + @unrelated = {c:3, d:4} + @similar = {a:2, b:3} + end - it "returns false when receiver size is larger than argument" do - (@bigger <= @hash).should == false - (@bigger <= @unrelated).should == false - end + it "returns false when receiver size is larger than argument" do + (@bigger <= @hash).should == false + (@bigger <= @unrelated).should == false + end - it "returns false when receiver size is the same as argument" do - (@hash <= @unrelated).should == false - (@unrelated <= @hash).should == false - end + it "returns false when receiver size is the same as argument" do + (@hash <= @unrelated).should == false + (@unrelated <= @hash).should == false + end - it "returns true when receiver is a subset of argument or equals to argument" do - (@hash <= @bigger).should == true - (@hash <= @hash).should == true - end + it "returns true when receiver is a subset of argument or equals to argument" do + (@hash <= @bigger).should == true + (@hash <= @hash).should == true + end - it "returns false when keys match but values don't" do - (@hash <= @similar).should == false - (@similar <= @hash).should == false - end + it "returns false when keys match but values don't" do + (@hash <= @similar).should == false + (@similar <= @hash).should == false end end diff --git a/spec/ruby/core/hash/shared/to_s.rb b/spec/ruby/core/hash/shared/to_s.rb index 32c86f9d33..88333e0f42 100644 --- a/spec/ruby/core/hash/shared/to_s.rb +++ b/spec/ruby/core/hash/shared/to_s.rb @@ -87,23 +87,10 @@ describe :hash_to_s, shared: true do { nil => nil }.untrust.send(@method).untrusted?.should be_true end - ruby_version_is ''...'2.3' do - it "raises if inspected result is not default external encoding" do - utf_16be = mock("utf_16be") - utf_16be.should_receive(:inspect).and_return(%<"utf_16be \u3042">.encode!(Encoding::UTF_16BE)) - - lambda { - {a: utf_16be}.send(@method) - }.should raise_error(Encoding::CompatibilityError) - end - end + it "does not raise if inspected result is not default external encoding" do + utf_16be = mock("utf_16be") + utf_16be.should_receive(:inspect).and_return(%<"utf_16be \u3042">.encode!(Encoding::UTF_16BE)) - ruby_version_is '2.3' do - it "does not raise if inspected result is not default external encoding" do - utf_16be = mock("utf_16be") - utf_16be.should_receive(:inspect).and_return(%<"utf_16be \u3042">.encode!(Encoding::UTF_16BE)) - - {a: utf_16be}.send(@method).should == '{:a=>"utf_16be \u3042"}' - end + {a: utf_16be}.send(@method).should == '{:a=>"utf_16be \u3042"}' end end diff --git a/spec/ruby/core/hash/to_proc_spec.rb b/spec/ruby/core/hash/to_proc_spec.rb index 3dc6a91459..ca55604043 100644 --- a/spec/ruby/core/hash/to_proc_spec.rb +++ b/spec/ruby/core/hash/to_proc_spec.rb @@ -1,89 +1,87 @@ require_relative '../../spec_helper' require_relative 'fixtures/classes' -ruby_version_is "2.3" do - describe "Hash#to_proc" do +describe "Hash#to_proc" do + before :each do + @key = Object.new + @value = Object.new + @hash = { @key => @value } + @default = Object.new + @unstored = Object.new + end + + it "returns an instance of Proc" do + @hash.to_proc.should be_an_instance_of Proc + end + + describe "the returned proc" do before :each do - @key = Object.new - @value = Object.new - @hash = { @key => @value } - @default = Object.new - @unstored = Object.new + @proc = @hash.to_proc end - it "returns an instance of Proc" do - @hash.to_proc.should be_an_instance_of Proc + it "is not a lambda" do + @proc.lambda?.should == false end - describe "the returned proc" do - before :each do - @proc = @hash.to_proc - end - - it "is not a lambda" do - @proc.lambda?.should == false - end + it "raises ArgumentError if not passed exactly one argument" do + lambda { + @proc.call + }.should raise_error(ArgumentError) - it "raises ArgumentError if not passed exactly one argument" do - lambda { - @proc.call - }.should raise_error(ArgumentError) + lambda { + @proc.call 1, 2 + }.should raise_error(ArgumentError) + end - lambda { - @proc.call 1, 2 - }.should raise_error(ArgumentError) + context "with a stored key" do + it "returns the paired value" do + @proc.call(@key).should equal(@value) end + end - context "with a stored key" do - it "returns the paired value" do - @proc.call(@key).should equal(@value) - end + context "passed as a block" do + it "retrieves the hash's values" do + [@key].map(&@proc)[0].should equal(@value) end - context "passed as a block" do - it "retrieves the hash's values" do - [@key].map(&@proc)[0].should equal(@value) - end - - context "to instance_exec" do - it "always retrieves the original hash's values" do - hash = {foo: 1, bar: 2} - proc = hash.to_proc + context "to instance_exec" do + it "always retrieves the original hash's values" do + hash = {foo: 1, bar: 2} + proc = hash.to_proc - hash.instance_exec(:foo, &proc).should == 1 + hash.instance_exec(:foo, &proc).should == 1 - hash2 = {quux: 1} - hash2.instance_exec(:foo, &proc).should == 1 - end + hash2 = {quux: 1} + hash2.instance_exec(:foo, &proc).should == 1 end end + end - context "with no stored key" do - it "returns nil" do - @proc.call(@unstored).should be_nil - end - - context "when the hash has a default value" do - before :each do - @hash.default = @default - end + context "with no stored key" do + it "returns nil" do + @proc.call(@unstored).should be_nil + end - it "returns the default value" do - @proc.call(@unstored).should equal(@default) - end + context "when the hash has a default value" do + before :each do + @hash.default = @default end - context "when the hash has a default proc" do - it "returns an evaluated value from the default proc" do - @hash.default_proc = -> hash, called_with { [hash.keys, called_with] } - @proc.call(@unstored).should == [[@key], @unstored] - end + it "returns the default value" do + @proc.call(@unstored).should equal(@default) end end - it "raises an ArgumentError when calling #call on the Proc with no arguments" do - lambda { @hash.to_proc.call }.should raise_error(ArgumentError) + context "when the hash has a default proc" do + it "returns an evaluated value from the default proc" do + @hash.default_proc = -> hash, called_with { [hash.keys, called_with] } + @proc.call(@unstored).should == [[@key], @unstored] + end end end + + it "raises an ArgumentError when calling #call on the Proc with no arguments" do + lambda { @hash.to_proc.call }.should raise_error(ArgumentError) + end end end diff --git a/spec/ruby/core/io/binread_spec.rb b/spec/ruby/core/io/binread_spec.rb index b7ab8e7fbc..5e936ac6ba 100644 --- a/spec/ruby/core/io/binread_spec.rb +++ b/spec/ruby/core/io/binread_spec.rb @@ -41,9 +41,7 @@ describe "IO.binread" do lambda { IO.binread @fname, -1 }.should raise_error(ArgumentError) end - ruby_version_is "2.3" do # MRI leaks the fd on older versions - it "raises an Errno::EINVAL when not passed a valid offset" do - lambda { IO.binread @fname, 0, -1 }.should raise_error(Errno::EINVAL) - end + it "raises an Errno::EINVAL when not passed a valid offset" do + lambda { IO.binread @fname, 0, -1 }.should raise_error(Errno::EINVAL) end end diff --git a/spec/ruby/core/io/close_on_exec_spec.rb b/spec/ruby/core/io/close_on_exec_spec.rb index 53546e6bb6..d6ba3c3cef 100644 --- a/spec/ruby/core/io/close_on_exec_spec.rb +++ b/spec/ruby/core/io/close_on_exec_spec.rb @@ -11,17 +11,7 @@ describe "IO#close_on_exec=" do rm_r @name end - guard -> { platform_is :windows and ruby_version_is ""..."2.3" } do - it "returns false from #respond_to?" do - @io.respond_to?(:close_on_exec=).should be_false - end - - it "raises a NotImplementedError when called" do - lambda { @io.close_on_exec = true }.should raise_error(NotImplementedError) - end - end - - guard -> { platform_is_not :windows or ruby_version_is "2.3" } do + guard -> { platform_is_not :windows } do it "sets the close-on-exec flag if true" do @io.close_on_exec = true @io.close_on_exec?.should == true @@ -72,17 +62,7 @@ describe "IO#close_on_exec?" do rm_r @name end - guard -> { platform_is :windows and ruby_version_is ""..."2.3" } do - it "returns false from #respond_to?" do - @io.respond_to?(:close_on_exec?).should be_false - end - - it "raises a NotImplementedError when called" do - lambda { @io.close_on_exec? }.should raise_error(NotImplementedError) - end - end - - guard -> { platform_is_not :windows or ruby_version_is "2.3" } do + guard -> { platform_is_not :windows } do it "returns true by default" do @io.close_on_exec?.should == true end diff --git a/spec/ruby/core/io/close_read_spec.rb b/spec/ruby/core/io/close_read_spec.rb index f928808c9b..9783cb252a 100644 --- a/spec/ruby/core/io/close_read_spec.rb +++ b/spec/ruby/core/io/close_read_spec.rb @@ -19,20 +19,10 @@ describe "IO#close_read" do lambda { @io.read }.should raise_error(IOError) end - ruby_version_is ''...'2.3' do - it "raises an IOError on subsequent invocations" do - @io.close_read - - lambda { @io.close_read }.should raise_error(IOError) - end - end - - ruby_version_is '2.3' do - it "does nothing on subsequent invocations" do - @io.close_read + it "does nothing on subsequent invocations" do + @io.close_read - @io.close_read.should be_nil - end + @io.close_read.should be_nil end it "allows subsequent invocation of close" do @@ -62,19 +52,9 @@ describe "IO#close_read" do io.closed?.should == true end - ruby_version_is ''...'2.3' do - it "raises IOError on closed stream" do - @io.close + it "does nothing on closed stream" do + @io.close - lambda { @io.close_read }.should raise_error(IOError) - end - end - - ruby_version_is '2.3' do - it "does nothing on closed stream" do - @io.close - - @io.close_read.should be_nil - end + @io.close_read.should be_nil end end diff --git a/spec/ruby/core/io/close_spec.rb b/spec/ruby/core/io/close_spec.rb index 7a2b97ac29..b7aa2276d1 100644 --- a/spec/ruby/core/io/close_spec.rb +++ b/spec/ruby/core/io/close_spec.rb @@ -38,19 +38,10 @@ describe "IO#close" do lambda { @io.write "data" }.should_not raise_error(IOError) end - ruby_version_is ''...'2.3' do - it "raises an IOError if closed" do - @io.close - lambda { @io.close }.should raise_error(IOError) - end - end - - ruby_version_is "2.3" do - it "does nothing if already closed" do - @io.close + it "does nothing if already closed" do + @io.close - @io.close.should be_nil - end + @io.close.should be_nil end ruby_version_is '2.5' do diff --git a/spec/ruby/core/io/close_write_spec.rb b/spec/ruby/core/io/close_write_spec.rb index c2577536fa..8643659025 100644 --- a/spec/ruby/core/io/close_write_spec.rb +++ b/spec/ruby/core/io/close_write_spec.rb @@ -18,20 +18,10 @@ describe "IO#close_write" do lambda { @io.write "attempt to write" }.should raise_error(IOError) end - ruby_version_is ''...'2.3' do - it "raises an IOError on subsequent invocations" do - @io.close_write - - lambda { @io.close_write }.should raise_error(IOError) - end - end - - ruby_version_is '2.3' do - it "does nothing on subsequent invocations" do - @io.close_write + it "does nothing on subsequent invocations" do + @io.close_write - @io.close_write.should be_nil - end + @io.close_write.should be_nil end it "allows subsequent invocation of close" do @@ -66,19 +56,9 @@ describe "IO#close_write" do @io.read.should == "12345\n" end - ruby_version_is ''...'2.3' do - it "raises IOError on closed stream" do - @io.close + it "does nothing on closed stream" do + @io.close - lambda { @io.close_write }.should raise_error(IOError) - end - end - - ruby_version_is '2.3' do - it "does nothing on closed stream" do - @io.close - - @io.close_write.should be_nil - end + @io.close_write.should be_nil end end diff --git a/spec/ruby/core/io/each_codepoint_spec.rb b/spec/ruby/core/io/each_codepoint_spec.rb index 920aaef07d..19824c38e4 100644 --- a/spec/ruby/core/io/each_codepoint_spec.rb +++ b/spec/ruby/core/io/each_codepoint_spec.rb @@ -37,9 +37,7 @@ describe "IO#each_codepoint" do @io.close if @io end - ruby_version_is "2.3" do # earlier versions stay blocked - it "raises an exception at incomplete character before EOF when conversion takes place" do - lambda { @io.each_codepoint {} }.should raise_error(ArgumentError) - end + it "raises an exception at incomplete character before EOF when conversion takes place" do + lambda { @io.each_codepoint {} }.should raise_error(ArgumentError) end end diff --git a/spec/ruby/core/io/read_nonblock_spec.rb b/spec/ruby/core/io/read_nonblock_spec.rb index cfa1e95e7f..e224707e38 100644 --- a/spec/ruby/core/io/read_nonblock_spec.rb +++ b/spec/ruby/core/io/read_nonblock_spec.rb @@ -22,23 +22,21 @@ describe "IO#read_nonblock" do } end - ruby_version_is "2.3" do - context "when exception option is set to false" do - context "when there is no data" do - it "returns :wait_readable" do - @read.read_nonblock(5, exception: false).should == :wait_readable - end + context "when exception option is set to false" do + context "when there is no data" do + it "returns :wait_readable" do + @read.read_nonblock(5, exception: false).should == :wait_readable end + end - context "when the end is reached" do - it "returns nil" do - @write << "hello" - @write.close + context "when the end is reached" do + it "returns nil" do + @write << "hello" + @write.close - @read.read_nonblock(5) + @read.read_nonblock(5) - @read.read_nonblock(5, exception: false).should be_nil - end + @read.read_nonblock(5, exception: false).should be_nil end end end diff --git a/spec/ruby/core/io/write_nonblock_spec.rb b/spec/ruby/core/io/write_nonblock_spec.rb index d493289a2c..b0da9b7e11 100644 --- a/spec/ruby/core/io/write_nonblock_spec.rb +++ b/spec/ruby/core/io/write_nonblock_spec.rb @@ -66,12 +66,10 @@ describe 'IO#write_nonblock' do } end - ruby_version_is "2.3" do - context "when exception option is set to false" do - it "returns :wait_writable when the operation would block" do - loop { break if @write.write_nonblock("a" * 10_000, exception: false) == :wait_writable } - 1.should == 1 - end + context "when exception option is set to false" do + it "returns :wait_writable when the operation would block" do + loop { break if @write.write_nonblock("a" * 10_000, exception: false) == :wait_writable } + 1.should == 1 end end diff --git a/spec/ruby/core/kernel/define_singleton_method_spec.rb b/spec/ruby/core/kernel/define_singleton_method_spec.rb index 81c91fd215..c2f2da7c79 100644 --- a/spec/ruby/core/kernel/define_singleton_method_spec.rb +++ b/spec/ruby/core/kernel/define_singleton_method_spec.rb @@ -86,16 +86,14 @@ describe "Kernel#define_singleton_method" do }.should raise_error(ArgumentError) end - ruby_version_is "2.3" do - it "does not use the caller block when no block is given" do - o = Object.new - def o.define(name) - define_singleton_method(name) - end - - lambda { - o.define(:foo) { raise "not used" } - }.should raise_error(ArgumentError) + it "does not use the caller block when no block is given" do + o = Object.new + def o.define(name) + define_singleton_method(name) end + + lambda { + o.define(:foo) { raise "not used" } + }.should raise_error(ArgumentError) end end diff --git a/spec/ruby/core/kernel/loop_spec.rb b/spec/ruby/core/kernel/loop_spec.rb index 522919ec41..3386326a13 100644 --- a/spec/ruby/core/kernel/loop_spec.rb +++ b/spec/ruby/core/kernel/loop_spec.rb @@ -58,15 +58,13 @@ describe "Kernel.loop" do lambda{ loop do raise StandardError end }.should raise_error( StandardError ) end - ruby_version_is "2.3" do - it "returns StopIteration#result, the result value of a finished iterator" do - e = Enumerator.new { |y| - y << 1 - y << 2 - :stopped - } - loop { e.next }.should == :stopped - end + it "returns StopIteration#result, the result value of a finished iterator" do + e = Enumerator.new { |y| + y << 1 + y << 2 + :stopped + } + loop { e.next }.should == :stopped end describe "when no block is given" do diff --git a/spec/ruby/core/kernel/require_relative_spec.rb b/spec/ruby/core/kernel/require_relative_spec.rb index d8113daf6c..4a2ef87357 100644 --- a/spec/ruby/core/kernel/require_relative_spec.rb +++ b/spec/ruby/core/kernel/require_relative_spec.rb @@ -40,6 +40,48 @@ describe "Kernel#require_relative with a relative path" do ScratchPad.recorded.should == [:loaded] end + describe "in an #instance_eval with a" do + + it "synthetic file base name loads a file base name relative to the working directory" do + Dir.chdir @abs_dir do + Object.new.instance_eval("require_relative(#{File.basename(@path).inspect})", "foo.rb").should be_true + end + ScratchPad.recorded.should == [:loaded] + end + + it "synthetic file path loads a relative path relative to the working directory plus the directory of the synthetic path" do + Dir.chdir @abs_dir do + Object.new.instance_eval("require_relative(File.join('..', #{File.basename(@path).inspect}))", "bar/foo.rb").should be_true + end + ScratchPad.recorded.should == [:loaded] + end + + platform_is_not :windows do + it "synthetic relative file path with a Windows path separator specified loads a relative path relative to the working directory" do + Dir.chdir @abs_dir do + Object.new.instance_eval("require_relative(#{File.basename(@path).inspect})", "bar\\foo.rb").should be_true + end + ScratchPad.recorded.should == [:loaded] + end + end + + it "absolute file path loads a path relative to the absolute path" do + Object.new.instance_eval("require_relative(#{@path.inspect})", __FILE__).should be_true + ScratchPad.recorded.should == [:loaded] + end + + it "absolute file path loads a path relative to the root directory" do + root = @abs_path + until File.dirname(root) == root + root = File.dirname(root) + end + root_relative = @abs_path[root.size..-1] + Object.new.instance_eval("require_relative(#{root_relative.inspect})", "/").should be_true + ScratchPad.recorded.should == [:loaded] + end + + end + it "loads a file defining many methods" do require_relative("#{@dir}/methods_fixture.rb").should be_true ScratchPad.recorded.should == [:loaded] diff --git a/spec/ruby/core/kernel/shared/require.rb b/spec/ruby/core/kernel/shared/require.rb index bf92b5509c..5e3f98f813 100644 --- a/spec/ruby/core/kernel/shared/require.rb +++ b/spec/ruby/core/kernel/shared/require.rb @@ -454,21 +454,7 @@ describe :kernel_require, shared: true do ScratchPad.recorded.should == [] end - ruby_version_is "2.2"..."2.3" do - it "complex, enumerator, rational and unicode_normalize are already required" do - provided = %w[complex enumerator rational unicode_normalize] - features = ruby_exe("puts $LOADED_FEATURES", options: '--disable-gems') - provided.each { |feature| - features.should =~ /\b#{feature}\.(rb|so)$/ - } - - code = provided.map { |f| "puts require #{f.inspect}\n" }.join - required = ruby_exe(code, options: '--disable-gems') - required.should == "false\n" * provided.size - end - end - - ruby_version_is "2.3"..."2.5" do + ruby_version_is ""..."2.5" do it "complex, enumerator, rational, thread and unicode_normalize are already required" do provided = %w[complex enumerator rational thread unicode_normalize] features = ruby_exe("puts $LOADED_FEATURES", options: '--disable-gems') diff --git a/spec/ruby/core/main/using_spec.rb b/spec/ruby/core/main/using_spec.rb index d043079316..1fb812f5cc 100644 --- a/spec/ruby/core/main/using_spec.rb +++ b/spec/ruby/core/main/using_spec.rb @@ -1,135 +1,132 @@ require_relative '../../spec_helper' +require_relative 'fixtures/classes' -ruby_version_is "2.0.0" do - require_relative 'fixtures/classes' +describe "main.using" do + it "requires one Module argument" do + lambda do + eval('using', TOPLEVEL_BINDING) + end.should raise_error(ArgumentError) - describe "main.using" do - it "requires one Module argument" do - lambda do - eval('using', TOPLEVEL_BINDING) - end.should raise_error(ArgumentError) + lambda do + eval('using "foo"', TOPLEVEL_BINDING) + end.should raise_error(TypeError) + end - lambda do - eval('using "foo"', TOPLEVEL_BINDING) - end.should raise_error(TypeError) - end + it "uses refinements from the given module only in the target file" do + require_relative 'fixtures/string_refinement' + load File.expand_path('../fixtures/string_refinement_user.rb', __FILE__) + MainSpecs::DATA[:in_module].should == 'foo' + MainSpecs::DATA[:toplevel].should == 'foo' + lambda do + 'hello'.foo + end.should raise_error(NoMethodError) + end - it "uses refinements from the given module only in the target file" do - require_relative 'fixtures/string_refinement' - load File.expand_path('../fixtures/string_refinement_user.rb', __FILE__) - MainSpecs::DATA[:in_module].should == 'foo' - MainSpecs::DATA[:toplevel].should == 'foo' - lambda do - 'hello'.foo - end.should raise_error(NoMethodError) - end + it "uses refinements from the given module for method calls in the target file" do + require_relative 'fixtures/string_refinement' + load File.expand_path('../fixtures/string_refinement_user.rb', __FILE__) + lambda do + 'hello'.foo + end.should raise_error(NoMethodError) + MainSpecs.call_foo('hello').should == 'foo' + end - it "uses refinements from the given module for method calls in the target file" do - require_relative 'fixtures/string_refinement' - load File.expand_path('../fixtures/string_refinement_user.rb', __FILE__) - lambda do - 'hello'.foo - end.should raise_error(NoMethodError) - MainSpecs.call_foo('hello').should == 'foo' + it "uses refinements from the given module in the eval string" do + cls = MainSpecs::DATA[:cls] = Class.new {def foo; 'foo'; end} + MainSpecs::DATA[:mod] = Module.new do + refine(cls) do + def foo; 'bar'; end + end end + eval(<<-EOS, TOPLEVEL_BINDING).should == 'bar' + using MainSpecs::DATA[:mod] + MainSpecs::DATA[:cls].new.foo + EOS + end - it "uses refinements from the given module in the eval string" do - cls = MainSpecs::DATA[:cls] = Class.new {def foo; 'foo'; end} - MainSpecs::DATA[:mod] = Module.new do - refine(cls) do - def foo; 'bar'; end - end + it "does not affect methods defined before it is called" do + cls = Class.new {def foo; 'foo'; end} + MainSpecs::DATA[:mod] = Module.new do + refine(cls) do + def foo; 'bar'; end end - eval(<<-EOS, TOPLEVEL_BINDING).should == 'bar' - using MainSpecs::DATA[:mod] - MainSpecs::DATA[:cls].new.foo - EOS end - - it "does not affect methods defined before it is called" do - cls = Class.new {def foo; 'foo'; end} - MainSpecs::DATA[:mod] = Module.new do - refine(cls) do - def foo; 'bar'; end - end + x = MainSpecs::DATA[:x] = Object.new + eval <<-EOS, TOPLEVEL_BINDING + x = MainSpecs::DATA[:x] + def x.before_using(obj) + obj.foo + end + using MainSpecs::DATA[:mod] + def x.after_using(obj) + obj.foo end - x = MainSpecs::DATA[:x] = Object.new - eval <<-EOS, TOPLEVEL_BINDING - x = MainSpecs::DATA[:x] - def x.before_using(obj) - obj.foo - end - using MainSpecs::DATA[:mod] - def x.after_using(obj) - obj.foo - end - EOS + EOS - obj = cls.new - x.before_using(obj).should == 'foo' - x.after_using(obj).should == 'bar' - end + obj = cls.new + x.before_using(obj).should == 'foo' + x.after_using(obj).should == 'bar' + end - it "propagates refinements added to existing modules after it is called" do - cls = Class.new {def foo; 'foo'; end} - mod = MainSpecs::DATA[:mod] = Module.new do - refine(cls) do - def foo; 'quux'; end - end + it "propagates refinements added to existing modules after it is called" do + cls = Class.new {def foo; 'foo'; end} + mod = MainSpecs::DATA[:mod] = Module.new do + refine(cls) do + def foo; 'quux'; end end - x = MainSpecs::DATA[:x] = Object.new - eval <<-EOS, TOPLEVEL_BINDING - using MainSpecs::DATA[:mod] - x = MainSpecs::DATA[:x] - def x.call_foo(obj) - obj.foo - end - def x.call_bar(obj) - obj.bar - end - EOS + end + x = MainSpecs::DATA[:x] = Object.new + eval <<-EOS, TOPLEVEL_BINDING + using MainSpecs::DATA[:mod] + x = MainSpecs::DATA[:x] + def x.call_foo(obj) + obj.foo + end + def x.call_bar(obj) + obj.bar + end + EOS - obj = cls.new - x.call_foo(obj).should == 'quux' + obj = cls.new + x.call_foo(obj).should == 'quux' - mod.module_eval do - refine(cls) do - def bar; 'quux'; end - end + mod.module_eval do + refine(cls) do + def bar; 'quux'; end end - - x.call_bar(obj).should == 'quux' end - it "does not propagate refinements of new modules added after it is called" do - cls = Class.new {def foo; 'foo'; end} - cls2 = Class.new {def bar; 'bar'; end} - mod = MainSpecs::DATA[:mod] = Module.new do - refine(cls) do - def foo; 'quux'; end - end + x.call_bar(obj).should == 'quux' + end + + it "does not propagate refinements of new modules added after it is called" do + cls = Class.new {def foo; 'foo'; end} + cls2 = Class.new {def bar; 'bar'; end} + mod = MainSpecs::DATA[:mod] = Module.new do + refine(cls) do + def foo; 'quux'; end end - x = MainSpecs::DATA[:x] = Object.new - eval <<-EOS, TOPLEVEL_BINDING - using MainSpecs::DATA[:mod] - x = MainSpecs::DATA[:x] - def x.call_foo(obj) - obj.foo - end - def x.call_bar(obj) - obj.bar - end - EOS + end + x = MainSpecs::DATA[:x] = Object.new + eval <<-EOS, TOPLEVEL_BINDING + using MainSpecs::DATA[:mod] + x = MainSpecs::DATA[:x] + def x.call_foo(obj) + obj.foo + end + def x.call_bar(obj) + obj.bar + end + EOS - x.call_foo(cls.new).should == 'quux' + x.call_foo(cls.new).should == 'quux' - mod.module_eval do - refine(cls2) do - def bar; 'quux'; end - end + mod.module_eval do + refine(cls2) do + def bar; 'quux'; end end - - x.call_bar(cls2.new).should == 'bar' end + + x.call_bar(cls2.new).should == 'bar' end end diff --git a/spec/ruby/core/module/autoload_spec.rb b/spec/ruby/core/module/autoload_spec.rb index f375ac2450..f355a5968d 100644 --- a/spec/ruby/core/module/autoload_spec.rb +++ b/spec/ruby/core/module/autoload_spec.rb @@ -400,52 +400,51 @@ describe "Module#autoload" do ModuleSpecs::Autoload.send(:remove_const, :Concur) end - ruby_bug "#10892", ""..."2.3" do - it "blocks others threads while doing an autoload" do - file_path = fixture(__FILE__, "repeated_concurrent_autoload.rb") - autoload_path = file_path.sub(/\.rb\Z/, '') - mod_count = 30 - thread_count = 16 - - mod_names = [] - mod_count.times do |i| - mod_name = :"Mod#{i}" - Object.autoload mod_name, autoload_path - mod_names << mod_name - end + # https://bugs.ruby-lang.org/issues/10892 + it "blocks others threads while doing an autoload" do + file_path = fixture(__FILE__, "repeated_concurrent_autoload.rb") + autoload_path = file_path.sub(/\.rb\Z/, '') + mod_count = 30 + thread_count = 16 + + mod_names = [] + mod_count.times do |i| + mod_name = :"Mod#{i}" + Object.autoload mod_name, autoload_path + mod_names << mod_name + end + + barrier = ModuleSpecs::CyclicBarrier.new thread_count + ScratchPad.record ModuleSpecs::ThreadSafeCounter.new - barrier = ModuleSpecs::CyclicBarrier.new thread_count - ScratchPad.record ModuleSpecs::ThreadSafeCounter.new - - threads = (1..thread_count).map do - Thread.new do - mod_names.each do |mod_name| - break false unless barrier.enabled? - - was_last_one_in = barrier.await # wait for all threads to finish the iteration - # clean up so we can autoload the same file again - $LOADED_FEATURES.delete(file_path) if was_last_one_in && $LOADED_FEATURES.include?(file_path) - barrier.await # get ready for race - - begin - Object.const_get(mod_name).foo - rescue NoMethodError - barrier.disable! - break false - end + threads = (1..thread_count).map do + Thread.new do + mod_names.each do |mod_name| + break false unless barrier.enabled? + + was_last_one_in = barrier.await # wait for all threads to finish the iteration + # clean up so we can autoload the same file again + $LOADED_FEATURES.delete(file_path) if was_last_one_in && $LOADED_FEATURES.include?(file_path) + barrier.await # get ready for race + + begin + Object.const_get(mod_name).foo + rescue NoMethodError + barrier.disable! + break false end end end + end - # check that no thread got a NoMethodError because of partially loaded module - threads.all? {|t| t.value}.should be_true + # check that no thread got a NoMethodError because of partially loaded module + threads.all? {|t| t.value}.should be_true - # check that the autoloaded file was evaled exactly once - ScratchPad.recorded.get.should == mod_count + # check that the autoloaded file was evaled exactly once + ScratchPad.recorded.get.should == mod_count - mod_names.each do |mod_name| - Object.send(:remove_const, mod_name) - end + mod_names.each do |mod_name| + Object.send(:remove_const, mod_name) end end diff --git a/spec/ruby/core/module/define_method_spec.rb b/spec/ruby/core/module/define_method_spec.rb index 957b401415..3f35c051a1 100644 --- a/spec/ruby/core/module/define_method_spec.rb +++ b/spec/ruby/core/module/define_method_spec.rb @@ -222,19 +222,17 @@ describe "Module#define_method" do }.should raise_error(ArgumentError) end - ruby_version_is "2.3" do - it "does not use the caller block when no block is given" do - o = Object.new - def o.define(name) - self.class.class_eval do - define_method(name) - end + it "does not use the caller block when no block is given" do + o = Object.new + def o.define(name) + self.class.class_eval do + define_method(name) end - - lambda { - o.define(:foo) { raise "not used" } - }.should raise_error(ArgumentError) end + + lambda { + o.define(:foo) { raise "not used" } + }.should raise_error(ArgumentError) end it "does not change the arity check style of the original proc" do diff --git a/spec/ruby/core/module/deprecate_constant_spec.rb b/spec/ruby/core/module/deprecate_constant_spec.rb index 4564497738..0954a6d8a5 100644 --- a/spec/ruby/core/module/deprecate_constant_spec.rb +++ b/spec/ruby/core/module/deprecate_constant_spec.rb @@ -1,52 +1,50 @@ require_relative '../../spec_helper' -ruby_version_is "2.3" do - describe "Module#deprecate_constant" do - before :each do - @module = Module.new - @value = :value - @module::PUBLIC1 = @value - @module::PUBLIC2 = @value - @module::PRIVATE = @value - @module.private_constant :PRIVATE - @module.deprecate_constant :PRIVATE - @pattern = /deprecated/ - end - - describe "when accessing the deprecated module" do - it "passes the accessing" do - @module.deprecate_constant :PUBLIC1 - - value = nil - lambda { - value = @module::PUBLIC1 - }.should complain(@pattern) - value.should equal(@value) +describe "Module#deprecate_constant" do + before :each do + @module = Module.new + @value = :value + @module::PUBLIC1 = @value + @module::PUBLIC2 = @value + @module::PRIVATE = @value + @module.private_constant :PRIVATE + @module.deprecate_constant :PRIVATE + @pattern = /deprecated/ + end - lambda { @module::PRIVATE }.should raise_error(NameError) - end + describe "when accessing the deprecated module" do + it "passes the accessing" do + @module.deprecate_constant :PUBLIC1 - it "warns with a message" do - @module.deprecate_constant :PUBLIC1 + value = nil + lambda { + value = @module::PUBLIC1 + }.should complain(@pattern) + value.should equal(@value) - lambda { @module::PUBLIC1 }.should complain(@pattern) - lambda { @module.const_get :PRIVATE }.should complain(@pattern) - end + lambda { @module::PRIVATE }.should raise_error(NameError) end - it "accepts multiple symbols and strings as constant names" do - @module.deprecate_constant "PUBLIC1", :PUBLIC2 + it "warns with a message" do + @module.deprecate_constant :PUBLIC1 lambda { @module::PUBLIC1 }.should complain(@pattern) - lambda { @module::PUBLIC2 }.should complain(@pattern) + lambda { @module.const_get :PRIVATE }.should complain(@pattern) end + end - it "returns self" do - @module.deprecate_constant(:PUBLIC1).should equal(@module) - end + it "accepts multiple symbols and strings as constant names" do + @module.deprecate_constant "PUBLIC1", :PUBLIC2 - it "raises a NameError when given an undefined name" do - lambda { @module.deprecate_constant :UNDEFINED }.should raise_error(NameError) - end + lambda { @module::PUBLIC1 }.should complain(@pattern) + lambda { @module::PUBLIC2 }.should complain(@pattern) + end + + it "returns self" do + @module.deprecate_constant(:PUBLIC1).should equal(@module) + end + + it "raises a NameError when given an undefined name" do + lambda { @module.deprecate_constant :UNDEFINED }.should raise_error(NameError) end end diff --git a/spec/ruby/core/module/prepend_spec.rb b/spec/ruby/core/module/prepend_spec.rb index 35b31f1fb0..ca80eb360f 100644 --- a/spec/ruby/core/module/prepend_spec.rb +++ b/spec/ruby/core/module/prepend_spec.rb @@ -110,12 +110,10 @@ describe "Module#prepend" do c.instance_method(:alias).owner.should == c end - ruby_version_is "2.3" do - it "reports the class for the owner of a method aliased from the prepended module" do - m = Module.new { def meth; :m end } - c = Class.new { prepend(m); alias_method :alias, :meth } - c.instance_method(:alias).owner.should == c - end + it "reports the class for the owner of a method aliased from the prepended module" do + m = Module.new { def meth; :m end } + c = Class.new { prepend(m); alias_method :alias, :meth } + c.instance_method(:alias).owner.should == c end it "sees an instance of a prepended class as kind of the prepended module" do diff --git a/spec/ruby/core/module/private_spec.rb b/spec/ruby/core/module/private_spec.rb index bf3e86a333..d476c6f54e 100644 --- a/spec/ruby/core/module/private_spec.rb +++ b/spec/ruby/core/module/private_spec.rb @@ -52,46 +52,44 @@ describe "Module#private" do end.should raise_error(NameError) end - ruby_version_is "2.3" do - ruby_bug "#14604", "2.3"..."2.5.1" do - it "only makes the method private in the class it is called on" do - base = Class.new do - def wrapped - 1 - end + ruby_bug "#14604", ""..."2.5.1" do + it "only makes the method private in the class it is called on" do + base = Class.new do + def wrapped + 1 end + end - klass = Class.new(base) do - def wrapped - super + 1 - end - private :wrapped + klass = Class.new(base) do + def wrapped + super + 1 end - - base.new.wrapped.should == 1 - lambda do - klass.new.wrapped - end.should raise_error(NameError) + private :wrapped end - it "continues to allow a prepended module method to call super" do - wrapper = Module.new do - def wrapped - super + 1 - end + base.new.wrapped.should == 1 + lambda do + klass.new.wrapped + end.should raise_error(NameError) + end + + it "continues to allow a prepended module method to call super" do + wrapper = Module.new do + def wrapped + super + 1 end + end - klass = Class.new do - prepend wrapper + klass = Class.new do + prepend wrapper - def wrapped - 1 - end - private :wrapped + def wrapped + 1 end - - klass.new.wrapped.should == 2 + private :wrapped end + + klass.new.wrapped.should == 2 end end end diff --git a/spec/ruby/core/numeric/negative_spec.rb b/spec/ruby/core/numeric/negative_spec.rb index 28591da696..da464a9094 100644 --- a/spec/ruby/core/numeric/negative_spec.rb +++ b/spec/ruby/core/numeric/negative_spec.rb @@ -1,43 +1,41 @@ require_relative '../../spec_helper' require_relative 'fixtures/classes' -ruby_version_is "2.3" do - describe "Numeric#negative?" do - describe "on positive numbers" do - it "returns false" do - 1.negative?.should be_false - 0.1.negative?.should be_false - end +describe "Numeric#negative?" do + describe "on positive numbers" do + it "returns false" do + 1.negative?.should be_false + 0.1.negative?.should be_false end + end - describe "on zero" do - it "returns false" do - 0.negative?.should be_false - 0.0.negative?.should be_false - end + describe "on zero" do + it "returns false" do + 0.negative?.should be_false + 0.0.negative?.should be_false end + end - describe "on negative numbers" do - it "returns true" do - -1.negative?.should be_true - -0.1.negative?.should be_true - end + describe "on negative numbers" do + it "returns true" do + -1.negative?.should be_true + -0.1.negative?.should be_true end end +end - describe "Numeric#negative?" do - before(:each) do - @obj = NumericSpecs::Subclass.new - end +describe "Numeric#negative?" do + before(:each) do + @obj = NumericSpecs::Subclass.new + end - it "returns true if self is less than 0" do - @obj.should_receive(:<).with(0).and_return(true) - @obj.negative?.should == true - end + it "returns true if self is less than 0" do + @obj.should_receive(:<).with(0).and_return(true) + @obj.negative?.should == true + end - it "returns false if self is greater than 0" do - @obj.should_receive(:<).with(0).and_return(false) - @obj.negative?.should == false - end + it "returns false if self is greater than 0" do + @obj.should_receive(:<).with(0).and_return(false) + @obj.negative?.should == false end end diff --git a/spec/ruby/core/numeric/positive_spec.rb b/spec/ruby/core/numeric/positive_spec.rb index 65bb0ea79d..8f98fbfa26 100644 --- a/spec/ruby/core/numeric/positive_spec.rb +++ b/spec/ruby/core/numeric/positive_spec.rb @@ -1,43 +1,41 @@ require_relative '../../spec_helper' require_relative 'fixtures/classes' -ruby_version_is "2.3" do - describe "Numeric#positive?" do - describe "on positive numbers" do - it "returns true" do - 1.positive?.should be_true - 0.1.positive?.should be_true - end +describe "Numeric#positive?" do + describe "on positive numbers" do + it "returns true" do + 1.positive?.should be_true + 0.1.positive?.should be_true end + end - describe "on zero" do - it "returns false" do - 0.positive?.should be_false - 0.0.positive?.should be_false - end + describe "on zero" do + it "returns false" do + 0.positive?.should be_false + 0.0.positive?.should be_false end + end - describe "on negative numbers" do - it "returns false" do - -1.positive?.should be_false - -0.1.positive?.should be_false - end + describe "on negative numbers" do + it "returns false" do + -1.positive?.should be_false + -0.1.positive?.should be_false end end +end - describe "Numeric#positive?" do - before(:each) do - @obj = NumericSpecs::Subclass.new - end +describe "Numeric#positive?" do + before(:each) do + @obj = NumericSpecs::Subclass.new + end - it "returns true if self is greater than 0" do - @obj.should_receive(:>).with(0).and_return(true) - @obj.positive?.should == true - end + it "returns true if self is greater than 0" do + @obj.should_receive(:>).with(0).and_return(true) + @obj.positive?.should == true + end - it "returns false if self is less than 0" do - @obj.should_receive(:>).with(0).and_return(false) - @obj.positive?.should == false - end + it "returns false if self is less than 0" do + @obj.should_receive(:>).with(0).and_return(false) + @obj.positive?.should == false end end diff --git a/spec/ruby/core/objectspace/each_object_spec.rb b/spec/ruby/core/objectspace/each_object_spec.rb index 187d2cc3b2..c827867fdc 100644 --- a/spec/ruby/core/objectspace/each_object_spec.rb +++ b/spec/ruby/core/objectspace/each_object_spec.rb @@ -184,18 +184,9 @@ describe "ObjectSpace.each_object" do hidden.should == nil end - ruby_version_is ""..."2.3" do - it "does not walk singleton classes" do - @sclass.should be_kind_of(@meta) - ObjectSpace.each_object(@meta).to_a.should_not include(@sclass) - end - end - - ruby_version_is "2.3" do - it "walks singleton classes" do - @sclass.should be_kind_of(@meta) - ObjectSpace.each_object(@meta).to_a.should include(@sclass) - end + it "walks singleton classes" do + @sclass.should be_kind_of(@meta) + ObjectSpace.each_object(@meta).to_a.should include(@sclass) end end @@ -211,10 +202,8 @@ describe "ObjectSpace.each_object" do expected = [ a, b, c, d ] # singleton classes should be walked only on >= 2.3 - ruby_version_is "2.3" do - expected << c_sclass - c_sclass.should be_kind_of(a.singleton_class) - end + expected << c_sclass + c_sclass.should be_kind_of(a.singleton_class) b.extend Enumerable # included modules should not be walked diff --git a/spec/ruby/core/process/status/exitstatus_spec.rb b/spec/ruby/core/process/status/exitstatus_spec.rb index 9a0be6a08d..cd46b2081f 100644 --- a/spec/ruby/core/process/status/exitstatus_spec.rb +++ b/spec/ruby/core/process/status/exitstatus_spec.rb @@ -1,7 +1,6 @@ require_relative '../../../spec_helper' describe "Process::Status#exitstatus" do - before :each do ruby_exe("exit(42)") end @@ -10,4 +9,17 @@ describe "Process::Status#exitstatus" do $?.exitstatus.should == 42 end + describe "for a child that raised SignalException" do + before :each do + ruby_exe("raise SignalException, 'SIGTERM'") + end + + platform_is_not :windows do + # The exitstatus is not set in these cases. See the termsig_spec + # for info on where the signal number (SIGTERM) is available. + it "returns nil" do + $?.exitstatus.should == nil + end + end + end end diff --git a/spec/ruby/core/process/status/termsig_spec.rb b/spec/ruby/core/process/status/termsig_spec.rb index db0765477d..1482d27146 100644 --- a/spec/ruby/core/process/status/termsig_spec.rb +++ b/spec/ruby/core/process/status/termsig_spec.rb @@ -13,6 +13,18 @@ describe "Process::Status#termsig" do end end + describe "for a child that raised SignalException" do + before :each do + ruby_exe("raise SignalException, 'SIGTERM'") + end + + platform_is_not :windows do + it "returns the signal" do + $?.termsig.should == Signal.list["TERM"] + end + end + end + describe "for a child that was sent a signal" do before :each do diff --git a/spec/ruby/core/random/urandom_spec.rb b/spec/ruby/core/random/urandom_spec.rb index a771445c60..e27f83cdcd 100644 --- a/spec/ruby/core/random/urandom_spec.rb +++ b/spec/ruby/core/random/urandom_spec.rb @@ -2,7 +2,7 @@ require_relative '../../spec_helper' require_relative 'shared/urandom' -ruby_version_is "2.3"..."2.5" do +ruby_version_is ""..."2.5" do describe "Random.raw_seed" do it_behaves_like :random_urandom, :raw_seed end diff --git a/spec/ruby/core/signal/signame_spec.rb b/spec/ruby/core/signal/signame_spec.rb index d94a8592bd..71b69b301a 100644 --- a/spec/ruby/core/signal/signame_spec.rb +++ b/spec/ruby/core/signal/signame_spec.rb @@ -5,16 +5,8 @@ describe "Signal.signame" do Signal.signame(0).should == "EXIT" end - ruby_version_is "2.0"..."2.3" do - it "raises an ArgumentError if the argument is an invalid signal number" do - lambda { Signal.signame(-1) }.should raise_error(ArgumentError) - end - end - - ruby_version_is "2.3" do - it "returns nil if the argument is an invalid signal number" do - Signal.signame(-1).should == nil - end + it "returns nil if the argument is an invalid signal number" do + Signal.signame(-1).should == nil end it "raises a TypeError when the passed argument can't be coerced to Integer" do diff --git a/spec/ruby/core/string/crypt_spec.rb b/spec/ruby/core/string/crypt_spec.rb index 697dfd5190..01d3830892 100644 --- a/spec/ruby/core/string/crypt_spec.rb +++ b/spec/ruby/core/string/crypt_spec.rb @@ -36,10 +36,8 @@ describe "String#crypt" do lambda { "hello".crypt("a\x00") }.should raise_error(ArgumentError) end - ruby_version_is "2.3" do - it "raises an ArgumentError when the string contains NUL character" do - lambda { "poison\0null".crypt("aa") }.should raise_error(ArgumentError) - end + it "raises an ArgumentError when the string contains NUL character" do + lambda { "poison\0null".crypt("aa") }.should raise_error(ArgumentError) end it "calls #to_str to converts the salt arg to a String" do diff --git a/spec/ruby/core/string/new_spec.rb b/spec/ruby/core/string/new_spec.rb index 7d1c361bf8..a65c6da2d1 100644 --- a/spec/ruby/core/string/new_spec.rb +++ b/spec/ruby/core/string/new_spec.rb @@ -7,12 +7,10 @@ describe "String.new" do str.should be_an_instance_of(String) end - ruby_version_is "2.3" do - it "accepts an encoding argument" do - xA4xA2 = [0xA4, 0xA2].pack('CC').force_encoding 'utf-8' - str = String.new(xA4xA2, encoding: 'euc-jp') - str.encoding.should == Encoding::EUC_JP - end + it "accepts an encoding argument" do + xA4xA2 = [0xA4, 0xA2].pack('CC').force_encoding 'utf-8' + str = String.new(xA4xA2, encoding: 'euc-jp') + str.encoding.should == Encoding::EUC_JP end ruby_version_is "2.4" do diff --git a/spec/ruby/core/string/shared/each_line.rb b/spec/ruby/core/string/shared/each_line.rb index dee741e270..19cf5e6d78 100644 --- a/spec/ruby/core/string/shared/each_line.rb +++ b/spec/ruby/core/string/shared/each_line.rb @@ -51,9 +51,8 @@ describe :string_each_line, shared: true do end end -quarantine! do # Currently fails on Travis ruby_version_is '2.5' do - it "yields paragraphs (broken by 2 or more successive newlines) when passed ''" do + it "yields paragraphs (broken by 2 or more successive newlines) when passed '' and replaces multiple newlines with only two ones" do a = [] "hello\nworld\n\n\nand\nuniverse\n\n\n\n\n".send(@method, '') { |s| a << s } a.should == ["hello\nworld\n\n", "and\nuniverse\n\n"] @@ -63,7 +62,6 @@ quarantine! do # Currently fails on Travis a.should == ["hello\nworld\n\n", "and\nuniverse\n\n", "dog"] end end -end describe "uses $/" do before :each do @@ -136,7 +134,7 @@ end ruby_version_is '2.4' do context "when `chomp` keyword argument is passed" do - it "removes new line characters" do + it "removes new line characters when separator is not specified" do a = [] "hello \nworld\n".send(@method, chomp: true) { |s| a << s } a.should == ["hello ", "world"] @@ -145,6 +143,23 @@ end "hello \r\nworld\r\n".send(@method, chomp: true) { |s| a << s } a.should == ["hello ", "world"] end + + it "removes only specified separator" do + a = [] + "hello world".send(@method, ' ', chomp: true) { |s| a << s } + a.should == ["hello", "world"] + end + + # https://bugs.ruby-lang.org/issues/14257 + it "ignores new line characters when separator is specified" do + a = [] + "hello\n world\n".send(@method, ' ', chomp: true) { |s| a << s } + a.should == ["hello\n", "world\n"] + + a = [] + "hello\r\n world\r\n".send(@method, ' ', chomp: true) { |s| a << s } + a.should == ["hello\r\n", "world\r\n"] + end end end end diff --git a/spec/ruby/core/string/uminus_spec.rb b/spec/ruby/core/string/uminus_spec.rb index a2b6fad098..f79683cb74 100644 --- a/spec/ruby/core/string/uminus_spec.rb +++ b/spec/ruby/core/string/uminus_spec.rb @@ -1,46 +1,44 @@ require_relative '../../spec_helper' -ruby_version_is "2.3" do - describe 'String#-@' do - it 'returns self if the String is frozen' do - input = 'foo'.freeze - output = -input - - output.equal?(input).should == true - output.frozen?.should == true - end +describe 'String#-@' do + it 'returns self if the String is frozen' do + input = 'foo'.freeze + output = -input - it 'returns a frozen copy if the String is not frozen' do - input = 'foo' - output = -input + output.equal?(input).should == true + output.frozen?.should == true + end - output.frozen?.should == true - output.should == 'foo' - end + it 'returns a frozen copy if the String is not frozen' do + input = 'foo' + output = -input - ruby_version_is "2.5" do - it "returns the same object for equal unfrozen strings" do - origin = "this is a string" - dynamic = %w(this is a string).join(' ') + output.frozen?.should == true + output.should == 'foo' + end - origin.should_not equal(dynamic) - (-origin).should equal(-dynamic) - end + ruby_version_is "2.5" do + it "returns the same object for equal unfrozen strings" do + origin = "this is a string" + dynamic = %w(this is a string).join(' ') - it "returns the same object when it's called on the same String literal" do - (-"unfrozen string").should equal(-"unfrozen string") - (-"unfrozen string").should_not equal(-"another unfrozen string") - end + origin.should_not equal(dynamic) + (-origin).should equal(-dynamic) + end + + it "returns the same object when it's called on the same String literal" do + (-"unfrozen string").should equal(-"unfrozen string") + (-"unfrozen string").should_not equal(-"another unfrozen string") + end - it "is an identity function if the string is frozen" do - dynamic = %w(this string is frozen).join(' ').freeze + it "is an identity function if the string is frozen" do + dynamic = %w(this string is frozen).join(' ').freeze - (-dynamic).should equal(dynamic) + (-dynamic).should equal(dynamic) - dynamic.should_not equal("this string is frozen".freeze) - (-dynamic).should_not equal("this string is frozen".freeze) - (-dynamic).should_not equal(-"this string is frozen".freeze) - end + dynamic.should_not equal("this string is frozen".freeze) + (-dynamic).should_not equal("this string is frozen".freeze) + (-dynamic).should_not equal(-"this string is frozen".freeze) end end end diff --git a/spec/ruby/core/string/unpack/j_spec.rb b/spec/ruby/core/string/unpack/j_spec.rb index 8f4213bd97..3c2baad642 100644 --- a/spec/ruby/core/string/unpack/j_spec.rb +++ b/spec/ruby/core/string/unpack/j_spec.rb @@ -3,272 +3,270 @@ require_relative '../fixtures/classes' require_relative 'shared/basic' require_relative 'shared/integer' -ruby_version_is '2.3' do - platform_is pointer_size: 64 do - little_endian do - describe "String#unpack with format 'J'" do - describe "with modifier '_'" do - it_behaves_like :string_unpack_64bit_le, 'J_' - it_behaves_like :string_unpack_64bit_le_unsigned, 'J_' - end - - describe "with modifier '!'" do - it_behaves_like :string_unpack_64bit_le, 'J!' - it_behaves_like :string_unpack_64bit_le_unsigned, 'J!' - end +platform_is pointer_size: 64 do + little_endian do + describe "String#unpack with format 'J'" do + describe "with modifier '_'" do + it_behaves_like :string_unpack_64bit_le, 'J_' + it_behaves_like :string_unpack_64bit_le_unsigned, 'J_' end - describe "String#unpack with format 'j'" do - describe "with modifier '_'" do - it_behaves_like :string_unpack_64bit_le, 'j_' - it_behaves_like :string_unpack_64bit_le_signed, 'j_' - end - - describe "with modifier '!'" do - it_behaves_like :string_unpack_64bit_le, 'j!' - it_behaves_like :string_unpack_64bit_le_signed, 'j!' - end + describe "with modifier '!'" do + it_behaves_like :string_unpack_64bit_le, 'J!' + it_behaves_like :string_unpack_64bit_le_unsigned, 'J!' end end - big_endian do - describe "String#unpack with format 'J'" do - describe "with modifier '_'" do - it_behaves_like :string_unpack_64bit_be, 'J_' - it_behaves_like :string_unpack_64bit_be_unsigned, 'J_' - end - - describe "with modifier '!'" do - it_behaves_like :string_unpack_64bit_be, 'J!' - it_behaves_like :string_unpack_64bit_be_unsigned, 'J!' - end + describe "String#unpack with format 'j'" do + describe "with modifier '_'" do + it_behaves_like :string_unpack_64bit_le, 'j_' + it_behaves_like :string_unpack_64bit_le_signed, 'j_' end - describe "String#unpack with format 'j'" do - describe "with modifier '_'" do - it_behaves_like :string_unpack_64bit_be, 'j_' - it_behaves_like :string_unpack_64bit_be_signed, 'j_' - end - - describe "with modifier '!'" do - it_behaves_like :string_unpack_64bit_be, 'j!' - it_behaves_like :string_unpack_64bit_be_signed, 'j!' - end + describe "with modifier '!'" do + it_behaves_like :string_unpack_64bit_le, 'j!' + it_behaves_like :string_unpack_64bit_le_signed, 'j!' end end + end + big_endian do describe "String#unpack with format 'J'" do - describe "with modifier '<'" do - it_behaves_like :string_unpack_64bit_le, 'J<' - it_behaves_like :string_unpack_64bit_le_unsigned, 'J<' - end - - describe "with modifier '>'" do - it_behaves_like :string_unpack_64bit_be, 'J>' - it_behaves_like :string_unpack_64bit_be_unsigned, 'J>' + describe "with modifier '_'" do + it_behaves_like :string_unpack_64bit_be, 'J_' + it_behaves_like :string_unpack_64bit_be_unsigned, 'J_' end - describe "with modifier '<' and '_'" do - it_behaves_like :string_unpack_64bit_le, 'J<_' - it_behaves_like :string_unpack_64bit_le, 'J_<' - it_behaves_like :string_unpack_64bit_le_unsigned, 'J<_' - it_behaves_like :string_unpack_64bit_le_unsigned, 'J_<' - end - - describe "with modifier '<' and '!'" do - it_behaves_like :string_unpack_64bit_le, 'J' and '_'" do - it_behaves_like :string_unpack_64bit_be, 'J>_' - it_behaves_like :string_unpack_64bit_be, 'J_>' - it_behaves_like :string_unpack_64bit_be_unsigned, 'J>_' - it_behaves_like :string_unpack_64bit_be_unsigned, 'J_>' + describe "String#unpack with format 'j'" do + describe "with modifier '_'" do + it_behaves_like :string_unpack_64bit_be, 'j_' + it_behaves_like :string_unpack_64bit_be_signed, 'j_' end - describe "with modifier '>' and '!'" do - it_behaves_like :string_unpack_64bit_be, 'J>!' - it_behaves_like :string_unpack_64bit_be, 'J!>' - it_behaves_like :string_unpack_64bit_be_unsigned, 'J>!' - it_behaves_like :string_unpack_64bit_be_unsigned, 'J!>' + describe "with modifier '!'" do + it_behaves_like :string_unpack_64bit_be, 'j!' + it_behaves_like :string_unpack_64bit_be_signed, 'j!' end end + end - describe "String#unpack with format 'j'" do - describe "with modifier '<'" do - it_behaves_like :string_unpack_64bit_le, 'j<' - it_behaves_like :string_unpack_64bit_le_signed, 'j<' - end + describe "String#unpack with format 'J'" do + describe "with modifier '<'" do + it_behaves_like :string_unpack_64bit_le, 'J<' + it_behaves_like :string_unpack_64bit_le_unsigned, 'J<' + end - describe "with modifier '>'" do - it_behaves_like :string_unpack_64bit_be, 'j>' - it_behaves_like :string_unpack_64bit_be_signed, 'j>' - end + describe "with modifier '>'" do + it_behaves_like :string_unpack_64bit_be, 'J>' + it_behaves_like :string_unpack_64bit_be_unsigned, 'J>' + end - describe "with modifier '<' and '_'" do - it_behaves_like :string_unpack_64bit_le, 'j<_' - it_behaves_like :string_unpack_64bit_le, 'j_<' - it_behaves_like :string_unpack_64bit_le_signed, 'j<_' - it_behaves_like :string_unpack_64bit_le_signed, 'j_<' - end + describe "with modifier '<' and '_'" do + it_behaves_like :string_unpack_64bit_le, 'J<_' + it_behaves_like :string_unpack_64bit_le, 'J_<' + it_behaves_like :string_unpack_64bit_le_unsigned, 'J<_' + it_behaves_like :string_unpack_64bit_le_unsigned, 'J_<' + end - describe "with modifier '<' and '!'" do - it_behaves_like :string_unpack_64bit_le, 'j' and '_'" do - it_behaves_like :string_unpack_64bit_be, 'j>_' - it_behaves_like :string_unpack_64bit_be, 'j_>' - it_behaves_like :string_unpack_64bit_be_signed, 'j>_' - it_behaves_like :string_unpack_64bit_be_signed, 'j_>' - end + describe "with modifier '>' and '_'" do + it_behaves_like :string_unpack_64bit_be, 'J>_' + it_behaves_like :string_unpack_64bit_be, 'J_>' + it_behaves_like :string_unpack_64bit_be_unsigned, 'J>_' + it_behaves_like :string_unpack_64bit_be_unsigned, 'J_>' + end - describe "with modifier '>' and '!'" do - it_behaves_like :string_unpack_64bit_be, 'j>!' - it_behaves_like :string_unpack_64bit_be, 'j!>' - it_behaves_like :string_unpack_64bit_be_signed, 'j>!' - it_behaves_like :string_unpack_64bit_be_signed, 'j!>' - end + describe "with modifier '>' and '!'" do + it_behaves_like :string_unpack_64bit_be, 'J>!' + it_behaves_like :string_unpack_64bit_be, 'J!>' + it_behaves_like :string_unpack_64bit_be_unsigned, 'J>!' + it_behaves_like :string_unpack_64bit_be_unsigned, 'J!>' end end - platform_is pointer_size: 32 do - little_endian do - describe "String#unpack with format 'J'" do - describe "with modifier '_'" do - it_behaves_like :string_unpack_32bit_le, 'J_' - it_behaves_like :string_unpack_32bit_le_unsigned, 'J_' - end - - describe "with modifier '!'" do - it_behaves_like :string_unpack_32bit_le, 'J!' - it_behaves_like :string_unpack_32bit_le_unsigned, 'J!' - end - end - - describe "String#unpack with format 'j'" do - describe "with modifier '_'" do - it_behaves_like :string_unpack_32bit_le, 'j_' - it_behaves_like :string_unpack_32bit_le_signed, 'j_' - end + describe "String#unpack with format 'j'" do + describe "with modifier '<'" do + it_behaves_like :string_unpack_64bit_le, 'j<' + it_behaves_like :string_unpack_64bit_le_signed, 'j<' + end - describe "with modifier '!'" do - it_behaves_like :string_unpack_32bit_le, 'j!' - it_behaves_like :string_unpack_32bit_le_signed, 'j!' - end - end + describe "with modifier '>'" do + it_behaves_like :string_unpack_64bit_be, 'j>' + it_behaves_like :string_unpack_64bit_be_signed, 'j>' end - big_endian do - describe "String#unpack with format 'J'" do - describe "with modifier '_'" do - it_behaves_like :string_unpack_32bit_be, 'J_' - it_behaves_like :string_unpack_32bit_be_unsigned, 'J_' - end + describe "with modifier '<' and '_'" do + it_behaves_like :string_unpack_64bit_le, 'j<_' + it_behaves_like :string_unpack_64bit_le, 'j_<' + it_behaves_like :string_unpack_64bit_le_signed, 'j<_' + it_behaves_like :string_unpack_64bit_le_signed, 'j_<' + end - describe "with modifier '!'" do - it_behaves_like :string_unpack_32bit_be, 'J!' - it_behaves_like :string_unpack_32bit_be_unsigned, 'J!' - end - end + describe "with modifier '<' and '!'" do + it_behaves_like :string_unpack_64bit_le, 'j' and '_'" do + it_behaves_like :string_unpack_64bit_be, 'j>_' + it_behaves_like :string_unpack_64bit_be, 'j_>' + it_behaves_like :string_unpack_64bit_be_signed, 'j>_' + it_behaves_like :string_unpack_64bit_be_signed, 'j_>' + end - describe "with modifier '!'" do - it_behaves_like :string_unpack_32bit_be, 'j!' - it_behaves_like :string_unpack_32bit_be_signed, 'j!' - end - end + describe "with modifier '>' and '!'" do + it_behaves_like :string_unpack_64bit_be, 'j>!' + it_behaves_like :string_unpack_64bit_be, 'j!>' + it_behaves_like :string_unpack_64bit_be_signed, 'j>!' + it_behaves_like :string_unpack_64bit_be_signed, 'j!>' end + end +end +platform_is pointer_size: 32 do + little_endian do describe "String#unpack with format 'J'" do - describe "with modifier '<'" do - it_behaves_like :string_unpack_32bit_le, 'J<' - it_behaves_like :string_unpack_32bit_le_unsigned, 'J<' + describe "with modifier '_'" do + it_behaves_like :string_unpack_32bit_le, 'J_' + it_behaves_like :string_unpack_32bit_le_unsigned, 'J_' end - describe "with modifier '>'" do - it_behaves_like :string_unpack_32bit_be, 'J>' - it_behaves_like :string_unpack_32bit_be_unsigned, 'J>' + describe "with modifier '!'" do + it_behaves_like :string_unpack_32bit_le, 'J!' + it_behaves_like :string_unpack_32bit_le_unsigned, 'J!' end + end - describe "with modifier '<' and '_'" do - it_behaves_like :string_unpack_32bit_le, 'J<_' - it_behaves_like :string_unpack_32bit_le, 'J_<' - it_behaves_like :string_unpack_32bit_le_unsigned, 'J<_' - it_behaves_like :string_unpack_32bit_le_unsigned, 'J_<' + describe "String#unpack with format 'j'" do + describe "with modifier '_'" do + it_behaves_like :string_unpack_32bit_le, 'j_' + it_behaves_like :string_unpack_32bit_le_signed, 'j_' end - describe "with modifier '<' and '!'" do - it_behaves_like :string_unpack_32bit_le, 'J' and '_'" do - it_behaves_like :string_unpack_32bit_be, 'J>_' - it_behaves_like :string_unpack_32bit_be, 'J_>' - it_behaves_like :string_unpack_32bit_be_unsigned, 'J>_' - it_behaves_like :string_unpack_32bit_be_unsigned, 'J_>' + big_endian do + describe "String#unpack with format 'J'" do + describe "with modifier '_'" do + it_behaves_like :string_unpack_32bit_be, 'J_' + it_behaves_like :string_unpack_32bit_be_unsigned, 'J_' end - describe "with modifier '>' and '!'" do - it_behaves_like :string_unpack_32bit_be, 'J>!' - it_behaves_like :string_unpack_32bit_be, 'J!>' - it_behaves_like :string_unpack_32bit_be_unsigned, 'J>!' - it_behaves_like :string_unpack_32bit_be_unsigned, 'J!>' + describe "with modifier '!'" do + it_behaves_like :string_unpack_32bit_be, 'J!' + it_behaves_like :string_unpack_32bit_be_unsigned, 'J!' end end describe "String#unpack with format 'j'" do - describe "with modifier '<'" do - it_behaves_like :string_unpack_32bit_le, 'j<' - it_behaves_like :string_unpack_32bit_le_signed, 'j<' + describe "with modifier '_'" do + it_behaves_like :string_unpack_32bit_be, 'j_' + it_behaves_like :string_unpack_32bit_be_signed, 'j_' end - describe "with modifier '>'" do - it_behaves_like :string_unpack_32bit_be, 'j>' - it_behaves_like :string_unpack_32bit_be_signed, 'j>' + describe "with modifier '!'" do + it_behaves_like :string_unpack_32bit_be, 'j!' + it_behaves_like :string_unpack_32bit_be_signed, 'j!' end + end + end - describe "with modifier '<' and '_'" do - it_behaves_like :string_unpack_32bit_le, 'j<_' - it_behaves_like :string_unpack_32bit_le, 'j_<' - it_behaves_like :string_unpack_32bit_le_signed, 'j<_' - it_behaves_like :string_unpack_32bit_le_signed, 'j_<' - end + describe "String#unpack with format 'J'" do + describe "with modifier '<'" do + it_behaves_like :string_unpack_32bit_le, 'J<' + it_behaves_like :string_unpack_32bit_le_unsigned, 'J<' + end - describe "with modifier '<' and '!'" do - it_behaves_like :string_unpack_32bit_le, 'j'" do + it_behaves_like :string_unpack_32bit_be, 'J>' + it_behaves_like :string_unpack_32bit_be_unsigned, 'J>' + end - describe "with modifier '>' and '_'" do - it_behaves_like :string_unpack_32bit_be, 'j>_' - it_behaves_like :string_unpack_32bit_be, 'j_>' - it_behaves_like :string_unpack_32bit_be_signed, 'j>_' - it_behaves_like :string_unpack_32bit_be_signed, 'j_>' - end + describe "with modifier '<' and '_'" do + it_behaves_like :string_unpack_32bit_le, 'J<_' + it_behaves_like :string_unpack_32bit_le, 'J_<' + it_behaves_like :string_unpack_32bit_le_unsigned, 'J<_' + it_behaves_like :string_unpack_32bit_le_unsigned, 'J_<' + end - describe "with modifier '>' and '!'" do - it_behaves_like :string_unpack_32bit_be, 'j>!' - it_behaves_like :string_unpack_32bit_be, 'j!>' - it_behaves_like :string_unpack_32bit_be_signed, 'j>!' - it_behaves_like :string_unpack_32bit_be_signed, 'j!>' - end + describe "with modifier '<' and '!'" do + it_behaves_like :string_unpack_32bit_le, 'J' and '_'" do + it_behaves_like :string_unpack_32bit_be, 'J>_' + it_behaves_like :string_unpack_32bit_be, 'J_>' + it_behaves_like :string_unpack_32bit_be_unsigned, 'J>_' + it_behaves_like :string_unpack_32bit_be_unsigned, 'J_>' + end + + describe "with modifier '>' and '!'" do + it_behaves_like :string_unpack_32bit_be, 'J>!' + it_behaves_like :string_unpack_32bit_be, 'J!>' + it_behaves_like :string_unpack_32bit_be_unsigned, 'J>!' + it_behaves_like :string_unpack_32bit_be_unsigned, 'J!>' + end + end + + describe "String#unpack with format 'j'" do + describe "with modifier '<'" do + it_behaves_like :string_unpack_32bit_le, 'j<' + it_behaves_like :string_unpack_32bit_le_signed, 'j<' + end + + describe "with modifier '>'" do + it_behaves_like :string_unpack_32bit_be, 'j>' + it_behaves_like :string_unpack_32bit_be_signed, 'j>' + end + + describe "with modifier '<' and '_'" do + it_behaves_like :string_unpack_32bit_le, 'j<_' + it_behaves_like :string_unpack_32bit_le, 'j_<' + it_behaves_like :string_unpack_32bit_le_signed, 'j<_' + it_behaves_like :string_unpack_32bit_le_signed, 'j_<' + end + + describe "with modifier '<' and '!'" do + it_behaves_like :string_unpack_32bit_le, 'j' and '_'" do + it_behaves_like :string_unpack_32bit_be, 'j>_' + it_behaves_like :string_unpack_32bit_be, 'j_>' + it_behaves_like :string_unpack_32bit_be_signed, 'j>_' + it_behaves_like :string_unpack_32bit_be_signed, 'j_>' + end + + describe "with modifier '>' and '!'" do + it_behaves_like :string_unpack_32bit_be, 'j>!' + it_behaves_like :string_unpack_32bit_be, 'j!>' + it_behaves_like :string_unpack_32bit_be_signed, 'j>!' + it_behaves_like :string_unpack_32bit_be_signed, 'j!>' end end end diff --git a/spec/ruby/core/string/uplus_spec.rb b/spec/ruby/core/string/uplus_spec.rb index 6c6792590e..a7402b4549 100644 --- a/spec/ruby/core/string/uplus_spec.rb +++ b/spec/ruby/core/string/uplus_spec.rb @@ -1,24 +1,22 @@ require_relative '../../spec_helper' -ruby_version_is "2.3" do - describe 'String#+@' do - it 'returns an unfrozen copy of a frozen String' do - input = 'foo'.freeze - output = +input +describe 'String#+@' do + it 'returns an unfrozen copy of a frozen String' do + input = 'foo'.freeze + output = +input - output.frozen?.should == false - output.should == 'foo' - end + output.frozen?.should == false + output.should == 'foo' + end - it 'returns self if the String is not frozen' do - input = 'foo' - output = +input + it 'returns self if the String is not frozen' do + input = 'foo' + output = +input - output.equal?(input).should == true - end + output.equal?(input).should == true + end - it 'returns mutable copy despite freeze-magic-comment in file' do - ruby_exe(fixture(__FILE__, "freeze_magic_comment.rb")).should == 'mutable' - end + it 'returns mutable copy despite freeze-magic-comment in file' do + ruby_exe(fixture(__FILE__, "freeze_magic_comment.rb")).should == 'mutable' end end diff --git a/spec/ruby/core/struct/dig_spec.rb b/spec/ruby/core/struct/dig_spec.rb index f51147a91b..c7c979fabe 100644 --- a/spec/ruby/core/struct/dig_spec.rb +++ b/spec/ruby/core/struct/dig_spec.rb @@ -1,44 +1,42 @@ require_relative '../../spec_helper' -ruby_version_is "2.3" do - describe "Struct#dig" do - before(:each) do - @klass = Struct.new(:a) - @instance = @klass.new(@klass.new({ b: [1, 2, 3] })) - end - - it "returns the nested value specified by the sequence of keys" do - @instance.dig(:a, :a).should == { b: [1, 2, 3] } - end +describe "Struct#dig" do + before(:each) do + @klass = Struct.new(:a) + @instance = @klass.new(@klass.new({ b: [1, 2, 3] })) + end - it "returns the nested value specified if the sequence includes an index" do - @instance.dig(:a, :a, :b, 0).should == 1 - end + it "returns the nested value specified by the sequence of keys" do + @instance.dig(:a, :a).should == { b: [1, 2, 3] } + end - it "returns nil if any intermediate step is nil" do - @instance.dig(:b, 0).should == nil - end + it "returns the nested value specified if the sequence includes an index" do + @instance.dig(:a, :a, :b, 0).should == 1 + end - it "raises a TypeError if any intermediate step does not respond to #dig" do - instance = @klass.new(1) - lambda { - instance.dig(:a, 3) - }.should raise_error(TypeError) - end + it "returns nil if any intermediate step is nil" do + @instance.dig(:b, 0).should == nil + end - it "raises an ArgumentError if no arguments provided" do - lambda { @instance.dig }.should raise_error(ArgumentError) - end + it "raises a TypeError if any intermediate step does not respond to #dig" do + instance = @klass.new(1) + lambda { + instance.dig(:a, 3) + }.should raise_error(TypeError) + end - it "calls #dig on any intermediate step with the rest of the sequence as arguments" do - obj = Object.new - instance = @klass.new(obj) + it "raises an ArgumentError if no arguments provided" do + lambda { @instance.dig }.should raise_error(ArgumentError) + end - def obj.dig(*args) - {dug: args} - end + it "calls #dig on any intermediate step with the rest of the sequence as arguments" do + obj = Object.new + instance = @klass.new(obj) - instance.dig(:a, :bar, :baz).should == { dug: [:bar, :baz] } + def obj.dig(*args) + {dug: args} end + + instance.dig(:a, :bar, :baz).should == { dug: [:bar, :baz] } end end diff --git a/spec/ruby/core/thread/name_spec.rb b/spec/ruby/core/thread/name_spec.rb index 503a909158..adb2d08fae 100644 --- a/spec/ruby/core/thread/name_spec.rb +++ b/spec/ruby/core/thread/name_spec.rb @@ -1,56 +1,54 @@ require_relative '../../spec_helper' -ruby_version_is '2.3' do - describe "Thread#name" do - before :each do - @thread = Thread.new {} - end - - after :each do - @thread.join - end - - it "is nil initially" do - @thread.name.should == nil - end - - it "returns the thread name" do - @thread.name = "thread_name" - @thread.name.should == "thread_name" - end - end - - describe "Thread#name=" do - before :each do - @thread = Thread.new {} - end - - after :each do - @thread.join - end - - it "can be set to a String" do - @thread.name = "new thread name" - @thread.name.should == "new thread name" - end - - it "raises an ArgumentError if the name includes a null byte" do - lambda { - @thread.name = "new thread\0name" - }.should raise_error(ArgumentError) - end - - it "can be reset to nil" do - @thread.name = nil - @thread.name.should == nil - end - - it "calls #to_str to convert name to String" do - name = mock("Thread#name") - name.should_receive(:to_str).and_return("a thread name") - - @thread.name = name - @thread.name.should == "a thread name" - end +describe "Thread#name" do + before :each do + @thread = Thread.new {} + end + + after :each do + @thread.join + end + + it "is nil initially" do + @thread.name.should == nil + end + + it "returns the thread name" do + @thread.name = "thread_name" + @thread.name.should == "thread_name" + end +end + +describe "Thread#name=" do + before :each do + @thread = Thread.new {} + end + + after :each do + @thread.join + end + + it "can be set to a String" do + @thread.name = "new thread name" + @thread.name.should == "new thread name" + end + + it "raises an ArgumentError if the name includes a null byte" do + lambda { + @thread.name = "new thread\0name" + }.should raise_error(ArgumentError) + end + + it "can be reset to nil" do + @thread.name = nil + @thread.name.should == nil + end + + it "calls #to_str to convert name to String" do + name = mock("Thread#name") + name.should_receive(:to_str).and_return("a thread name") + + @thread.name = name + @thread.name.should == "a thread name" end end diff --git a/spec/ruby/core/time/at_spec.rb b/spec/ruby/core/time/at_spec.rb index 8363a0bc70..7c66104156 100644 --- a/spec/ruby/core/time/at_spec.rb +++ b/spec/ruby/core/time/at_spec.rb @@ -34,7 +34,7 @@ describe "Time.at" do describe "passed BigDecimal" do it "doesn't round input value" do require 'bigdecimal' - Time.at(BigDecimal.new('1.1')).to_f.should == 1.1 + Time.at(BigDecimal('1.1')).to_f.should == 1.1 end end end diff --git a/spec/ruby/core/tracepoint/disable_spec.rb b/spec/ruby/core/tracepoint/disable_spec.rb index 1ee3125351..e936d3498d 100644 --- a/spec/ruby/core/tracepoint/disable_spec.rb +++ b/spec/ruby/core/tracepoint/disable_spec.rb @@ -55,7 +55,7 @@ describe 'TracePoint#disable' do end end - ruby_bug "#14057", "2.0"..."2.5" do + ruby_bug "#14057", ""..."2.5" do it 'can accept param within a block but it should not yield arguments' do event_name = nil trace = TracePoint.new(:line) {} diff --git a/spec/ruby/core/tracepoint/enable_spec.rb b/spec/ruby/core/tracepoint/enable_spec.rb index 769c1b643a..b1a8628896 100644 --- a/spec/ruby/core/tracepoint/enable_spec.rb +++ b/spec/ruby/core/tracepoint/enable_spec.rb @@ -62,7 +62,7 @@ describe 'TracePoint#enable' do end.enable { event_name.should equal(:line) } end - ruby_bug "#14057", "2.0"..."2.5" do + ruby_bug "#14057", ""..."2.5" do it 'can accept arguments within a block but it should not yield arguments' do event_name = nil trace = TracePoint.new(:line) { |tp| event_name = tp.event } diff --git a/spec/ruby/core/tracepoint/new_spec.rb b/spec/ruby/core/tracepoint/new_spec.rb index ec6f673745..77675561f6 100644 --- a/spec/ruby/core/tracepoint/new_spec.rb +++ b/spec/ruby/core/tracepoint/new_spec.rb @@ -56,7 +56,7 @@ describe 'TracePoint.new' do -> { TracePoint.new(o) {}}.should raise_error(TypeError) end - ruby_bug "#140740", "2.0"..."2.5" do + ruby_bug "#140740", ""..."2.5" do it 'expects to be called with a block' do -> { TracePoint.new(:line) }.should raise_error(ArgumentError) end diff --git a/spec/ruby/language/block_spec.rb b/spec/ruby/language/block_spec.rb index bd3c14d487..27fcb4919b 100644 --- a/spec/ruby/language/block_spec.rb +++ b/spec/ruby/language/block_spec.rb @@ -62,14 +62,12 @@ describe "A block yielded a single" do result.should == [{"a" => 1}, b: 2] end - ruby_version_is "2.2.1" do # SEGV on MRI 2.2.0 - it "calls #to_hash on the argument but does not use the result when no keywords are present" do - obj = mock("coerce block keyword arguments") - obj.should_receive(:to_hash).and_return({"a" => 1, "b" => 2}) + it "calls #to_hash on the argument but does not use the result when no keywords are present" do + obj = mock("coerce block keyword arguments") + obj.should_receive(:to_hash).and_return({"a" => 1, "b" => 2}) - result = m([obj]) { |a=nil, **b| [a, b] } - result.should == [{"a" => 1, "b" => 2}, {}] - end + result = m([obj]) { |a=nil, **b| [a, b] } + result.should == [{"a" => 1, "b" => 2}, {}] end it "assigns non-symbol keys to non-keyword arguments" do diff --git a/spec/ruby/language/class_spec.rb b/spec/ruby/language/class_spec.rb index c8eba18d80..a91b165ffe 100644 --- a/spec/ruby/language/class_spec.rb +++ b/spec/ruby/language/class_spec.rb @@ -13,11 +13,9 @@ describe "The class keyword" do ClassSpecsKeywordWithSemicolon.should be_an_instance_of(Class) end - ruby_version_is "2.3" do - it "does not raise a SyntaxError when opening a class without a semicolon" do - eval "class ClassSpecsKeywordWithoutSemicolon end" - ClassSpecsKeywordWithoutSemicolon.should be_an_instance_of(Class) - end + it "does not raise a SyntaxError when opening a class without a semicolon" do + eval "class ClassSpecsKeywordWithoutSemicolon end" + ClassSpecsKeywordWithoutSemicolon.should be_an_instance_of(Class) end end diff --git a/spec/ruby/language/constants_spec.rb b/spec/ruby/language/constants_spec.rb index e6bb13bed2..4e0df9fd6d 100644 --- a/spec/ruby/language/constants_spec.rb +++ b/spec/ruby/language/constants_spec.rb @@ -404,24 +404,22 @@ describe "Constant resolution within a singleton class (class << obj)" do ConstantSpecs::CS_SINGLETON1.foo.should == 1 end - ruby_version_is "2.3" do - it "uses its own namespace for each object" do - a = ConstantSpecs::CS_SINGLETON2[0].foo - b = ConstantSpecs::CS_SINGLETON2[1].foo - [a, b].should == [1, 2] - end + it "uses its own namespace for each object" do + a = ConstantSpecs::CS_SINGLETON2[0].foo + b = ConstantSpecs::CS_SINGLETON2[1].foo + [a, b].should == [1, 2] + end - it "uses its own namespace for nested modules" do - a = ConstantSpecs::CS_SINGLETON3[0].x - b = ConstantSpecs::CS_SINGLETON3[1].x - a.should_not equal(b) - end + it "uses its own namespace for nested modules" do + a = ConstantSpecs::CS_SINGLETON3[0].x + b = ConstantSpecs::CS_SINGLETON3[1].x + a.should_not equal(b) + end - it "allows nested modules to have proper resolution" do - a = ConstantSpecs::CS_SINGLETON4_CLASSES[0].new - b = ConstantSpecs::CS_SINGLETON4_CLASSES[1].new - [a.foo, b.foo].should == [1, 2] - end + it "allows nested modules to have proper resolution" do + a = ConstantSpecs::CS_SINGLETON4_CLASSES[0].new + b = ConstantSpecs::CS_SINGLETON4_CLASSES[1].new + [a.foo, b.foo].should == [1, 2] end end diff --git a/spec/ruby/language/ensure_spec.rb b/spec/ruby/language/ensure_spec.rb index 2ba12557ef..064627b2f7 100644 --- a/spec/ruby/language/ensure_spec.rb +++ b/spec/ruby/language/ensure_spec.rb @@ -66,6 +66,18 @@ describe "An ensure block inside a begin block" do :ensure end.should == :begin end + + it "sets exception cause if raises exception in block and in ensure" do + -> { + begin + raise "from block" + ensure + raise "from ensure" + end + }.should raise_error(RuntimeError, "from ensure") do |e| + e.cause.message.should == "from block" + end + end end describe "The value of an ensure expression," do @@ -117,6 +129,34 @@ describe "An ensure block inside a method" do it "has an impact on the method's explicit return value" do @obj.explicit_return_in_method_with_ensure.should == :ensure end + + it "has an impact on the method's explicit return value from rescue if returns explicitly" do + @obj.explicit_return_in_rescue_and_explicit_return_in_ensure.should == "returned in ensure" + end + + it "has no impact on the method's explicit return value from rescue if returns implicitly" do + @obj.explicit_return_in_rescue_and_implicit_return_in_ensure.should == "returned in rescue" + end + + it "suppresses exception raised in method if returns value explicitly" do + @obj.raise_and_explicit_return_in_ensure.should == "returned in ensure" + end + + it "suppresses exception raised in rescue if returns value explicitly" do + @obj.raise_in_rescue_and_explicit_return_in_ensure.should == "returned in ensure" + end + + it "overrides exception raised in rescue if raises exception itself" do + -> { + @obj.raise_in_rescue_and_raise_in_ensure + }.should raise_error(RuntimeError, "raised in ensure") + end + + it "suppresses exception raised in method if raises exception itself" do + -> { + @obj.raise_in_method_and_raise_in_ensure + }.should raise_error(RuntimeError, "raised in ensure") + end end describe "An ensure block inside a class" do diff --git a/spec/ruby/language/fixtures/ensure.rb b/spec/ruby/language/fixtures/ensure.rb index d1a9da37b8..6047ac5bc0 100644 --- a/spec/ruby/language/fixtures/ensure.rb +++ b/spec/ruby/language/fixtures/ensure.rb @@ -40,6 +40,50 @@ module EnsureSpec ensure return :ensure end + + def explicit_return_in_rescue_and_explicit_return_in_ensure + raise + rescue + return 2 + ensure + return "returned in ensure" + end + + def explicit_return_in_rescue_and_implicit_return_in_ensure + raise + rescue + return "returned in rescue" + ensure + 3 + end + + def raise_and_explicit_return_in_ensure + raise + ensure + return "returned in ensure" + end + + def raise_in_rescue_and_explicit_return_in_ensure + raise + rescue + raise + ensure + return "returned in ensure" + end + + def raise_in_rescue_and_raise_in_ensure + raise + rescue + raise "raised in rescue" + ensure + raise "raised in ensure" + end + + def raise_in_method_and_raise_in_ensure + raise + ensure + raise "raised in ensure" + end end end diff --git a/spec/ruby/language/fixtures/super.rb b/spec/ruby/language/fixtures/super.rb index 09a454bdf4..e487b15354 100644 --- a/spec/ruby/language/fixtures/super.rb +++ b/spec/ruby/language/fixtures/super.rb @@ -455,6 +455,38 @@ module Super end end + module ZSuperWithRestReassigned + class A + def a(*args) + args + end + end + + class B < A + def a(*args) + args = ["foo"] + + super + end + end + end + + module ZSuperWithRestReassignedWithScalar + class A + def a(*args) + args + end + end + + class B < A + def a(*args) + args = "foo" + + super + end + end + end + module ZSuperWithUnderscores class A def m(*args) diff --git a/spec/ruby/language/heredoc_spec.rb b/spec/ruby/language/heredoc_spec.rb index 1cc836063d..09a04a3cb1 100644 --- a/spec/ruby/language/heredoc_spec.rb +++ b/spec/ruby/language/heredoc_spec.rb @@ -53,35 +53,33 @@ HERE s.should == ' foo bar#{@ip}' + "\n" end - ruby_version_is "2.3" do - it "allows HEREDOC with <<~'identifier', allowing to indent identifier and content" do - require_relative 'fixtures/squiggly_heredoc' - SquigglyHeredocSpecs.message.should == "character density, n.:\n The number of very weird people in the office.\n" - end - - it "trims trailing newline character for blank HEREDOC with <<~'identifier'" do - require_relative 'fixtures/squiggly_heredoc' - SquigglyHeredocSpecs.blank.should == "" - end - - it 'allows HEREDOC with <<~identifier, interpolated' do - require_relative 'fixtures/squiggly_heredoc' - SquigglyHeredocSpecs.unquoted.should == "unquoted interpolated\n" - end - - it 'allows HEREDOC with <<~"identifier", interpolated' do - require_relative 'fixtures/squiggly_heredoc' - SquigglyHeredocSpecs.doublequoted.should == "doublequoted interpolated\n" - end - - it "allows HEREDOC with <<~'identifier', no interpolation" do - require_relative 'fixtures/squiggly_heredoc' - SquigglyHeredocSpecs.singlequoted.should == "singlequoted \#{\"interpolated\"}\n" - end - - it "selects the least-indented line and removes its indentation from all the lines" do - require_relative 'fixtures/squiggly_heredoc' - SquigglyHeredocSpecs.least_indented_on_the_last_line.should == " a\n b\nc\n" - end + it "allows HEREDOC with <<~'identifier', allowing to indent identifier and content" do + require_relative 'fixtures/squiggly_heredoc' + SquigglyHeredocSpecs.message.should == "character density, n.:\n The number of very weird people in the office.\n" + end + + it "trims trailing newline character for blank HEREDOC with <<~'identifier'" do + require_relative 'fixtures/squiggly_heredoc' + SquigglyHeredocSpecs.blank.should == "" + end + + it 'allows HEREDOC with <<~identifier, interpolated' do + require_relative 'fixtures/squiggly_heredoc' + SquigglyHeredocSpecs.unquoted.should == "unquoted interpolated\n" + end + + it 'allows HEREDOC with <<~"identifier", interpolated' do + require_relative 'fixtures/squiggly_heredoc' + SquigglyHeredocSpecs.doublequoted.should == "doublequoted interpolated\n" + end + + it "allows HEREDOC with <<~'identifier', no interpolation" do + require_relative 'fixtures/squiggly_heredoc' + SquigglyHeredocSpecs.singlequoted.should == "singlequoted \#{\"interpolated\"}\n" + end + + it "selects the least-indented line and removes its indentation from all the lines" do + require_relative 'fixtures/squiggly_heredoc' + SquigglyHeredocSpecs.least_indented_on_the_last_line.should == " a\n b\nc\n" end end diff --git a/spec/ruby/language/optional_assignments_spec.rb b/spec/ruby/language/optional_assignments_spec.rb index 5d539cba42..a83c0da272 100644 --- a/spec/ruby/language/optional_assignments_spec.rb +++ b/spec/ruby/language/optional_assignments_spec.rb @@ -181,6 +181,52 @@ describe 'Optional variable assignments' do @a.b.should == 20 end end + + describe 'using a #[]' do + before do + @a = {} + end + + it 'leaves new variable unassigned' do + @a[:k] &&= 10 + + @a.key?(:k).should == false + end + + it 'leaves false' do + @a[:k] = false + @a[:k] &&= 10 + + @a[:k].should == false + end + + it 'leaves nil' do + @a[:k] = nil + @a[:k] &&= 10 + + @a[:k].should == nil + end + + it 'does not evaluate the right side when not needed' do + @a[:k] = nil + @a[:k] &&= raise('should not be executed') + @a[:k].should == nil + end + + it 'does re-assign a variable with a truthy value' do + @a[:k] = 10 + @a[:k] &&= 20 + + @a[:k].should == 20 + end + + it 'does re-assign a variable with a truthy value when using an inline rescue' do + @a[:k] = 10 + @a[:k] &&= 20 rescue 30 + + @a[:k].should == 20 + end + end end describe 'using compunded constants' do diff --git a/spec/ruby/language/predefined/fixtures/toplevel_binding_dynamic.rb b/spec/ruby/language/predefined/fixtures/toplevel_binding_dynamic.rb new file mode 100644 index 0000000000..f7809109fa --- /dev/null +++ b/spec/ruby/language/predefined/fixtures/toplevel_binding_dynamic.rb @@ -0,0 +1,4 @@ +p TOPLEVEL_BINDING.local_variables.sort +TOPLEVEL_BINDING.local_variable_set(:dynamic_set_main, 2) +p TOPLEVEL_BINDING.local_variables.sort +main_script = 3 diff --git a/spec/ruby/language/predefined/fixtures/toplevel_binding_dynamic_required.rb b/spec/ruby/language/predefined/fixtures/toplevel_binding_dynamic_required.rb new file mode 100644 index 0000000000..7ccf329680 --- /dev/null +++ b/spec/ruby/language/predefined/fixtures/toplevel_binding_dynamic_required.rb @@ -0,0 +1,2 @@ +TOPLEVEL_BINDING.local_variable_set(:dynamic_set_required, 1) +p TOPLEVEL_BINDING.local_variables diff --git a/spec/ruby/language/predefined/fixtures/toplevel_binding_id.rb b/spec/ruby/language/predefined/fixtures/toplevel_binding_id.rb new file mode 100644 index 0000000000..3626ea1f10 --- /dev/null +++ b/spec/ruby/language/predefined/fixtures/toplevel_binding_id.rb @@ -0,0 +1,4 @@ +a = TOPLEVEL_BINDING.object_id +require_relative 'toplevel_binding_id_required' +c = eval('TOPLEVEL_BINDING.object_id') +p [a, $b, c].uniq.size diff --git a/spec/ruby/language/predefined/fixtures/toplevel_binding_id_required.rb b/spec/ruby/language/predefined/fixtures/toplevel_binding_id_required.rb new file mode 100644 index 0000000000..b31b6e32a0 --- /dev/null +++ b/spec/ruby/language/predefined/fixtures/toplevel_binding_id_required.rb @@ -0,0 +1 @@ +$b = TOPLEVEL_BINDING.object_id diff --git a/spec/ruby/language/predefined/fixtures/toplevel_binding_required_before.rb b/spec/ruby/language/predefined/fixtures/toplevel_binding_required_before.rb new file mode 100644 index 0000000000..58924a5800 --- /dev/null +++ b/spec/ruby/language/predefined/fixtures/toplevel_binding_required_before.rb @@ -0,0 +1,2 @@ +required = true +p [:required_before, TOPLEVEL_BINDING.local_variables] diff --git a/spec/ruby/language/predefined/fixtures/toplevel_binding_values.rb b/spec/ruby/language/predefined/fixtures/toplevel_binding_values.rb new file mode 100644 index 0000000000..42bd67f347 --- /dev/null +++ b/spec/ruby/language/predefined/fixtures/toplevel_binding_values.rb @@ -0,0 +1,9 @@ +p TOPLEVEL_BINDING.local_variable_get(:a) +p TOPLEVEL_BINDING.local_variable_get(:b) +a = 1 +p TOPLEVEL_BINDING.local_variable_get(:a) +p TOPLEVEL_BINDING.local_variable_get(:b) +b = 2 +a = 3 +p TOPLEVEL_BINDING.local_variable_get(:a) +p TOPLEVEL_BINDING.local_variable_get(:b) diff --git a/spec/ruby/language/predefined/fixtures/toplevel_binding_variables.rb b/spec/ruby/language/predefined/fixtures/toplevel_binding_variables.rb new file mode 100644 index 0000000000..151f4340ef --- /dev/null +++ b/spec/ruby/language/predefined/fixtures/toplevel_binding_variables.rb @@ -0,0 +1,4 @@ +main_script = 1 +require_relative 'toplevel_binding_variables_required' +eval('eval_var = 3') +p TOPLEVEL_BINDING.local_variables diff --git a/spec/ruby/language/predefined/fixtures/toplevel_binding_variables_required.rb b/spec/ruby/language/predefined/fixtures/toplevel_binding_variables_required.rb new file mode 100644 index 0000000000..614547fe16 --- /dev/null +++ b/spec/ruby/language/predefined/fixtures/toplevel_binding_variables_required.rb @@ -0,0 +1,2 @@ +required = 2 +p [:required_after, TOPLEVEL_BINDING.local_variables] diff --git a/spec/ruby/language/predefined/toplevel_binding_spec.rb b/spec/ruby/language/predefined/toplevel_binding_spec.rb new file mode 100644 index 0000000000..69ac28618c --- /dev/null +++ b/spec/ruby/language/predefined/toplevel_binding_spec.rb @@ -0,0 +1,34 @@ +require_relative '../../spec_helper' + +describe "The TOPLEVEL_BINDING constant" do + it "only includes local variables defined in the main script, not in required files or eval" do + binding_toplevel_variables = ruby_exe(fixture(__FILE__, "toplevel_binding_variables.rb")) + binding_toplevel_variables.should == "[:required_after, [:main_script]]\n[:main_script]\n" + end + + it "has no local variables in files required before the main script" do + required = fixture(__FILE__, 'toplevel_binding_required_before.rb') + out = ruby_exe("a=1; p TOPLEVEL_BINDING.local_variables.sort; b=2", options: "-r#{required}") + out.should == "[:required_before, []]\n[:a, :b]\n" + end + + it "merges local variables of the main script with dynamically-defined Binding variables" do + required = fixture(__FILE__, 'toplevel_binding_dynamic_required.rb') + out = ruby_exe(fixture(__FILE__, 'toplevel_binding_dynamic.rb'), options: "-r#{required}") + out.should == < { ScratchPad << :bar; StandardError }.call + end + + ScratchPad.recorded.should == [:foo] + end + + it "suppresses exception from block when raises one from rescue expression" do + -> { + begin + raise "from block" + rescue (raise "from rescue expression") + end + }.should raise_error(RuntimeError, "from rescue expression") do |e| + e.cause.message.should == "from block" + end end it "should splat the handling Error classes" do diff --git a/spec/ruby/language/safe_navigator_spec.rb b/spec/ruby/language/safe_navigator_spec.rb index 5783103e42..46a1a012d1 100644 --- a/spec/ruby/language/safe_navigator_spec.rb +++ b/spec/ruby/language/safe_navigator_spec.rb @@ -1,101 +1,99 @@ require_relative '../spec_helper' -ruby_version_is "2.3" do - describe "Safe navigator" do - it "requires a method name to be provided" do - lambda { eval("obj&. {}") }.should raise_error(SyntaxError) - end +describe "Safe navigator" do + it "requires a method name to be provided" do + lambda { eval("obj&. {}") }.should raise_error(SyntaxError) + end - context "when context is nil" do - it "always returns nil" do - eval("nil&.unknown").should == nil - eval("[][10]&.unknown").should == nil - end + context "when context is nil" do + it "always returns nil" do + eval("nil&.unknown").should == nil + eval("[][10]&.unknown").should == nil + end - it "can be chained" do - eval("nil&.one&.two&.three").should == nil - end + it "can be chained" do + eval("nil&.one&.two&.three").should == nil + end - it "doesn't evaluate arguments" do - obj = Object.new - obj.should_not_receive(:m) - eval("nil&.unknown(obj.m) { obj.m }") - end + it "doesn't evaluate arguments" do + obj = Object.new + obj.should_not_receive(:m) + eval("nil&.unknown(obj.m) { obj.m }") end + end - context "when context is false" do - it "calls the method" do - eval("false&.to_s").should == "false" + context "when context is false" do + it "calls the method" do + eval("false&.to_s").should == "false" - lambda { eval("false&.unknown") }.should raise_error(NoMethodError) - end + lambda { eval("false&.unknown") }.should raise_error(NoMethodError) end + end - context "when context is truthy" do - it "calls the method" do - eval("1&.to_s").should == "1" + context "when context is truthy" do + it "calls the method" do + eval("1&.to_s").should == "1" - lambda { eval("1&.unknown") }.should raise_error(NoMethodError) - end + lambda { eval("1&.unknown") }.should raise_error(NoMethodError) end + end - it "takes a list of arguments" do - eval("[1,2,3]&.first(2)").should == [1,2] - end + it "takes a list of arguments" do + eval("[1,2,3]&.first(2)").should == [1,2] + end - it "takes a block" do - eval("[1,2]&.map { |i| i * 2 }").should == [2, 4] - end + it "takes a block" do + eval("[1,2]&.map { |i| i * 2 }").should == [2, 4] + end - it "allows assignment methods" do - klass = Class.new do - attr_reader :foo - def foo=(val) - @foo = val - 42 - end + it "allows assignment methods" do + klass = Class.new do + attr_reader :foo + def foo=(val) + @foo = val + 42 end - obj = klass.new + end + obj = klass.new - eval("obj&.foo = 3").should == 3 - obj.foo.should == 3 + eval("obj&.foo = 3").should == 3 + obj.foo.should == 3 - obj = nil - eval("obj&.foo = 3").should == nil - end + obj = nil + eval("obj&.foo = 3").should == nil + end - it "allows assignment operators" do - klass = Class.new do - attr_accessor :m + it "allows assignment operators" do + klass = Class.new do + attr_accessor :m - def initialize - @m = 0 - end + def initialize + @m = 0 end + end - obj = klass.new + obj = klass.new - eval("obj&.m += 3") - obj.m.should == 3 + eval("obj&.m += 3") + obj.m.should == 3 - obj = nil - eval("obj&.m += 3").should == nil - end + obj = nil + eval("obj&.m += 3").should == nil + end - it "does not call the operator method lazily with an assignment operator" do - klass = Class.new do - attr_writer :foo - def foo - nil - end + it "does not call the operator method lazily with an assignment operator" do + klass = Class.new do + attr_writer :foo + def foo + nil end - obj = klass.new - - lambda { - eval("obj&.foo += 3") - }.should raise_error(NoMethodError) { |e| - e.name.should == :+ - } end + obj = klass.new + + lambda { + eval("obj&.foo += 3") + }.should raise_error(NoMethodError) { |e| + e.name.should == :+ + } end end diff --git a/spec/ruby/language/string_spec.rb b/spec/ruby/language/string_spec.rb index 98b8638f08..b198979d87 100644 --- a/spec/ruby/language/string_spec.rb +++ b/spec/ruby/language/string_spec.rb @@ -233,27 +233,25 @@ describe "Ruby String literals" do long_string_literals.should == "Beautiful is better than ugly.Explicit is better than implicit." end - ruby_version_is "2.3" do - describe "with a magic frozen comment" do - it "produce the same object each time" do - ruby_exe(fixture(__FILE__, "freeze_magic_comment_one_literal.rb")).chomp.should == "true" - end + describe "with a magic frozen comment" do + it "produce the same object each time" do + ruby_exe(fixture(__FILE__, "freeze_magic_comment_one_literal.rb")).chomp.should == "true" + end - it "produce the same object for literals with the same content" do - ruby_exe(fixture(__FILE__, "freeze_magic_comment_two_literals.rb")).chomp.should == "true" - end + it "produce the same object for literals with the same content" do + ruby_exe(fixture(__FILE__, "freeze_magic_comment_two_literals.rb")).chomp.should == "true" + end - it "produce the same object for literals with the same content in different files" do - ruby_exe(fixture(__FILE__, "freeze_magic_comment_across_files.rb")).chomp.should == "true" - end + it "produce the same object for literals with the same content in different files" do + ruby_exe(fixture(__FILE__, "freeze_magic_comment_across_files.rb")).chomp.should == "true" + end - it "produce different objects for literals with the same content in different files if the other file doesn't have the comment" do - ruby_exe(fixture(__FILE__, "freeze_magic_comment_across_files_no_comment.rb")).chomp.should == "true" - end + it "produce different objects for literals with the same content in different files if the other file doesn't have the comment" do + ruby_exe(fixture(__FILE__, "freeze_magic_comment_across_files_no_comment.rb")).chomp.should == "true" + end - it "produce different objects for literals with the same content in different files if they have different encodings" do - ruby_exe(fixture(__FILE__, "freeze_magic_comment_across_files_diff_enc.rb")).chomp.should == "true" - end + it "produce different objects for literals with the same content in different files if they have different encodings" do + ruby_exe(fixture(__FILE__, "freeze_magic_comment_across_files_diff_enc.rb")).chomp.should == "true" end end diff --git a/spec/ruby/language/super_spec.rb b/spec/ruby/language/super_spec.rb index 936e3164b6..a86fb1df33 100644 --- a/spec/ruby/language/super_spec.rb +++ b/spec/ruby/language/super_spec.rb @@ -191,6 +191,20 @@ describe "The super keyword" do Super::RestArgsWithSuper::B.new.a.should == ["foo"] end + # https://bugs.ruby-lang.org/issues/14279 + it "passes along reassigned rest args" do + Super::ZSuperWithRestReassigned::B.new.a("bar").should == ["foo"] + end + + # Don't run this spec on Appveyor because it uses old Ruby versions + # The specs ends with segfault on old versions so let's just disable it + platform_is_not :windows do + # https://bugs.ruby-lang.org/issues/14279 + it "wraps into array and passes along reassigned rest args with non-array scalar value" do + Super::ZSuperWithRestReassignedWithScalar::B.new.a("bar").should == ["foo"] + end + end + it "invokes methods from a chain of anonymous modules" do Super::AnonymousModuleIncludedTwice.new.a([]).should == ["anon", "anon", "non-anon"] end diff --git a/spec/ruby/language/yield_spec.rb b/spec/ruby/language/yield_spec.rb index a3cf5b20d5..8a2aa81819 100644 --- a/spec/ruby/language/yield_spec.rb +++ b/spec/ruby/language/yield_spec.rb @@ -69,7 +69,7 @@ describe "The yield call" do }.should raise_error(ArgumentError) end - ruby_bug "#12705", "2.2"..."2.5" do + ruby_bug "#12705", ""..."2.5" do it "should not destructure an Array into multiple arguments" do lambda { @y.s([1, 2], &lambda { |a,b| [a,b] }) diff --git a/spec/ruby/library/base64/urlsafe_decode64_spec.rb b/spec/ruby/library/base64/urlsafe_decode64_spec.rb index 3c1e72f961..1b813ee1b9 100644 --- a/spec/ruby/library/base64/urlsafe_decode64_spec.rb +++ b/spec/ruby/library/base64/urlsafe_decode64_spec.rb @@ -13,15 +13,7 @@ describe "Base64#urlsafe_decode64" do decoded.should == '"Being disintegrated makes me ve-ry an-gry!" ' end - ruby_version_is ""..."2.3" do - it "requires padding" do - lambda { Base64.urlsafe_decode64("MQ") }.should raise_error(ArgumentError) - end - end - - ruby_version_is "2.3" do - it "does not require padding" do - Base64.urlsafe_decode64("MQ").should == "1" - end + it "does not require padding" do + Base64.urlsafe_decode64("MQ").should == "1" end end diff --git a/spec/ruby/library/base64/urlsafe_encode64_spec.rb b/spec/ruby/library/base64/urlsafe_encode64_spec.rb index e47a53add8..de1f235cea 100644 --- a/spec/ruby/library/base64/urlsafe_encode64_spec.rb +++ b/spec/ruby/library/base64/urlsafe_encode64_spec.rb @@ -13,10 +13,8 @@ describe "Base64#urlsafe_encode64" do encoded.should == 'IkJlaW5nIGRpc2ludGVncmF0ZWQgbWFrZXMgbWUgdmUtcnkgYW4tZ3J5ISIgPGh1ZmYsIGh1ZmY-' end - ruby_version_is "2.3" do - it "makes padding optional" do - Base64.urlsafe_encode64("1", padding: false).should == "MQ" - Base64.urlsafe_encode64("1").should == "MQ==" - end + it "makes padding optional" do + Base64.urlsafe_encode64("1", padding: false).should == "MQ" + Base64.urlsafe_encode64("1").should == "MQ==" end end diff --git a/spec/ruby/library/bigdecimal/BigDecimal_spec.rb b/spec/ruby/library/bigdecimal/BigDecimal_spec.rb new file mode 100644 index 0000000000..d278512737 --- /dev/null +++ b/spec/ruby/library/bigdecimal/BigDecimal_spec.rb @@ -0,0 +1,109 @@ +require_relative '../../spec_helper' +require 'bigdecimal' + +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 "accepts significant digits >= given precision" do + BigDecimal("3.1415923", 10).precs[1].should >= 10 + end + + it "determines precision from initial value" do + pi_string = "3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593014782083152134043" + BigDecimal(pi_string).precs[1].should >= pi_string.size-1 + end + + it "ignores leading whitespace" do + BigDecimal(" \t\n \r1234").should == BigDecimal("1234") + BigDecimal(" \t\n \rNaN \n").nan?.should == true + BigDecimal(" \t\n \rInfinity \n").infinite?.should == 1 + BigDecimal(" \t\n \r-Infinity \n").infinite?.should == -1 + end + + it "ignores trailing garbage" do + BigDecimal("123E45ruby").should == BigDecimal("123E45") + BigDecimal("123x45").should == BigDecimal("123") + BigDecimal("123.4%E5").should == BigDecimal("123.4") + BigDecimal("1E2E3E4E5E").should == BigDecimal("100") + end + + ruby_version_is ""..."2.4" do + it "treats invalid strings as 0.0" do + BigDecimal("ruby").should == BigDecimal("0.0") + BigDecimal(" \t\n \r-\t\t\tInfinity \n").should == BigDecimal("0.0") + end + end + + ruby_version_is "2.4" do + it "raises ArgumentError for invalid strings" do + lambda { BigDecimal("ruby") }.should raise_error(ArgumentError) + lambda { BigDecimal(" \t\n \r-\t\t\tInfinity \n") }.should raise_error(ArgumentError) + end + end + + it "allows omitting the integer part" do + BigDecimal(".123").should == BigDecimal("0.123") + end + + it "allows for underscores in all parts" do + reference = BigDecimal("12345.67E89") + + BigDecimal("12_345.67E89").should == reference + BigDecimal("1_2_3_4_5_._6____7_E89").should == reference + BigDecimal("12345_.67E_8__9_").should == reference + end + + it "accepts NaN and [+-]Infinity" do + BigDecimal("NaN").nan?.should == true + + pos_inf = BigDecimal("Infinity") + pos_inf.finite?.should == false + pos_inf.should > 0 + pos_inf.should == BigDecimal("+Infinity") + + neg_inf = BigDecimal("-Infinity") + neg_inf.finite?.should == false + neg_inf.should < 0 + end + + it "allows for [eEdD] as exponent separator" do + reference = BigDecimal("12345.67E89") + + BigDecimal("12345.67e89").should == reference + BigDecimal("12345.67E89").should == reference + BigDecimal("12345.67d89").should == reference + BigDecimal("12345.67D89").should == reference + end + + it "allows for varying signs" do + reference = BigDecimal("123.456E1") + + BigDecimal("+123.456E1").should == reference + BigDecimal("-123.456E1").should == -reference + BigDecimal("123.456E+1").should == reference + BigDecimal("12345.6E-1").should == reference + BigDecimal("+123.456E+1").should == reference + BigDecimal("+12345.6E-1").should == reference + BigDecimal("-123.456E+1").should == -reference + BigDecimal("-12345.6E-1").should == -reference + end + + it 'raises ArgumentError when Float is used without precision' do + lambda { BigDecimal(1.0) }.should raise_error(ArgumentError) + end + +end diff --git a/spec/ruby/library/bigdecimal/divmod_spec.rb b/spec/ruby/library/bigdecimal/divmod_spec.rb index a93e0836bf..22b66c2d48 100644 --- a/spec/ruby/library/bigdecimal/divmod_spec.rb +++ b/spec/ruby/library/bigdecimal/divmod_spec.rb @@ -36,7 +36,7 @@ describe "BigDecimal#mod_part_of_divmod" do it_behaves_like :bigdecimal_modulo, :mod_part_of_divmod it "raises ZeroDivisionError if other is zero" do - bd5667 = BigDecimal.new("5667.19") + bd5667 = BigDecimal("5667.19") lambda { bd5667.send(@method, 0) }.should raise_error(ZeroDivisionError) lambda { bd5667.send(@method, BigDecimal("0")) }.should raise_error(ZeroDivisionError) @@ -96,8 +96,8 @@ describe "BigDecimal#divmod" do it "can be reversed with * and +" do # Example taken from BigDecimal documentation - a = BigDecimal.new("42") - b = BigDecimal.new("9") + a = BigDecimal("42") + b = BigDecimal("9") q, m = a.divmod(b) c = q * b + m a.should == c diff --git a/spec/ruby/library/bigdecimal/inspect_spec.rb b/spec/ruby/library/bigdecimal/inspect_spec.rb index 0873e8bef6..7e1a8297e2 100644 --- a/spec/ruby/library/bigdecimal/inspect_spec.rb +++ b/spec/ruby/library/bigdecimal/inspect_spec.rb @@ -4,7 +4,7 @@ require 'bigdecimal' describe "BigDecimal#inspect" do before :each do - @bigdec = BigDecimal.new("1234.5678") + @bigdec = BigDecimal("1234.5678") end it "returns String" do diff --git a/spec/ruby/library/bigdecimal/limit_spec.rb b/spec/ruby/library/bigdecimal/limit_spec.rb index 7fd395dd50..75cbc8b55c 100644 --- a/spec/ruby/library/bigdecimal/limit_spec.rb +++ b/spec/ruby/library/bigdecimal/limit_spec.rb @@ -42,4 +42,14 @@ describe "BigDecimal.limit" do 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/new_spec.rb b/spec/ruby/library/bigdecimal/new_spec.rb deleted file mode 100644 index 64f2a7f468..0000000000 --- a/spec/ruby/library/bigdecimal/new_spec.rb +++ /dev/null @@ -1,109 +0,0 @@ -require_relative '../../spec_helper' -require 'bigdecimal' - -describe "BigDecimal.new" do - - it "creates a new object of class BigDecimal" do - BigDecimal.new("3.14159").should be_kind_of(BigDecimal) - (0..9).each {|i| - BigDecimal.new("1#{i}").should == 10 + i - BigDecimal.new("-1#{i}").should == -10 - i - BigDecimal.new("1E#{i}").should == 10**i - BigDecimal.new("1000000E-#{i}").should == 10**(6-i).to_f - # ^ to_f to avoid Rational type - } - (1..9).each {|i| - BigDecimal.new("100.#{i}").to_s.should =~ /\A0\.100#{i}E3\z/i - BigDecimal.new("-100.#{i}").to_s.should =~ /\A-0\.100#{i}E3\z/i - } - end - - it "accepts significant digits >= given precision" do - BigDecimal.new("3.1415923", 10).precs[1].should >= 10 - end - - it "determines precision from initial value" do - pi_string = "3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593014782083152134043" - BigDecimal.new(pi_string).precs[1].should >= pi_string.size-1 - end - - it "ignores leading whitespace" do - BigDecimal.new(" \t\n \r1234").should == BigDecimal.new("1234") - BigDecimal.new(" \t\n \rNaN \n").nan?.should == true - BigDecimal.new(" \t\n \rInfinity \n").infinite?.should == 1 - BigDecimal.new(" \t\n \r-Infinity \n").infinite?.should == -1 - end - - it "ignores trailing garbage" do - BigDecimal.new("123E45ruby").should == BigDecimal.new("123E45") - BigDecimal.new("123x45").should == BigDecimal.new("123") - BigDecimal.new("123.4%E5").should == BigDecimal.new("123.4") - BigDecimal.new("1E2E3E4E5E").should == BigDecimal.new("100") - end - - ruby_version_is ""..."2.4" do - it "treats invalid strings as 0.0" do - BigDecimal.new("ruby").should == BigDecimal.new("0.0") - BigDecimal.new(" \t\n \r-\t\t\tInfinity \n").should == BigDecimal.new("0.0") - end - end - - ruby_version_is "2.4" do - it "raises ArgumentError for invalid strings" do - lambda { BigDecimal.new("ruby") }.should raise_error(ArgumentError) - lambda { BigDecimal.new(" \t\n \r-\t\t\tInfinity \n") }.should raise_error(ArgumentError) - end - end - - it "allows omitting the integer part" do - BigDecimal.new(".123").should == BigDecimal.new("0.123") - end - - it "allows for underscores in all parts" do - reference = BigDecimal.new("12345.67E89") - - BigDecimal.new("12_345.67E89").should == reference - BigDecimal.new("1_2_3_4_5_._6____7_E89").should == reference - BigDecimal.new("12345_.67E_8__9_").should == reference - end - - it "accepts NaN and [+-]Infinity" do - BigDecimal.new("NaN").nan?.should == true - - pos_inf = BigDecimal.new("Infinity") - pos_inf.finite?.should == false - pos_inf.should > 0 - pos_inf.should == BigDecimal.new("+Infinity") - - neg_inf = BigDecimal.new("-Infinity") - neg_inf.finite?.should == false - neg_inf.should < 0 - end - - it "allows for [eEdD] as exponent separator" do - reference = BigDecimal.new("12345.67E89") - - BigDecimal.new("12345.67e89").should == reference - BigDecimal.new("12345.67E89").should == reference - BigDecimal.new("12345.67d89").should == reference - BigDecimal.new("12345.67D89").should == reference - end - - it "allows for varying signs" do - reference = BigDecimal.new("123.456E1") - - BigDecimal.new("+123.456E1").should == reference - BigDecimal.new("-123.456E1").should == -reference - BigDecimal.new("123.456E+1").should == reference - BigDecimal.new("12345.6E-1").should == reference - BigDecimal.new("+123.456E+1").should == reference - BigDecimal.new("+12345.6E-1").should == reference - BigDecimal.new("-123.456E+1").should == -reference - BigDecimal.new("-12345.6E-1").should == -reference - end - - it 'raises ArgumentError when Float is used without precision' do - lambda { BigDecimal(1.0) }.should raise_error(ArgumentError) - end - -end diff --git a/spec/ruby/library/bigdecimal/shared/eql.rb b/spec/ruby/library/bigdecimal/shared/eql.rb index eaad272e9a..8e3e388bab 100644 --- a/spec/ruby/library/bigdecimal/shared/eql.rb +++ b/spec/ruby/library/bigdecimal/shared/eql.rb @@ -2,8 +2,8 @@ require 'bigdecimal' describe :bigdecimal_eql, shared: true do before :each do - @bg6543_21 = BigDecimal.new("6543.21") - @bg5667_19 = BigDecimal.new("5667.19") + @bg6543_21 = BigDecimal("6543.21") + @bg5667_19 = BigDecimal("5667.19") @a = BigDecimal("1.0000000000000000000000000000000000000000005") @b = BigDecimal("1.00000000000000000000000000000000000000000005") @bigint = BigDecimal("1000.0") diff --git a/spec/ruby/library/bigdecimal/shared/modulo.rb b/spec/ruby/library/bigdecimal/shared/modulo.rb index 78ebe8360d..c9691cbf37 100644 --- a/spec/ruby/library/bigdecimal/shared/modulo.rb +++ b/spec/ruby/library/bigdecimal/shared/modulo.rb @@ -18,8 +18,8 @@ describe :bigdecimal_modulo, shared: true do end it "returns self modulo other" do - bd6543 = BigDecimal.new("6543.21") - bd5667 = BigDecimal.new("5667.19") + bd6543 = BigDecimal("6543.21") + bd5667 = BigDecimal("5667.19") a = BigDecimal("1.0000000000000000000000000000000000000000005") b = BigDecimal("1.00000000000000000000000000000000000000000005") @@ -107,7 +107,7 @@ end describe :bigdecimal_modulo_zerodivisionerror, shared: true do it "raises ZeroDivisionError if other is zero" do - bd5667 = BigDecimal.new("5667.19") + bd5667 = BigDecimal("5667.19") lambda { bd5667.send(@method, 0) }.should raise_error(ZeroDivisionError) lambda { bd5667.send(@method, BigDecimal("0")) }.should raise_error(ZeroDivisionError) diff --git a/spec/ruby/library/bigdecimal/to_r_spec.rb b/spec/ruby/library/bigdecimal/to_r_spec.rb index e2956782bd..91d2b33993 100644 --- a/spec/ruby/library/bigdecimal/to_r_spec.rb +++ b/spec/ruby/library/bigdecimal/to_r_spec.rb @@ -8,7 +8,7 @@ describe "BigDecimal#to_r" do end it "returns a Rational with bignum values" do - r = BigDecimal.new("3.141592653589793238462643").to_r + r = BigDecimal("3.141592653589793238462643").to_r r.numerator.should eql(3141592653589793238462643) r.denominator.should eql(1000000000000000000000000) end diff --git a/spec/ruby/library/bigdecimal/to_s_spec.rb b/spec/ruby/library/bigdecimal/to_s_spec.rb index 86716c93fe..86ae1e61f6 100644 --- a/spec/ruby/library/bigdecimal/to_s_spec.rb +++ b/spec/ruby/library/bigdecimal/to_s_spec.rb @@ -34,11 +34,11 @@ describe "BigDecimal#to_s" do @bigdec.to_s(3).should =~ re str1 = '-123.45678 90123 45678 9' - BigDecimal.new("-123.45678901234567890").to_s('5F').should == str1 + BigDecimal("-123.45678901234567890").to_s('5F').should == str1 # trailing zeroes removed - BigDecimal.new("1.00000000000").to_s('1F').should == "1.0" + BigDecimal("1.00000000000").to_s('1F').should == "1.0" # 0 is treated as no spaces - BigDecimal.new("1.2345").to_s('0F').should == "1.2345" + BigDecimal("1.2345").to_s('0F').should == "1.2345" end it "can return a leading space for values > 0" do @@ -47,15 +47,15 @@ describe "BigDecimal#to_s" do end it "removes trailing spaces in floating point notation" do - BigDecimal.new('-123.45678901234567890').to_s('F').should == "-123.4567890123456789" - BigDecimal.new('1.2500').to_s('F').should == "1.25" - BigDecimal.new('0000.00000').to_s('F').should == "0.0" - BigDecimal.new('-00.000010000').to_s('F').should == "-0.00001" - BigDecimal.new("5.00000E-2").to_s("F").should == "0.05" + BigDecimal('-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.new("500000").to_s("F").should == "500000.0" - BigDecimal.new("5E2").to_s("F").should == "500.0" - BigDecimal.new("-5E100").to_s("F").should == "-5" + "0" * 100 + ".0" + BigDecimal("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 @@ -66,7 +66,7 @@ describe "BigDecimal#to_s" do @bigdec.to_s("F").should == @bigdec_str @bigneg.to_s("F").should == @bigneg_str str2 = "+123.45678901 23456789" - BigDecimal.new('123.45678901234567890').to_s('+8F').should == str2 + BigDecimal('123.45678901234567890').to_s('+8F').should == str2 end end diff --git a/spec/ruby/library/coverage/peek_result_spec.rb b/spec/ruby/library/coverage/peek_result_spec.rb index f10e85828e..897fc4d978 100644 --- a/spec/ruby/library/coverage/peek_result_spec.rb +++ b/spec/ruby/library/coverage/peek_result_spec.rb @@ -2,66 +2,64 @@ require_relative '../../spec_helper' require fixture __FILE__, 'spec_helper' require 'coverage' -ruby_version_is '2.3' do - describe 'Coverage.peek_result' do - before :all do - @class_file = fixture __FILE__, 'some_class.rb' - @second_class_file = fixture __FILE__, 'second_class.rb' - end +describe 'Coverage.peek_result' do + before :all do + @class_file = fixture __FILE__, 'some_class.rb' + @second_class_file = fixture __FILE__, 'second_class.rb' + end - after :each do - $LOADED_FEATURES.delete(@class_file) - $LOADED_FEATURES.delete(@second_class_file) - end + after :each do + $LOADED_FEATURES.delete(@class_file) + $LOADED_FEATURES.delete(@second_class_file) + end - it 'returns the result so far' do - Coverage.start - require @class_file.chomp('.rb') - result = Coverage.peek_result - Coverage.result + it 'returns the result so far' do + Coverage.start + require @class_file.chomp('.rb') + result = Coverage.peek_result + Coverage.result - result.should == { - @class_file => [ - nil, nil, 1, nil, nil, 1, nil, nil, 0, nil, nil, nil, nil, nil, nil, nil - ] - } - end + result.should == { + @class_file => [ + nil, nil, 1, nil, nil, 1, nil, nil, 0, nil, nil, nil, nil, nil, nil, nil + ] + } + end - it 'immediate second call returns same result' do - Coverage.start - require @class_file.chomp('.rb') - result1 = Coverage.peek_result - result2 = Coverage.peek_result - Coverage.result + it 'immediate second call returns same result' do + Coverage.start + require @class_file.chomp('.rb') + result1 = Coverage.peek_result + result2 = Coverage.peek_result + Coverage.result - result2.should == result1 - end + result2.should == result1 + end - it 'second call after require returns accumulated result' do - Coverage.start - require @class_file.chomp('.rb') - Coverage.peek_result - require @second_class_file.chomp('.rb') - result = Coverage.peek_result - Coverage.result + it 'second call after require returns accumulated result' do + Coverage.start + require @class_file.chomp('.rb') + Coverage.peek_result + require @second_class_file.chomp('.rb') + result = Coverage.peek_result + Coverage.result - result.should == { - @class_file => [ - nil, nil, 1, nil, nil, 1, nil, nil, 0, nil, nil, nil, nil, nil, nil, nil - ], - @second_class_file => [ - 1, 1, 0, nil, nil - ] - } - end + result.should == { + @class_file => [ + nil, nil, 1, nil, nil, 1, nil, nil, 0, nil, nil, nil, nil, nil, nil, nil + ], + @second_class_file => [ + 1, 1, 0, nil, nil + ] + } + end - it 'call right before Coverage.result should give equal result' do - Coverage.start - require @class_file.chomp('.rb') - result1 = Coverage.peek_result - result2 = Coverage.result + it 'call right before Coverage.result should give equal result' do + Coverage.start + require @class_file.chomp('.rb') + result1 = Coverage.peek_result + result2 = Coverage.result - result1.should == result2 - end + result1.should == result2 end end diff --git a/spec/ruby/library/date/minus_month_spec.rb b/spec/ruby/library/date/minus_month_spec.rb index b9b5e99bf2..563da073f0 100644 --- a/spec/ruby/library/date/minus_month_spec.rb +++ b/spec/ruby/library/date/minus_month_spec.rb @@ -13,13 +13,11 @@ describe "Date#<<" do d.should == Date.civil(2008, 2, 29) end - ruby_version_is "2.3" do - it "raises an error on non numeric parameters" do - lambda { Date.civil(2007,2,27) << :hello }.should raise_error(TypeError) - lambda { Date.civil(2007,2,27) << "hello" }.should raise_error(TypeError) - lambda { Date.civil(2007,2,27) << Date.new }.should raise_error(TypeError) - lambda { Date.civil(2007,2,27) << Object.new }.should raise_error(TypeError) - end + it "raises an error on non numeric parameters" do + lambda { Date.civil(2007,2,27) << :hello }.should raise_error(TypeError) + lambda { Date.civil(2007,2,27) << "hello" }.should raise_error(TypeError) + lambda { Date.civil(2007,2,27) << Date.new }.should raise_error(TypeError) + lambda { Date.civil(2007,2,27) << Object.new }.should raise_error(TypeError) end end diff --git a/spec/ruby/library/net/ftp/default_passive_spec.rb b/spec/ruby/library/net/ftp/default_passive_spec.rb index af8925fc1e..30eb8f9da2 100644 --- a/spec/ruby/library/net/ftp/default_passive_spec.rb +++ b/spec/ruby/library/net/ftp/default_passive_spec.rb @@ -1,10 +1,8 @@ require_relative '../../../spec_helper' require_relative 'spec_helper' -ruby_version_is "2.3" do - describe "Net::FTP#default_passive" do - it "is true by default" do - ruby_exe(fixture(__FILE__, "default_passive.rb")).should == "true\ntrue\n" - end +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/passive_spec.rb b/spec/ruby/library/net/ftp/passive_spec.rb index 041b9552d5..e8db030cbd 100644 --- a/spec/ruby/library/net/ftp/passive_spec.rb +++ b/spec/ruby/library/net/ftp/passive_spec.rb @@ -10,16 +10,8 @@ describe "Net::FTP#passive" do ftp.passive.should be_true end - ruby_version_is ""..."2.3" do - it "is false by default" do - ruby_exe(fixture(__FILE__, "passive.rb")).should == "false" - end - end - - ruby_version_is "2.3" do - it "is the value of Net::FTP.default_value by default" do - ruby_exe(fixture(__FILE__, "passive.rb")).should == "true" - end + it "is the value of Net::FTP.default_value by default" do + ruby_exe(fixture(__FILE__, "passive.rb")).should == "true" end end diff --git a/spec/ruby/library/net/http/http/open_timeout_spec.rb b/spec/ruby/library/net/http/http/open_timeout_spec.rb index 333ad5c5b5..44b33615e6 100644 --- a/spec/ruby/library/net/http/http/open_timeout_spec.rb +++ b/spec/ruby/library/net/http/http/open_timeout_spec.rb @@ -2,22 +2,11 @@ require_relative '../../../../spec_helper' require 'net/http' describe "Net::HTTP#open_timeout" do - ruby_version_is ""..."2.3" do - it "returns the seconds to wait till the connection is open" do - net = Net::HTTP.new("localhost") - net.open_timeout.should be_nil - net.open_timeout = 10 - net.open_timeout.should eql(10) - end - end - - ruby_version_is "2.3" do - it "returns the seconds to wait till the connection is open" do - net = Net::HTTP.new("localhost") - net.open_timeout.should eql(60) - net.open_timeout = 10 - net.open_timeout.should eql(10) - end + it "returns the seconds to wait till the connection is open" do + net = Net::HTTP.new("localhost") + net.open_timeout.should eql(60) + net.open_timeout = 10 + net.open_timeout.should eql(10) end end diff --git a/spec/ruby/library/rexml/element/namespaces_spec.rb b/spec/ruby/library/rexml/element/namespaces_spec.rb index 0fba0a1cf6..a84c1d1dab 100644 --- a/spec/ruby/library/rexml/element/namespaces_spec.rb +++ b/spec/ruby/library/rexml/element/namespaces_spec.rb @@ -28,4 +28,5 @@ describe "REXML::Element#namespaces" do values = ["2", "3", "1"] @elem.namespaces.values.sort.should == values.sort end + end diff --git a/spec/ruby/library/securerandom/random_number_spec.rb b/spec/ruby/library/securerandom/random_number_spec.rb index 67884f99bf..6b3279e6d7 100644 --- a/spec/ruby/library/securerandom/random_number_spec.rb +++ b/spec/ruby/library/securerandom/random_number_spec.rb @@ -31,34 +31,32 @@ describe "SecureRandom.random_number" do end end - ruby_version_is "2.3" do - it "generates a random value in given (integer) range limits" do - 64.times do - num = SecureRandom.random_number 11...13 - num.should be_kind_of(Integer) - (11 <= num).should == true - (num < 13).should == true - end + it "generates a random value in given (integer) range limits" do + 64.times do + num = SecureRandom.random_number 11...13 + num.should be_kind_of(Integer) + (11 <= num).should == true + (num < 13).should == true end + end - it "generates a random value in given big (integer) range limits" do - lower = 12345678901234567890 - upper = 12345678901234567890 + 5 - 32.times do - num = SecureRandom.random_number lower..upper - num.should be_kind_of(Integer) - (lower <= num).should == true - (num <= upper).should == true - end + it "generates a random value in given big (integer) range limits" do + lower = 12345678901234567890 + upper = 12345678901234567890 + 5 + 32.times do + num = SecureRandom.random_number lower..upper + num.should be_kind_of(Integer) + (lower <= num).should == true + (num <= upper).should == true end + end - it "generates a random value in given (float) range limits" do - 64.times do - num = SecureRandom.random_number 0.6..0.9 - num.should be_kind_of(Float) - (0.6 <= num).should == true - (num <= 0.9).should == true - end + it "generates a random value in given (float) range limits" do + 64.times do + num = SecureRandom.random_number 0.6..0.9 + num.should be_kind_of(Float) + (0.6 <= num).should == true + (num <= 0.9).should == true end end diff --git a/spec/ruby/library/socket/basicsocket/recv_spec.rb b/spec/ruby/library/socket/basicsocket/recv_spec.rb index d6418134c5..7677d4ff8c 100644 --- a/spec/ruby/library/socket/basicsocket/recv_spec.rb +++ b/spec/ruby/library/socket/basicsocket/recv_spec.rb @@ -76,21 +76,19 @@ describe "BasicSocket#recv" do ScratchPad.recorded.should == "firstline\377" end - ruby_version_is "2.3" do - it "allows an output buffer as third argument" do - socket = TCPSocket.new('127.0.0.1', @port) - socket.write("data") - - client = @server.accept - buf = "foo" - begin - client.recv(4, 0, buf) - ensure - client.close - end - buf.should == "data" + it "allows an output buffer as third argument" do + socket = TCPSocket.new('127.0.0.1', @port) + socket.write("data") - socket.close + client = @server.accept + buf = "foo" + begin + client.recv(4, 0, buf) + ensure + client.close end + buf.should == "data" + + socket.close end end diff --git a/spec/ruby/library/socket/shared/recv_nonblock.rb b/spec/ruby/library/socket/shared/recv_nonblock.rb index a5f6c6812e..2b584d52a2 100644 --- a/spec/ruby/library/socket/shared/recv_nonblock.rb +++ b/spec/ruby/library/socket/shared/recv_nonblock.rb @@ -30,16 +30,14 @@ describe :socket_recv_nonblock, shared: true do @s1.recv_nonblock(5).should == "aaa" end - ruby_version_is "2.3" do - it "allows an output buffer as third argument" do - @s1.bind(Socket.pack_sockaddr_in(0, "127.0.0.1")) - @s2.send("data", 0, @s1.getsockname) - IO.select([@s1], nil, nil, 2) + it "allows an output buffer as third argument" do + @s1.bind(Socket.pack_sockaddr_in(0, "127.0.0.1")) + @s2.send("data", 0, @s1.getsockname) + IO.select([@s1], nil, nil, 2) - buf = "foo" - @s1.recv_nonblock(5, 0, buf) - buf.should == "data" - end + buf = "foo" + @s1.recv_nonblock(5, 0, buf) + buf.should == "data" end it "does not block if there's no data available" do diff --git a/spec/ruby/library/socket/socket/accept_nonblock_spec.rb b/spec/ruby/library/socket/socket/accept_nonblock_spec.rb index b495cd934c..44f3be9c0e 100644 --- a/spec/ruby/library/socket/socket/accept_nonblock_spec.rb +++ b/spec/ruby/library/socket/socket/accept_nonblock_spec.rb @@ -29,9 +29,7 @@ describe "Socket#accept_nonblock" do } end - ruby_version_is '2.3' do - it 'returns :wait_readable in exceptionless mode' do - @socket.accept_nonblock(exception: false).should == :wait_readable - end + it 'returns :wait_readable in exceptionless mode' do + @socket.accept_nonblock(exception: false).should == :wait_readable end end diff --git a/spec/ruby/library/socket/socket/connect_nonblock_spec.rb b/spec/ruby/library/socket/socket/connect_nonblock_spec.rb index 98f4cd8aad..caac24401c 100644 --- a/spec/ruby/library/socket/socket/connect_nonblock_spec.rb +++ b/spec/ruby/library/socket/socket/connect_nonblock_spec.rb @@ -64,10 +64,8 @@ describe "Socket#connect_nonblock" do end.should raise_error(IO::WaitWritable) end - ruby_version_is "2.3" do - it "returns :wait_writable in exceptionless mode when the connect would block" do - @socket.connect_nonblock(@addr, exception: false).should == :wait_writable - end + it "returns :wait_writable in exceptionless mode when the connect would block" do + @socket.connect_nonblock(@addr, exception: false).should == :wait_writable end end end diff --git a/spec/ruby/library/socket/tcpserver/accept_nonblock_spec.rb b/spec/ruby/library/socket/tcpserver/accept_nonblock_spec.rb index be13630444..8566081d2f 100644 --- a/spec/ruby/library/socket/tcpserver/accept_nonblock_spec.rb +++ b/spec/ruby/library/socket/tcpserver/accept_nonblock_spec.rb @@ -41,10 +41,8 @@ describe "Socket::TCPServer.accept_nonblock" do lambda { @server.accept_nonblock }.should raise_error(IO::WaitReadable) end - ruby_version_is '2.3' do - it 'returns :wait_readable in exceptionless mode' do - @server.accept_nonblock(exception: false).should == :wait_readable - end + it 'returns :wait_readable in exceptionless mode' do + @server.accept_nonblock(exception: false).should == :wait_readable end end end diff --git a/spec/ruby/library/socket/tcpsocket/recv_nonblock_spec.rb b/spec/ruby/library/socket/tcpsocket/recv_nonblock_spec.rb index 9ee7db8cf6..23bba526e8 100644 --- a/spec/ruby/library/socket/tcpsocket/recv_nonblock_spec.rb +++ b/spec/ruby/library/socket/tcpsocket/recv_nonblock_spec.rb @@ -27,10 +27,8 @@ describe "TCPSocket#recv_nonblock" do @socket.recv_nonblock(50).should == "TCPSocket#recv_nonblock" end - ruby_version_is '2.3' do - it 'returns :wait_readable in exceptionless mode' do - @socket = TCPSocket.new @hostname, @server.port - @socket.recv_nonblock(50, exception: false).should == :wait_readable - end + it 'returns :wait_readable in exceptionless mode' do + @socket = TCPSocket.new @hostname, @server.port + @socket.recv_nonblock(50, exception: false).should == :wait_readable end end diff --git a/spec/ruby/library/socket/unixserver/accept_nonblock_spec.rb b/spec/ruby/library/socket/unixserver/accept_nonblock_spec.rb index 7454297fd8..27603aeabd 100644 --- a/spec/ruby/library/socket/unixserver/accept_nonblock_spec.rb +++ b/spec/ruby/library/socket/unixserver/accept_nonblock_spec.rb @@ -29,10 +29,8 @@ describe "UNIXServer#accept_nonblock" do @socket.should be_kind_of(UNIXSocket) end - ruby_version_is '2.3' do - it 'returns :wait_readable in exceptionless mode' do - @server.accept_nonblock(exception: false).should == :wait_readable - end + it 'returns :wait_readable in exceptionless mode' do + @server.accept_nonblock(exception: false).should == :wait_readable end end end diff --git a/spec/ruby/library/stringio/close_read_spec.rb b/spec/ruby/library/stringio/close_read_spec.rb index 48630e0a7b..05d6c9f7d2 100644 --- a/spec/ruby/library/stringio/close_read_spec.rb +++ b/spec/ruby/library/stringio/close_read_spec.rb @@ -26,11 +26,6 @@ describe "StringIO#close_read" do io = StringIO.new("example") io.close_read - ruby_version_is ''...'2.3' do - lambda { io.close_read }.should raise_error(IOError) - end - ruby_version_is '2.3' do - io.close_read.should == nil - end + io.close_read.should == nil end end diff --git a/spec/ruby/library/stringio/close_spec.rb b/spec/ruby/library/stringio/close_spec.rb index 592dfdf526..a5a931aff1 100644 --- a/spec/ruby/library/stringio/close_spec.rb +++ b/spec/ruby/library/stringio/close_spec.rb @@ -16,17 +16,8 @@ describe "StringIO#close" do lambda { @io.write('x') }.should raise_error(IOError) end - ruby_version_is ''...'2.3' do - it "raises an IOError when self was already closed" do - @io.close - lambda { @io.close }.should raise_error(IOError) - end - end - - ruby_version_is "2.3" do - it "does not raise anything when self was already closed" do - @io.close - lambda { @io.close }.should_not raise_error(IOError) - end + it "does not raise anything when self was already closed" do + @io.close + lambda { @io.close }.should_not raise_error(IOError) end end diff --git a/spec/ruby/library/stringio/close_write_spec.rb b/spec/ruby/library/stringio/close_write_spec.rb index f6292a9253..8a7ac12581 100644 --- a/spec/ruby/library/stringio/close_write_spec.rb +++ b/spec/ruby/library/stringio/close_write_spec.rb @@ -26,11 +26,6 @@ describe "StringIO#close_write" do io = StringIO.new("example") io.close_write - ruby_version_is ''...'2.3' do - lambda { io.close_write }.should raise_error(IOError) - end - ruby_version_is '2.3' do - io.close_write.should == nil - end + io.close_write.should == nil end end diff --git a/spec/ruby/library/stringio/external_encoding_spec.rb b/spec/ruby/library/stringio/external_encoding_spec.rb index 1a57081287..9c3d4041e5 100644 --- a/spec/ruby/library/stringio/external_encoding_spec.rb +++ b/spec/ruby/library/stringio/external_encoding_spec.rb @@ -8,14 +8,12 @@ describe "StringIO#external_encoding" do io.external_encoding.should == Encoding::EUC_JP end - ruby_version_is "2.3" do - it "does not set the encoding of its buffer string if the string is frozen" do - str = "foo".freeze - enc = str.encoding - io = StringIO.new(str) - io.set_encoding Encoding::EUC_JP - io.external_encoding.should == Encoding::EUC_JP - str.encoding.should == enc - end + it "does not set the encoding of its buffer string if the string is frozen" do + str = "foo".freeze + enc = str.encoding + io = StringIO.new(str) + io.set_encoding Encoding::EUC_JP + io.external_encoding.should == Encoding::EUC_JP + str.encoding.should == enc end end diff --git a/spec/ruby/library/stringio/read_nonblock_spec.rb b/spec/ruby/library/stringio/read_nonblock_spec.rb index 88728fcc18..7a79eef3c5 100644 --- a/spec/ruby/library/stringio/read_nonblock_spec.rb +++ b/spec/ruby/library/stringio/read_nonblock_spec.rb @@ -18,3 +18,12 @@ end describe "StringIO#read_nonblock when passed length" do it_behaves_like :stringio_sysread_length, :read_nonblock end + +describe "StringIO#read_nonblock" do + + it "accepts an exception option" do + stringio = StringIO.new('foo') + stringio.read_nonblock(3, exception: false).should == 'foo' + end + +end diff --git a/spec/ruby/library/thread/queue/close_spec.rb b/spec/ruby/library/thread/queue/close_spec.rb index 16c2d9d2e3..32bc0a32d7 100644 --- a/spec/ruby/library/thread/queue/close_spec.rb +++ b/spec/ruby/library/thread/queue/close_spec.rb @@ -2,8 +2,6 @@ require_relative '../../../spec_helper' require 'thread' require_relative '../shared/queue/close' -ruby_version_is "2.3" do - describe "Queue#close" do - it_behaves_like :queue_close, :close, -> { Queue.new } - end +describe "Queue#close" do + it_behaves_like :queue_close, :close, -> { Queue.new } end diff --git a/spec/ruby/library/thread/queue/closed_spec.rb b/spec/ruby/library/thread/queue/closed_spec.rb index 052c9320e0..df3596b14b 100644 --- a/spec/ruby/library/thread/queue/closed_spec.rb +++ b/spec/ruby/library/thread/queue/closed_spec.rb @@ -2,8 +2,6 @@ require_relative '../../../spec_helper' require 'thread' require_relative '../shared/queue/closed' -ruby_version_is "2.3" do - describe "Queue#closed?" do - it_behaves_like :queue_closed?, :closed?, -> { Queue.new } - end +describe "Queue#closed?" do + it_behaves_like :queue_closed?, :closed?, -> { Queue.new } end diff --git a/spec/ruby/library/thread/sizedqueue/close_spec.rb b/spec/ruby/library/thread/sizedqueue/close_spec.rb index 79ba87c127..3222772f61 100644 --- a/spec/ruby/library/thread/sizedqueue/close_spec.rb +++ b/spec/ruby/library/thread/sizedqueue/close_spec.rb @@ -2,8 +2,6 @@ require_relative '../../../spec_helper' require 'thread' require_relative '../shared/queue/close' -ruby_version_is "2.3" do - describe "SizedQueue#close" do - it_behaves_like :queue_close, :close, -> { SizedQueue.new(10) } - end +describe "SizedQueue#close" do + it_behaves_like :queue_close, :close, -> { SizedQueue.new(10) } end diff --git a/spec/ruby/library/thread/sizedqueue/closed_spec.rb b/spec/ruby/library/thread/sizedqueue/closed_spec.rb index 1cc68078c0..9e41b89640 100644 --- a/spec/ruby/library/thread/sizedqueue/closed_spec.rb +++ b/spec/ruby/library/thread/sizedqueue/closed_spec.rb @@ -2,8 +2,6 @@ require_relative '../../../spec_helper' require 'thread' require_relative '../shared/queue/closed' -ruby_version_is "2.3" do - describe "SizedQueue#closed?" do - it_behaves_like :queue_closed?, :closed?, -> { SizedQueue.new(10) } - end +describe "SizedQueue#closed?" do + it_behaves_like :queue_closed?, :closed?, -> { SizedQueue.new(10) } end diff --git a/spec/ruby/optional/capi/class_spec.rb b/spec/ruby/optional/capi/class_spec.rb index 85d7419fd2..acfb8e3728 100644 --- a/spec/ruby/optional/capi/class_spec.rb +++ b/spec/ruby/optional/capi/class_spec.rb @@ -257,34 +257,20 @@ describe "C-API Class function" do }.should raise_error(TypeError) end - ruby_version_is "2.3" do - it "raises a TypeError when given a mismatched class to superclass" do - CApiClassSpecs::ClassUnder6 = Class.new(CApiClassSpecs::Super) - lambda { @s.rb_define_class_under(CApiClassSpecs, - "ClassUnder6", - Class.new) - }.should raise_error(TypeError) - end - end - - ruby_version_is ""..."2.3" do - it "raises a NameError when given a mismatched class to superclass" do - CApiClassSpecs::ClassUnder6 = Class.new(CApiClassSpecs::Super) - lambda { @s.rb_define_class_under(CApiClassSpecs, - "ClassUnder6", - Class.new) - }.should raise_error(NameError) - end + it "raises a TypeError when given a mismatched class to superclass" do + CApiClassSpecs::ClassUnder6 = Class.new(CApiClassSpecs::Super) + lambda { @s.rb_define_class_under(CApiClassSpecs, + "ClassUnder6", + Class.new) + }.should raise_error(TypeError) end it "defines a class for an existing Autoload" do ClassUnderAutoload.name.should == "ClassUnderAutoload" end - ruby_version_is "2.3" do - it "raises a TypeError if class is defined and its superclass mismatches the given one" do - lambda { @s.rb_define_class_under(CApiClassSpecs, "Sub", Object) }.should raise_error(TypeError) - end + it "raises a TypeError if class is defined and its superclass mismatches the given one" do + lambda { @s.rb_define_class_under(CApiClassSpecs, "Sub", Object) }.should raise_error(TypeError) end end @@ -310,10 +296,8 @@ describe "C-API Class function" do ClassIdUnderAutoload.name.should == "ClassIdUnderAutoload" end - ruby_version_is "2.3" do - it "raises a TypeError if class is defined and its superclass mismatches the given one" do - lambda { @s.rb_define_class_id_under(CApiClassSpecs, :Sub, Object) }.should raise_error(TypeError) - end + it "raises a TypeError if class is defined and its superclass mismatches the given one" do + lambda { @s.rb_define_class_id_under(CApiClassSpecs, :Sub, Object) }.should raise_error(TypeError) end end diff --git a/spec/ruby/optional/capi/time_spec.rb b/spec/ruby/optional/capi/time_spec.rb index 7cc1c642b0..4a59c98100 100644 --- a/spec/ruby/optional/capi/time_spec.rb +++ b/spec/ruby/optional/capi/time_spec.rb @@ -258,45 +258,43 @@ describe "CApiTimeSpecs" do end end - ruby_version_is "2.3" do - describe "rb_time_timespec_new" do - it "returns a time object with the given timespec and UTC offset" do - @s.rb_time_timespec_new(1447087832, 476451125, 32400).should == Time.at(1447087832, 476451.125).localtime(32400) - end - - describe "when offset given is within range of -86400 and 86400 (exclusive)" do - it "sets time's is_gmt to false" do - @s.rb_time_timespec_new(1447087832, 476451125, 0).gmt?.should be_false - end + describe "rb_time_timespec_new" do + it "returns a time object with the given timespec and UTC offset" do + @s.rb_time_timespec_new(1447087832, 476451125, 32400).should == Time.at(1447087832, 476451.125).localtime(32400) + end - it "sets time's offset to the offset given" do - @s.rb_time_timespec_new(1447087832, 476451125, 86399).gmtoff.should == 86399 - end + describe "when offset given is within range of -86400 and 86400 (exclusive)" do + it "sets time's is_gmt to false" do + @s.rb_time_timespec_new(1447087832, 476451125, 0).gmt?.should be_false end - it "returns time object in UTC if offset given equals INT_MAX - 1" do - @s.rb_time_timespec_new(1447087832, 476451125, 0x7ffffffe).utc?.should be_true + it "sets time's offset to the offset given" do + @s.rb_time_timespec_new(1447087832, 476451125, 86399).gmtoff.should == 86399 end + end - it "returns time object in localtime if offset given equals INT_MAX" do - @s.rb_time_timespec_new(1447087832, 476451125, 0x7fffffff).should == Time.at(1447087832, 476451.125).localtime - t = Time.now - @s.rb_time_timespec_new(t.tv_sec, t.tv_nsec, 0x7fffffff).gmtoff.should == t.gmtoff - end + it "returns time object in UTC if offset given equals INT_MAX - 1" do + @s.rb_time_timespec_new(1447087832, 476451125, 0x7ffffffe).utc?.should be_true + end - it "raises an ArgumentError if offset passed is not within range of -86400 and 86400 (exclusive)" do - lambda { @s.rb_time_timespec_new(1447087832, 476451125, 86400) }.should raise_error(ArgumentError) - lambda { @s.rb_time_timespec_new(1447087832, 476451125, -86400) }.should raise_error(ArgumentError) - end + it "returns time object in localtime if offset given equals INT_MAX" do + @s.rb_time_timespec_new(1447087832, 476451125, 0x7fffffff).should == Time.at(1447087832, 476451.125).localtime + t = Time.now + @s.rb_time_timespec_new(t.tv_sec, t.tv_nsec, 0x7fffffff).gmtoff.should == t.gmtoff end - describe "rb_timespec_now" do - it "fills a struct timespec with the current time" do - now = Time.now - time = @s.rb_time_from_timespec(now.utc_offset) - time.should be_an_instance_of(Time) - (time - now).should be_close(0, 10) - end + it "raises an ArgumentError if offset passed is not within range of -86400 and 86400 (exclusive)" do + lambda { @s.rb_time_timespec_new(1447087832, 476451125, 86400) }.should raise_error(ArgumentError) + lambda { @s.rb_time_timespec_new(1447087832, 476451125, -86400) }.should raise_error(ArgumentError) + end + end + + describe "rb_timespec_now" do + it "fills a struct timespec with the current time" do + now = Time.now + time = @s.rb_time_from_timespec(now.utc_offset) + time.should be_an_instance_of(Time) + (time - now).should be_close(0, 10) end end end diff --git a/spec/ruby/security/cve_2014_8080_spec.rb b/spec/ruby/security/cve_2014_8080_spec.rb index e12faa6a75..e9d7fd320c 100644 --- a/spec/ruby/security/cve_2014_8080_spec.rb +++ b/spec/ruby/security/cve_2014_8080_spec.rb @@ -24,9 +24,9 @@ describe "REXML::Document.new" do XML - lambda { REXML::Document.new(xml).doctype.entities['x9'].value }.should raise_error(REXML::ParseException) { |e| - e.message.should =~ /entity expansion has grown too large/ - } + lambda { + REXML::Document.new(xml).doctype.entities['x9'].value + }.should raise_error(REXML::ParseException, /entity expansion has grown too large/) end end diff --git a/spec/ruby/security/cve_2017_17742_spec.rb b/spec/ruby/security/cve_2017_17742_spec.rb new file mode 100644 index 0000000000..f1205412c6 --- /dev/null +++ b/spec/ruby/security/cve_2017_17742_spec.rb @@ -0,0 +1,40 @@ +require_relative '../spec_helper' + +require "webrick" +require "stringio" +require "net/http" + +guard -> { + ruby_version_is "2.3.7"..."2.4" or + ruby_version_is "2.4.4"..."2.5" or + ruby_version_is "2.5.1" +} do + describe "WEBrick" do + describe "resists CVE-2017-17742" do + it "for a response splitting headers" do + config = WEBrick::Config::HTTP + res = WEBrick::HTTPResponse.new config + res['X-header'] = "malicious\r\nCookie: hack" + io = StringIO.new + res.send_response io + io.rewind + res = Net::HTTPResponse.read_new(Net::BufferedIO.new(io)) + res.code.should == '500' + io.string.should_not =~ /hack/ + end + + it "for a response splitting cookie headers" do + user_input = "malicious\r\nCookie: hack" + config = WEBrick::Config::HTTP + res = WEBrick::HTTPResponse.new config + res.cookies << WEBrick::Cookie.new('author', user_input) + io = StringIO.new + res.send_response io + io.rewind + res = Net::HTTPResponse.read_new(Net::BufferedIO.new(io)) + res.code.should == '500' + io.string.should_not =~ /hack/ + end + end + end +end diff --git a/spec/ruby/security/cve_2018_6914_spec.rb b/spec/ruby/security/cve_2018_6914_spec.rb new file mode 100644 index 0000000000..657341e474 --- /dev/null +++ b/spec/ruby/security/cve_2018_6914_spec.rb @@ -0,0 +1,59 @@ +require_relative '../spec_helper' + +require 'tempfile' + +guard -> { + ruby_version_is "2.3.7"..."2.4" or + ruby_version_is "2.4.4"..."2.5" or + ruby_version_is "2.5.1" +} do + describe "CVE-2018-6914 is resisted by" do + before :all do + @traversal_path = Array.new(Dir.pwd.split('/').count, '..').join('/') + Dir.pwd + '/' + @traversal_path.delete!(':') if /mswin|mingw/ =~ RUBY_PLATFORM + end + + it "Tempfile.open by deleting separators" do + begin + expect = Dir.glob(@traversal_path + '*').count + t = Tempfile.open([@traversal_path, 'foo']) + actual = Dir.glob(@traversal_path + '*').count + actual.should == expect + ensure + t.close! + end + end + + it "Tempfile.new by deleting separators" do + begin + expect = Dir.glob(@traversal_path + '*').count + t = Tempfile.new(@traversal_path + 'foo') + actual = Dir.glob(@traversal_path + '*').count + actual.should == expect + ensure + t.close! + end + end + + it "Tempfile.create by deleting separators" do + expect = Dir.glob(@traversal_path + '*').count + Tempfile.create(@traversal_path + 'foo') + actual = Dir.glob(@traversal_path + '*').count + actual.should == expect + end + + it "Dir.mktmpdir by deleting separators" do + expect = Dir.glob(@traversal_path + '*').count + Dir.mktmpdir(@traversal_path + 'foo') + actual = Dir.glob(@traversal_path + '*').count + actual.should == expect + end + + it "Dir.mktmpdir with an array by deleting separators" do + expect = Dir.glob(@traversal_path + '*').count + Dir.mktmpdir([@traversal_path, 'foo']) + actual = Dir.glob(@traversal_path + '*').count + actual.should == expect + end + end +end diff --git a/spec/ruby/security/cve_2018_8778_spec.rb b/spec/ruby/security/cve_2018_8778_spec.rb new file mode 100644 index 0000000000..a264a8581e --- /dev/null +++ b/spec/ruby/security/cve_2018_8778_spec.rb @@ -0,0 +1,12 @@ +require_relative '../spec_helper' + +describe "String#unpack" do + + it "resists CVE-2018-8778 by raising an exception when a position indicator is larger than a native integer" do + pos = (1 << PlatformGuard::POINTER_SIZE) - 99 + lambda { + "0123456789".unpack("@#{pos}C10") + }.should raise_error(RangeError, /pack length too big/) + end + +end diff --git a/spec/ruby/security/cve_2018_8779_spec.rb b/spec/ruby/security/cve_2018_8779_spec.rb new file mode 100644 index 0000000000..9659b321ee --- /dev/null +++ b/spec/ruby/security/cve_2018_8779_spec.rb @@ -0,0 +1,30 @@ +require_relative '../spec_helper' + +require 'socket' +require 'tempfile' + +platform_is_not :windows do + describe "CVE-2018-8779 is resisted by" do + before :each do + tmpfile = Tempfile.new("s") + @path = tmpfile.path + tmpfile.close(true) + end + + after :each do + File.unlink @path if @path && File.socket?(@path) + end + + it "UNIXServer.open by raising an exception when there is a NUL byte" do + lambda { + UNIXServer.open(@path+"\0") + }.should raise_error(ArgumentError, /(path name|string) contains null byte/) + end + + it "UNIXSocket.open by raising an exception when there is a NUL byte" do + lambda { + UNIXSocket.open(@path+"\0") + }.should raise_error(ArgumentError, /(path name|string) contains null byte/) + end + end +end diff --git a/spec/ruby/security/cve_2018_8780_spec.rb b/spec/ruby/security/cve_2018_8780_spec.rb new file mode 100644 index 0000000000..44be29bf22 --- /dev/null +++ b/spec/ruby/security/cve_2018_8780_spec.rb @@ -0,0 +1,53 @@ +require_relative '../spec_helper' + +guard -> { + ruby_version_is "2.3.7"..."2.4" or + ruby_version_is "2.4.4"..."2.5" or + ruby_version_is "2.5.1" +} do + describe "CVE-2018-8780 is resisted by" do + before :all do + @root = File.realpath(tmp("")) + end + + it "Dir.glob by raising an exception when there is a NUL byte" do + lambda { + Dir.glob([[@root, File.join(@root, "*")].join("\0")]) + }.should raise_error(ArgumentError, /(path name|string) contains null byte/) + end + + it "Dir.entries by raising an exception when there is a NUL byte" do + lambda { + Dir.entries(@root+"\0") + }.should raise_error(ArgumentError, /(path name|string) contains null byte/) + end + + it "Dir.foreach by raising an exception when there is a NUL byte" do + lambda { + Dir.foreach(@root+"\0").to_a + }.should raise_error(ArgumentError, /(path name|string) contains null byte/) + end + + ruby_version_is "2.5" do + it "Dir.children by raising an exception when there is a NUL byte" do + lambda { + Dir.children(@root+"\0") + }.should raise_error(ArgumentError, /(path name|string) contains null byte/) + end + + it "Dir.each_child by raising an exception when there is a NUL byte" do + lambda { + Dir.each_child(@root+"\0").to_a + }.should raise_error(ArgumentError, /(path name|string) contains null byte/) + end + end + + ruby_version_is "2.4" do + it "Dir.empty? by raising an exception when there is a NUL byte" do + lambda { + Dir.empty?(@root+"\0") + }.should raise_error(ArgumentError, /(path name|string) contains null byte/) + end + end + end +end diff --git a/spec/ruby/shared/basicobject/method_missing.rb b/spec/ruby/shared/basicobject/method_missing.rb index e331d7262f..0759dd9606 100644 --- a/spec/ruby/shared/basicobject/method_missing.rb +++ b/spec/ruby/shared/basicobject/method_missing.rb @@ -111,15 +111,13 @@ describe :method_missing_instance, shared: true do lambda { @object.new.method_private }.should raise_error(NoMethodError) end - ruby_version_is "2.3" do - it 'sets the receiver of the raised NoMethodError' do - obj = @object.new - - begin - obj.method_private - rescue NoMethodError => error - (error.receiver == obj).should == true - end + it 'sets the receiver of the raised NoMethodError' do + obj = @object.new + + begin + obj.method_private + rescue NoMethodError => error + (error.receiver == obj).should == true end end end -- cgit v1.2.3