Class: Gherkin::Formatter::FilterFormatter

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

Instance Method Summary collapse

Methods included from Rubify

#rubify

Constructor Details

#initialize(formatter, filters) ⇒ FilterFormatter

Returns a new instance of FilterFormatter.



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

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


  @feature_tags           = []
  @feature_element_tags   = []
  @examples_tags          = []

  @feature_events         = []
  @background_events      = []
  @feature_element_events = []
  @examples_events        = []
end

Instance Method Details

#background(statement) ⇒ Object



33
34
35
36
37
# File 'lib/gherkin/formatter/filter_formatter.rb', line 33

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

#eofObject



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

def eof
  replay!
  @formatter.eof
end

#examples(statement, examples_rows) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/gherkin/formatter/filter_formatter.rb', line 57

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

  table_body_range = examples_rows.to_a[1].line..examples_rows.to_a[-1].line
  @examples_range = statement.line_range.first..table_body_range.last
  if(LineFilter === @filter && @filter.eval([table_body_range]))
    examples_rows = @filter.filter_table_body_rows(examples_rows)
  end
  @examples_events = [[:examples, statement, examples_rows]]
end

#feature(statement, uri) ⇒ Object



27
28
29
30
31
# File 'lib/gherkin/formatter/filter_formatter.rb', line 27

def feature(statement, uri)
  @feature_tags   = statement.tags
  @feature_name   = statement.name
  @feature_events = [[:feature, statement, uri]]
end

#scenario(statement) ⇒ Object



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

def scenario(statement)
  replay!
  @feature_element_tags   = statement.tags
  @feature_element_name   = statement.name
  @feature_element_range  = statement.line_range
  @feature_element_events = [[:scenario, statement]]
  @examples_events.clear
end

#scenario_outline(statement) ⇒ Object



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

def scenario_outline(statement)
  replay!
  @feature_element_tags   = statement.tags
  @feature_element_name   = statement.name
  @feature_element_range  = statement.line_range
  @feature_element_events = [[:scenario_outline, statement]]
  @examples_events.clear
end

#step(statement, multiline_arg, result) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/gherkin/formatter/filter_formatter.rb', line 70

def step(statement, multiline_arg, result)
  args = [:step, statement, multiline_arg, result]
  if @feature_element_events.any?
    @feature_element_events << args
  else
    @background_events << args
  end

  if LineFilter === @filter
    step_range = statement.line_range
    case rubify(multiline_arg)
    when Model::PyString
      step_range = step_range.first..multiline_arg.line_range.last
    when Array
      step_range = step_range.first..multiline_arg.to_a[-1].line
    end
    @feature_element_range = @feature_element_range.first..step_range.last
  end
end