Skip to content

Commit

Permalink
Merge pull request #655 from Soobrakay/master
Browse files Browse the repository at this point in the history
#542 Using Dir[]
  • Loading branch information
rafaelfranca committed Sep 12, 2019
2 parents 56f47d4 + 422bac0 commit 6d9efff
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 4 deletions.
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 @@ -76,5 +76,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

0 comments on commit 6d9efff

Please sign in to comment.