Class: Gherkin::Formatter::FilterFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/gherkin/formatter/filter_formatter.rb

Instance Method Summary collapse

Constructor Details

#initialize(formatter, filters) ⇒ FilterFormatter

Returns a new instance of FilterFormatter



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/gherkin/formatter/filter_formatter.rb', line 13

def initialize(formatter, filters)
  @formatter = formatter
  @filter    = detect_filter(filters)

  @feature_tags           = []
  @feature_element_tags   = []
  @examples_tags          = []
  @examples_range         = []
  @feature_events         = []
  @background_events      = []
  @feature_element_events = []
  @examples_events        = []

  @examples_name          = nil
  @feature_element_name   = nil
  @feature_element_range  = nil
end

Instance Method Details

#background(background) ⇒ Object



41
42
43
44
45
# File 'lib/gherkin/formatter/filter_formatter.rb', line 41

def background(background)
  @feature_element_name   = background.name
  @feature_element_range  = background.line_range
  @background_events      = [background]
end

#doneObject



96
97
98
# File 'lib/gherkin/formatter/filter_formatter.rb', line 96

def done
  @formatter.done
end

#eofObject



91
92
93
94
# File 'lib/gherkin/formatter/filter_formatter.rb', line 91

def eof
  replay!
  @formatter.eof
end

#examples(examples) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/gherkin/formatter/filter_formatter.rb', line 63

def examples(examples)
  replay!
  @examples_tags = examples.tags
  @examples_name = examples.name

  table_body_range = case(examples.rows.length)
    when 0 then examples.line_range.last..examples.line_range.last
    when 1 then examples.rows[0].line..examples.rows[0].line
    else examples.rows[1].line..examples.rows[-1].line
  end

  @examples_range = examples.line_range.first..table_body_range.last
  if(@filter.evaluate([], [], [table_body_range]))
    examples.rows = @filter.filter_table_body_rows(examples.rows)
  end
  @examples_events = [examples]
end

#feature(feature) ⇒ Object



35
36
37
38
39
# File 'lib/gherkin/formatter/filter_formatter.rb', line 35

def feature(feature)
  @feature_tags   = feature.tags
  @feature_name   = feature.name
  @feature_events = [feature]
end

#scenario(scenario) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/gherkin/formatter/filter_formatter.rb', line 47

def scenario(scenario)
  replay!
  @feature_element_tags   = scenario.tags
  @feature_element_name   = scenario.name
  @feature_element_range  = scenario.line_range
  @feature_element_events = [scenario]
end

#scenario_outline(scenario_outline) ⇒ Object



55
56
57
58
59
60
61
# File 'lib/gherkin/formatter/filter_formatter.rb', line 55

def scenario_outline(scenario_outline)
  replay!
  @feature_element_tags   = scenario_outline.tags
  @feature_element_name   = scenario_outline.name
  @feature_element_range  = scenario_outline.line_range
  @feature_element_events = [scenario_outline]
end

#step(step) ⇒ Object



81
82
83
84
85
86
87
88
89
# File 'lib/gherkin/formatter/filter_formatter.rb', line 81

def step(step)
  if @feature_element_events.any?
    @feature_element_events << step
  else
    @background_events << step
  end

  @feature_element_range = @feature_element_range.first..step.line_range.last
end

#uri(uri) ⇒ Object



31
32
33
# File 'lib/gherkin/formatter/filter_formatter.rb', line 31

def uri(uri)
  @formatter.uri(uri)
end