Module: Guard::Cucumber::Focuser
- Defined in:
- lib/guard/cucumber/focuser.rb
Overview
The Cucumber focuser updates cucumber feature paths to focus on sections tagged with a provided focus_tag.
For example, if the ‘foo.feature` file has the provided focus tag `@bar` on line 8, then the path will be updated using the cucumber syntax for focusing on a section:
foo.feature:8
If ‘@bar’ is found on lines 8 and 16, the path is updated as follows:
foo.feature:8:16
The path is not updated if it does not contain the focus tag.
Class Method Summary collapse
-
.append_line_numbers_to_path(line_numbers, path) ⇒ String
Appends the line numbers to the path.
-
.focus(paths, focus_tag) ⇒ Array<String>
Focus the supplied paths using the provided focus tag.
-
.scan_path_for_focus_tag(path, focus_tag) ⇒ Array<Integer>
Checks to see if the file at path contains the focus tag It will return an empty array if the path is a directory.
Class Method Details
.append_line_numbers_to_path(line_numbers, path) ⇒ String
Appends the line numbers to the path
75 76 77 78 79 |
# File 'lib/guard/cucumber/focuser.rb', line 75 def append_line_numbers_to_path(line_numbers, path) line_numbers.each { |num| path += ':' + num.to_s } path end |
.focus(paths, focus_tag) ⇒ Array<String>
Focus the supplied paths using the provided focus tag.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/guard/cucumber/focuser.rb', line 28 def focus(paths, focus_tag) return false if paths.empty? paths.inject([]) do |updated_paths, path| focused_line_numbers = scan_path_for_focus_tag(path, focus_tag) unless focused_line_numbers.empty? updated_paths << append_line_numbers_to_path( focused_line_numbers, path ) else updated_paths << path end updated_paths end end |
.scan_path_for_focus_tag(path, focus_tag) ⇒ Array<Integer>
Checks to see if the file at path contains the focus tag It will return an empty array if the path is a directory.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/guard/cucumber/focuser.rb', line 53 def scan_path_for_focus_tag(path, focus_tag) return [] if File.directory?(path) || path.include?(':') line_numbers = [] File.open(path, 'r') do |file| while (line = file.gets) if line.include?(focus_tag) line_numbers << file.lineno end end end line_numbers end |