Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
version: 2.1
orbs:
ruby: circleci/ruby@1.1.2
ruby: circleci/ruby@1.2.0
references:
unit: &unit
run:
Expand Down Expand Up @@ -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
Expand All @@ -61,4 +72,5 @@ workflows:
- "ruby-2-6"
- "ruby-2-7"
- "ruby-3-0"
- "ruby-3-1"
- "lint"
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
4 changes: 3 additions & 1 deletion lib/dead_end/core_ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 10 additions & 3 deletions spec/integration/ruby_command_line_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down