Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scan_for_focus_path should return an empty array if path is a directory #7

Merged
merged 1 commit into from
Jan 7, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/guard/cucumber/focuser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def focus(paths, focus_tag)
end

# Checks to see if the file at path contains the focus tag
# It will return an empty array if the path is a directory.
#
# @param [String] path the file path to search
# @param [String] focus_tag the focus tag to look for in each path
Expand All @@ -52,6 +53,8 @@ def focus(paths, focus_tag)
def scan_path_for_focus_tag(path, focus_tag)
line_numbers = []

return line_numbers if File.directory?(path)

File.open(path, 'r') do |f|
while (line = f.gets)
if line.include?(focus_tag)
Expand Down
11 changes: 11 additions & 0 deletions spec/guard/cucumber/focuser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,17 @@
focuser.scan_path_for_focus_tag(path, focus_tag).should eql([])
end
end

context 'file that is a directory' do
before do
File.should_receive(:directory?).with(dir).and_return(true)
end

it 'returns an empty array' do
focuser.scan_path_for_focus_tag(dir, focus_tag).should eql([])
end
end

end

describe '#append_line_numbers_to_path' do
Expand Down