diff --git a/lib/thor/actions.rb b/lib/thor/actions.rb index 552eb135c..bc8d56ffc 100644 --- a/lib/thor/actions.rb +++ b/lib/thor/actions.rb @@ -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 diff --git a/spec/actions_spec.rb b/spec/actions_spec.rb index 47416e148..904881ce9 100644 --- a/spec/actions_spec.rb +++ b/spec/actions_spec.rb @@ -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