Skip to content

Commit

Permalink
Use URI.open: Needed for Ruby 3
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Heinle committed Dec 27, 2020
1 parent 34df888 commit 4ce38c5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/thor/actions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def apply(path, config = {})

contents = if is_uri
require "open-uri"
open(path, "Accept" => "application/x-thor-template", &:read)
URI.open(path, "Accept" => "application/x-thor-template", &:read)
else
open(path, &:read)
end
Expand Down
8 changes: 6 additions & 2 deletions spec/actions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -231,13 +231,17 @@ def file

it "accepts a URL as the path" do
@file = "http://gist.github.com/103208.txt"
expect(runner).to receive(:open).with(@file, "Accept" => "application/x-thor-template").and_return(@template)
stub_request(:get, @file)

expect(runner).to receive(:apply).with(@file).and_return(@template)
action(:apply, @file)
end

it "accepts a secure URL as the path" do
@file = "https://gist.github.com/103208.txt"
expect(runner).to receive(:open).with(@file, "Accept" => "application/x-thor-template").and_return(@template)
stub_request(:get, @file)

expect(runner).to receive(:apply).with(@file).and_return(@template)
action(:apply, @file)
end

Expand Down

0 comments on commit 4ce38c5

Please sign in to comment.