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.
Class Method Details
.append_line_numbers_to_path(line_numbers, path) ⇒ String
Appends the line numbers to the path
72 73 74 75 76 |
# File 'lib/guard/cucumber/focuser.rb', line 72 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
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/guard/cucumber/focuser.rb', line 52 def scan_path_for_focus_tag(path, focus_tag) line_numbers = [] File.open(path, 'r') do |f| while (line = f.gets) if line.include?(focus_tag) line_numbers << f.lineno end end end line_numbers end |