Skip to content

Commit 6d9efff

Browse files
authored
Merge pull request #655 from Soobrakay/master
#542 Using Dir[]
2 parents 56f47d4 + 422bac0 commit 6d9efff

File tree

5 files changed

+30
-4
lines changed

5 files changed

+30
-4
lines changed

lib/thor/actions/directory.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class Directory < EmptyDirectory #:nodoc:
5656
attr_reader :source
5757

5858
def initialize(base, source, destination = nil, config = {}, &block)
59-
@source = File.expand_path(base.find_in_source_paths(source.to_s))
59+
@source = File.expand_path(Dir[Util.escape_globs(base.find_in_source_paths(source.to_s))].first)
6060
@block = block
6161
super(base, destination, {:recursive => true}.merge(config))
6262
end

spec/actions/create_link_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
require "thor/actions"
33
require "tempfile"
44

5-
describe Thor::Actions::CreateLink do
5+
describe Thor::Actions::CreateLink, :unless => windows? do
66
before do
77
@silence = false
88
@hardlink_to = File.join(Dir.tmpdir, "linkdest.rb")

spec/actions/directory_spec.rb

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
require "tmpdir"
12
require "helper"
23
require "thor/actions"
34

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

2627
def exists_and_identical?(source_path, destination_path)
2728
%w(config.rb README).each do |file|
28-
source = File.join(source_root, source_path, file)
29+
source = File.join(source_root, source_path, file)
2930
destination = File.join(destination_root, destination_path, file)
3031

3132
expect(File.exist?(destination)).to be true
@@ -146,6 +147,24 @@ def exists_and_identical?(source_path, destination_path)
146147
content = invoke!("app{1}")
147148
expect(content).to match(%r{create app\{1\}/README})
148149
end
150+
151+
context "windows temp directories", :if => windows? do
152+
let(:spec_dir) { File.join(@temp_dir, "spec") }
153+
154+
before(:each) do
155+
@temp_dir = Dir.mktmpdir("thor")
156+
Dir.mkdir(spec_dir)
157+
File.new(File.join(spec_dir, "spec_helper.rb"), "w").close
158+
end
159+
160+
after(:each) { FileUtils.rm_rf(@temp_dir) }
161+
it "works with windows temp dir" do
162+
invoke! spec_dir, "specs"
163+
file = File.join(destination_root, "specs")
164+
expect(File.exist?(file)).to be true
165+
expect(File.directory?(file)).to be true
166+
end
167+
end
149168
end
150169

151170
describe "#revoke!" do

spec/actions/file_manipulation_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def file
9696
end
9797
end
9898

99-
describe "#link_file" do
99+
describe "#link_file", :unless => windows? do
100100
it "links file from source to default destination" do
101101
action :link_file, "command.thor"
102102
exists_and_identical?("command.thor", "command.thor")

spec/helper.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,5 +76,12 @@ def silence_warnings
7676
$VERBOSE = old_verbose
7777
end
7878

79+
# true if running on windows, used for conditional spec skips
80+
#
81+
# @return [TrueClass/FalseClass]
82+
def windows?
83+
Gem.win_platform?
84+
end
85+
7986
alias silence capture
8087
end

0 commit comments

Comments
 (0)