Skip to content

#542 Using Dir[] #655

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from Sep 12, 2019
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
2 changes: 1 addition & 1 deletion lib/thor/actions/directory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class Directory < EmptyDirectory #:nodoc:
attr_reader :source

def initialize(base, source, destination = nil, config = {}, &block)
@source = File.expand_path(base.find_in_source_paths(source.to_s))
@source = File.expand_path(Dir[Util.escape_globs(base.find_in_source_paths(source.to_s))].first)
@block = block
super(base, destination, {:recursive => true}.merge(config))
end
Expand Down
2 changes: 1 addition & 1 deletion spec/actions/create_link_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
require "thor/actions"
require "tempfile"

describe Thor::Actions::CreateLink do
describe Thor::Actions::CreateLink, :unless => windows? do
before do
@silence = false
@hardlink_to = File.join(Dir.tmpdir, "linkdest.rb")
Expand Down
21 changes: 20 additions & 1 deletion spec/actions/directory_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require "tmpdir"
require "helper"
require "thor/actions"

Expand Down Expand Up @@ -25,7 +26,7 @@ def revoke!(*args, &block)

def exists_and_identical?(source_path, destination_path)
%w(config.rb README).each do |file|
source = File.join(source_root, source_path, file)
source = File.join(source_root, source_path, file)
destination = File.join(destination_root, destination_path, file)

expect(File.exist?(destination)).to be true
Expand Down Expand Up @@ -146,6 +147,24 @@ def exists_and_identical?(source_path, destination_path)
content = invoke!("app{1}")
expect(content).to match(%r{create app\{1\}/README})
end

context "windows temp directories", :if => windows? do
let(:spec_dir) { File.join(@temp_dir, "spec") }

before(:each) do
@temp_dir = Dir.mktmpdir("thor")
Dir.mkdir(spec_dir)
File.new(File.join(spec_dir, "spec_helper.rb"), "w").close
end

after(:each) { FileUtils.rm_rf(@temp_dir) }
it "works with windows temp dir" do
invoke! spec_dir, "specs"
file = File.join(destination_root, "specs")
expect(File.exist?(file)).to be true
expect(File.directory?(file)).to be true
end
end
end

describe "#revoke!" do
Expand Down
2 changes: 1 addition & 1 deletion spec/actions/file_manipulation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def file
end
end

describe "#link_file" do
describe "#link_file", :unless => windows? do
it "links file from source to default destination" do
action :link_file, "command.thor"
exists_and_identical?("command.thor", "command.thor")
Expand Down
7 changes: 7 additions & 0 deletions spec/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,12 @@ def silence_warnings
$VERBOSE = old_verbose
end

# true if running on windows, used for conditional spec skips
#
# @return [TrueClass/FalseClass]
def windows?
Gem.win_platform?
end

alias silence capture
end