Skip to content

Commit

Permalink
Close opened file handle in #from_filename
Browse files Browse the repository at this point in the history
We can use the block form of `File.open` to accomplish that.
  • Loading branch information
martinandert committed Aug 24, 2017
1 parent 60a4c02 commit 77b136c
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 77b136c

Please sign in to comment.