Skip to content

Commit

Permalink
(#21971) Fixes PathPattern's usage of Dir.glob for Windows
Browse files Browse the repository at this point in the history
Dir.glob seems to perform an impilicit to_s on what is passed.  Except
on Windows.  This change explicitly converts Pathname to a String, so we
don't have any surprises.
  • Loading branch information
jpartlow committed Aug 7, 2013
1 parent 3932e78 commit a0f8a32
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/puppet/file_system/path_pattern.rb
Expand Up @@ -31,7 +31,7 @@ def prefix_with(prefix)
end

def glob
Dir.glob(pathname)
Dir.glob(pathname.to_s)
end

def to_s
Expand Down
12 changes: 6 additions & 6 deletions spec/unit/module_spec.rb
Expand Up @@ -403,40 +403,40 @@
end

it "should return all manifests matching the glob pattern" do
Dir.expects(:glob).with(Pathname.new(@fq_glob_with_extension)).returns(%w{foo bar})
Dir.expects(:glob).with(@fq_glob_with_extension).returns(%w{foo bar})
FileTest.stubs(:directory?).returns false

@mod.match_manifests(@pq_glob_with_extension).should == %w{foo bar}
end

it "should not return directories" do
Dir.expects(:glob).with(Pathname.new(@fq_glob_with_extension)).returns(%w{foo bar})
Dir.expects(:glob).with(@fq_glob_with_extension).returns(%w{foo bar})

FileTest.expects(:directory?).with("foo").returns false
FileTest.expects(:directory?).with("bar").returns true
@mod.match_manifests(@pq_glob_with_extension).should == %w{foo}
end

it "should default to the 'init' file if no glob pattern is specified" do
Dir.expects(:glob).with(Pathname.new("/a/manifests/init.{pp,rb}")).returns(%w{/a/manifests/init.pp})
Dir.expects(:glob).with("/a/manifests/init.{pp,rb}").returns(%w{/a/manifests/init.pp})

@mod.match_manifests(nil).should == %w{/a/manifests/init.pp}
end

it "should return all manifests matching the glob pattern in all existing paths" do
Dir.expects(:glob).with(Pathname.new(@fq_glob_with_extension)).returns(%w{a b})
Dir.expects(:glob).with(@fq_glob_with_extension).returns(%w{a b})

@mod.match_manifests(@pq_glob_with_extension).should == %w{a b}
end

it "should match the glob pattern plus '.{pp,rb}' if no extention is specified" do
Dir.expects(:glob).with(Pathname.new("/a/manifests/yay/foo.{pp,rb}")).returns(%w{yay})
Dir.expects(:glob).with("/a/manifests/yay/foo.{pp,rb}").returns(%w{yay})

@mod.match_manifests("yay/foo").should == %w{yay}
end

it "should return an empty array if no manifests matched" do
Dir.expects(:glob).with(Pathname.new(@fq_glob_with_extension)).returns([])
Dir.expects(:glob).with(@fq_glob_with_extension).returns([])

@mod.match_manifests(@pq_glob_with_extension).should == []
end
Expand Down

0 comments on commit a0f8a32

Please sign in to comment.