Created
February 8, 2014 07:30
-
-
Save s-mage/8877983 to your computer and use it in GitHub Desktop.
Find test in cucumber by tag.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TAG_STRING = /(@\w+\W?)+/ | |
EMPTY_STRING = /^\W*$/ | |
def scan_project(dirname, tag) | |
Dir.new(dirname). | |
select { |file| File.extname(file) == '.feature' }. | |
inject('') { |r, f| r << format_file(f, scan_file(f, tag)) } | |
end | |
def format_file(filename, scan_result) | |
scan_result.empty? ? '' : ("\n" << filename << "\n" << scan_result) | |
end | |
def scan_file(filename, tag) | |
return("\n" << File.read(filename)) if tagged_feature?(filename, tag) | |
status = :skip | |
IO.readlines(filename).inject('') do |result, line| | |
case line | |
when TAG_STRING | |
status, processed_line = *process_tag_line(line, tag) | |
result << processed_line | |
when EMPTY_STRING | |
status = :skip | |
result | |
else | |
result << process_regular_line(line, status) | |
end | |
end | |
end | |
def tagged_feature?(filename, tag) | |
has_tag? File.open(filename, &:readline), tag | |
end | |
def process_tag_line(line, tag) | |
has_tag?(line, tag) ? [:read, "\n" << line] : [:skip, ''] | |
end | |
def has_tag?(line, tag) | |
line.split(' ').include?('@' + tag) | |
end | |
def process_regular_line(line, status) | |
status == :skip ? '' : line | |
end | |
dirname, tag = *ARGV | |
Dir.chdir dirname | |
puts scan_project(dirname, tag) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment