diff --git a/lib/pathspec.rb b/lib/pathspec.rb index 5293336..70aa73b 100644 --- a/lib/pathspec.rb +++ b/lib/pathspec.rb @@ -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) diff --git a/spec/unit/pathspec_spec.rb b/spec/unit/pathspec_spec.rb index 91361a2..9b04a19 100644 --- a/spec/unit/pathspec_spec.rb +++ b/spec/unit/pathspec_spec.rb @@ -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