Class: Cucumber::Filter

Inherits:
Object show all
Defined in:
lib/cucumber/filter.rb

Instance Method Summary collapse

Constructor Details

#initialize(lines, options) ⇒ Filter

Returns a new instance of Filter.



3
4
5
6
7
8
9
# File 'lib/cucumber/filter.rb', line 3

def initialize(lines, options)
  @lines = lines

  @include_tags = options[:include_tags] ? options[:include_tags].keys : []
  @exclude_tags = options[:exclude_tags] ? options[:exclude_tags].keys : []
  @name_regexps = options[:name_regexps] || []
end

Instance Method Details

#accept?(syntax_node) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
14
15
# File 'lib/cucumber/filter.rb', line 11

def accept?(syntax_node)
  at_line?(syntax_node) &&
  matches_tags?(syntax_node) &&
  matches_names?(syntax_node)
end

#accept_example?(syntax_node, outline) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
20
# File 'lib/cucumber/filter.rb', line 17

def accept_example?(syntax_node, outline)
  (at_line?(syntax_node) || outline_at_line?(outline)) &&
  (matches_names?(syntax_node) || outline_matches_names?(outline))
end

#at_line?(syntax_node) ⇒ Boolean

Returns:

  • (Boolean)


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

def at_line?(syntax_node)
  @lines.nil? || @lines.empty? || @lines.detect{|line| syntax_node.at_line?(line)}
end

#excluded_by_tags?(syntax_node) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/cucumber/filter.rb', line 39

def excluded_by_tags?(syntax_node)
  @exclude_tags.any? && syntax_node.has_tags?(@exclude_tags)
end

#included_by_tags?(syntax_node) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/cucumber/filter.rb', line 35

def included_by_tags?(syntax_node)
  @include_tags.empty? || syntax_node.has_all_tags?(@include_tags)
end

#matches_names?(syntax_node) ⇒ Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/cucumber/filter.rb', line 47

def matches_names?(syntax_node)
  @name_regexps.nil? || @name_regexps.empty? || @name_regexps.detect{|name_regexp| syntax_node.matches_name?(name_regexp)}
end

#matches_tags?(syntax_node) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
33
# File 'lib/cucumber/filter.rb', line 30

def matches_tags?(syntax_node)
  !excluded_by_tags?(syntax_node) &&
  included_by_tags?(syntax_node)
end

#outline_at_line?(syntax_node) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/cucumber/filter.rb', line 26

def outline_at_line?(syntax_node)
   @lines.nil? || @lines.empty? || @lines.detect{|line| syntax_node.outline_at_line?(line)}
end

#outline_matches_names?(syntax_node) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/cucumber/filter.rb', line 43

def outline_matches_names?(syntax_node)
  @name_regexps.nil? || @name_regexps.empty? || @name_regexps.detect{|name_regexp| syntax_node.outline_matches_name?(name_regexp)}
end