diff --git a/.circleci/config.yml b/.circleci/config.yml index 803997f..f296eb2 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,6 +1,6 @@ version: 2.1 orbs: - ruby: circleci/ruby@1.1.2 + ruby: circleci/ruby@1.2.0 references: unit: &unit run: @@ -45,6 +45,17 @@ jobs: - ruby/install-deps - <<: *unit + "ruby-3-1": + docker: + - image: 'cimg/base:stable' + steps: + - checkout + - ruby/install: + version: '3.1.0-preview1' + - run: ruby -v + - ruby/install-deps + - <<: *unit + "lint": docker: - image: circleci/ruby:3.0 @@ -61,4 +72,5 @@ workflows: - "ruby-2-6" - "ruby-2-7" - "ruby-3-0" + - "ruby-3-1" - "lint" diff --git a/CHANGELOG.md b/CHANGELOG.md index ac88977..64b3821 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ## HEAD (unreleased) +- Add support for Ruby 3.1 by updating `require_relative` logic (https://github.com/zombocom/dead_end/pull/120) - Requiring `dead_end/auto` is now deprecated please require `dead_end` instead (https://github.com/zombocom/dead_end/pull/119) - Requiring `dead_end/api` now loads code without monkeypatching core extensions (https://github.com/zombocom/dead_end/pull/119) - The interface `DeadEnd.handle_error` is declared public and stable (https://github.com/zombocom/dead_end/pull/119) diff --git a/lib/dead_end/core_ext.rb b/lib/dead_end/core_ext.rb index c89abd5..2886785 100644 --- a/lib/dead_end/core_ext.rb +++ b/lib/dead_end/core_ext.rb @@ -25,7 +25,9 @@ def require_relative(file) if Pathname.new(file).absolute? dead_end_original_require file else - dead_end_original_require File.expand_path("../#{file}", Kernel.caller_locations(1, 1)[0].absolute_path) + relative_from = caller_locations(1..1).first + relative_from_path = relative_from.absolute_path || relative_from.path + dead_end_original_require File.expand_path("../#{file}", relative_from_path) end rescue SyntaxError => e DeadEnd.handle_error(e) diff --git a/spec/integration/ruby_command_line_spec.rb b/spec/integration/ruby_command_line_spec.rb index df82dca..e124287 100644 --- a/spec/integration/ruby_command_line_spec.rb +++ b/spec/integration/ruby_command_line_spec.rb @@ -24,15 +24,22 @@ module DeadEnd Process.wait(d_pid) Process.wait(r_pid) - dead_end_methods_array = dead_end_methods_file.read.strip.lines.map(&:strip) kernel_methods_array = kernel_methods_file.read.strip.lines.map(&:strip) + dead_end_methods_array = dead_end_methods_file.read.strip.lines.map(&:strip) api_only_methods_array = api_only_methods_file.read.strip.lines.map(&:strip) + # In ruby 3.1.0-preview1 the `timeout` file is already required + # we can remove it if it exists to normalize the output for + # all ruby versions + [dead_end_methods_array, kernel_methods_array, api_only_methods_array].each do |array| + array.delete("timeout") + end + methods = (dead_end_methods_array - kernel_methods_array).sort - expect(methods).to eq(["dead_end_original_load", "dead_end_original_require", "dead_end_original_require_relative", "timeout"]) + expect(methods).to eq(["dead_end_original_load", "dead_end_original_require", "dead_end_original_require_relative"]) methods = (api_only_methods_array - kernel_methods_array).sort - expect(methods).to eq(["timeout"]) + expect(methods).to eq([]) end end