Skip to content

Commit

Permalink
Merge pull request #13 from martinandert/close-file-handle
Browse files Browse the repository at this point in the history
Close opened file handle in #from_filename
  • Loading branch information
highb committed Aug 29, 2017
2 parents 60a4c02 + 77b136c commit 98880f5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/pathspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def drive_letter_to_path(path)

# Generate specs from a filename, such as a .gitignore
def self.from_filename(filename, type=:git)
self.from_lines(File.open(filename, 'r'), type)
File.open(filename, 'r') { |io| self.from_lines(io, type) }
end

def self.from_lines(lines, type=:git)
Expand Down
6 changes: 4 additions & 2 deletions spec/unit/pathspec_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,10 @@

context "#from_filename" do
it "forwards the type argument" do
expect(File).to receive(:open).and_return(anything)
expect(PathSpec).to receive(:from_lines).with(anything, :regex)
io = double

expect(File).to receive(:open).and_yield(io)
expect(PathSpec).to receive(:from_lines).with(io, :regex)

PathSpec.from_filename "/some/file", :regex
end
Expand Down

0 comments on commit 98880f5

Please sign in to comment.