Class: CucumberTags::TagsHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/cucumber_tags/cucumber_tags.rb

Overview

search for tags and filter the files

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(files, tags) ⇒ TagsHelper

Returns a new instance of TagsHelper.



8
9
10
11
12
# File 'lib/cucumber_tags/cucumber_tags.rb', line 8

def initialize(files, tags)
  @feature_files = files
  @tags = tags.strip.tr('\"', '').split(' and ')
  @filtered_feature = []
end

Instance Attribute Details

#filtered_featureObject (readonly)

Returns the value of attribute filtered_feature.



6
7
8
# File 'lib/cucumber_tags/cucumber_tags.rb', line 6

def filtered_feature
  @filtered_feature
end

Instance Method Details

#filter_featureObject

rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/cucumber_tags/cucumber_tags.rb', line 27

def filter_feature
  @feature_files.each do |file|
    find = false
    gherkin_document = Gherkin::Parser.new.parse(File.read(file))
    feature_tags = node_tags(gherkin_document[:feature])
    gherkin_document[:feature][:children].each do |child|
      next if child[:type] == :Background
      break if find

      tags = node_tags(child) + feature_tags
      next if not_allowed_tags.any? { |x| tags.include? x }

      if child[:type] == :ScenarioOutline
        child[:examples].each do |example|
          child_tags = node_tags(example) + tags
          next if not_allowed_tags.any? { |x| child_tags.include? x }

          next unless required_tags - child_tags == []

          find = true
          @filtered_feature << file
          break
        end
      elsif required_tags - tags == []
        @filtered_feature << file
        break
      end
    end
  end
end

#node_tags(node) ⇒ Object



22
23
24
# File 'lib/cucumber_tags/cucumber_tags.rb', line 22

def node_tags(node)
  node[:tags].map { |x| x[:name] }
end

#not_allowed_tagsObject



18
19
20
# File 'lib/cucumber_tags/cucumber_tags.rb', line 18

def not_allowed_tags
  @not_allowed_tags = @tags.filter { |x| x if x.include? 'not' }
end

#required_tagsObject



14
15
16
# File 'lib/cucumber_tags/cucumber_tags.rb', line 14

def required_tags
  @required_tags = @tags.filter { |x| x unless x.include? 'not' }
end