Class: Cucumber::Formatter::Json
- Inherits:
-
Object
- Object
- Cucumber::Formatter::Json
show all
- Includes:
- Io
- Defined in:
- lib/cucumber/formatter/json.rb
Overview
The formatter used for --format json
Defined Under Namespace
Classes: Error
Instance Method Summary
collapse
-
#after_background(background) ⇒ Object
-
#after_feature_element(feature_element) ⇒ Object
-
#after_features(features) ⇒ Object
-
#after_step(step) ⇒ Object
-
#after_table_row(row) ⇒ Object
-
#before_background(background) ⇒ Object
-
#before_examples(examples) ⇒ Object
-
#before_feature(feature) ⇒ Object
-
#before_feature_element(feature_element) ⇒ Object
-
#before_features(features) ⇒ Object
-
#before_outline_table(*args) ⇒ Object
-
#before_step(step) ⇒ Object
-
#before_step_result(keyword, step_match, multiline_arg, status, exception, source_indent, background) ⇒ Object
-
#before_steps(steps) ⇒ Object
-
#before_table_row(row) ⇒ Object
-
#before_tags(tags) ⇒ Object
-
#embed(file, mime_type) ⇒ Object
-
#examples_name(keyword, name) ⇒ Object
-
#initialize(step_mother, io, options) ⇒ Json
constructor
-
#py_string(string) ⇒ Object
-
#scenario_name(keyword, name, file_colon_line, source_indent) ⇒ Object
-
#step_name(keyword, step_match, status, source_indent, background) ⇒ Object
-
#table_cell_value(value, status) ⇒ Object
Methods included from Io
#ensure_dir, #ensure_file, #ensure_io
Constructor Details
#initialize(step_mother, io, options) ⇒ Json
Returns a new instance of Json.
13
14
15
16
|
# File 'lib/cucumber/formatter/json.rb', line 13
def initialize(step_mother, io, options)
@io = ensure_io(io, "json")
@options = options
end
|
Instance Method Details
#after_background(background) ⇒ Object
37
38
39
|
# File 'lib/cucumber/formatter/json.rb', line 37
def after_background(background)
@current_object = last_feature
end
|
#after_feature_element(feature_element) ⇒ Object
120
121
122
123
|
# File 'lib/cucumber/formatter/json.rb', line 120
def after_feature_element(feature_element)
@current_object = last_feature
end
|
#after_features(features) ⇒ Object
125
126
127
128
|
# File 'lib/cucumber/formatter/json.rb', line 125
def after_features(features)
@io.write json_string
@io.flush
end
|
#after_step(step) ⇒ Object
77
78
79
|
# File 'lib/cucumber/formatter/json.rb', line 77
def after_step(step)
@current_step = nil
end
|
#after_table_row(row) ⇒ Object
109
110
111
112
113
114
|
# File 'lib/cucumber/formatter/json.rb', line 109
def after_table_row(row)
if row.exception
@current_row[:exception] = exception_hash_for(row.exception)
end
@current_row = nil
end
|
#before_background(background) ⇒ Object
31
32
33
34
35
|
# File 'lib/cucumber/formatter/json.rb', line 31
def before_background(background)
background = {}
@current_object[:background] = background
@current_object = background
end
|
#before_examples(examples) ⇒ Object
81
82
83
|
# File 'lib/cucumber/formatter/json.rb', line 81
def before_examples(examples)
@current_object[:examples] = {}
end
|
#before_feature(feature) ⇒ Object
22
23
24
25
|
# File 'lib/cucumber/formatter/json.rb', line 22
def before_feature(feature)
@current_object = {:file => feature.file, :name => feature.name}
@json[:features] << @current_object
end
|
#before_feature_element(feature_element) ⇒ Object
41
42
43
44
45
46
47
|
# File 'lib/cucumber/formatter/json.rb', line 41
def before_feature_element(feature_element)
elements = @current_object[:elements] ||= []
@current_object = {}
elements << @current_object
end
|
#before_features(features) ⇒ Object
18
19
20
|
# File 'lib/cucumber/formatter/json.rb', line 18
def before_features(features)
@json = {:features => []}
end
|
#before_outline_table(*args) ⇒ Object
89
90
91
|
# File 'lib/cucumber/formatter/json.rb', line 89
def before_outline_table(*args)
@current_object[:examples][:table] = []
end
|
#before_step(step) ⇒ Object
59
60
61
62
|
# File 'lib/cucumber/formatter/json.rb', line 59
def before_step(step)
@current_step = {}
@current_object[:steps] << @current_step
end
|
#before_step_result(keyword, step_match, multiline_arg, status, exception, source_indent, background) ⇒ Object
64
65
66
67
68
|
# File 'lib/cucumber/formatter/json.rb', line 64
def before_step_result(keyword, step_match, multiline_arg, status, exception, source_indent, background)
if exception
@current_step[:exception] = exception_hash_for(exception)
end
end
|
#before_steps(steps) ⇒ Object
55
56
57
|
# File 'lib/cucumber/formatter/json.rb', line 55
def before_steps(steps)
@current_object[:steps] = []
end
|
#before_table_row(row) ⇒ Object
93
94
95
96
97
98
99
100
101
102
103
|
# File 'lib/cucumber/formatter/json.rb', line 93
def before_table_row(row)
@current_row = {:cells => []}
if @current_object.member? :examples
@current_object[:examples][:table] << @current_row
elsif @current_step
(@current_step[:table] ||= []) << @current_row
else
internal_error
end
end
|
27
28
29
|
# File 'lib/cucumber/formatter/json.rb', line 27
def before_tags(tags)
@current_object[:tags] = tags.tag_names.to_a
end
|
#embed(file, mime_type) ⇒ Object
130
131
132
133
134
135
136
137
138
139
|
# File 'lib/cucumber/formatter/json.rb', line 130
def embed(file, mime_type)
obj = @current_step || @current_object
obj[:embedded] ||= []
obj[:embedded] << {
:file => file,
:mime_type => mime_type,
:data => [File.read(file)].pack("m*") }
end
|
#examples_name(keyword, name) ⇒ Object
85
86
87
|
# File 'lib/cucumber/formatter/json.rb', line 85
def examples_name(keyword, name)
@current_object[:examples][:name] = "#{keyword} #{name}"
end
|
#py_string(string) ⇒ Object
116
117
118
|
# File 'lib/cucumber/formatter/json.rb', line 116
def py_string(string)
@current_step[:py_string] = string
end
|
#scenario_name(keyword, name, file_colon_line, source_indent) ⇒ Object
49
50
51
52
53
|
# File 'lib/cucumber/formatter/json.rb', line 49
def scenario_name(keyword, name, file_colon_line, source_indent)
@current_object[:keyword] = keyword
@current_object[:name] = name
@current_object[:file_colon_line] = file_colon_line
end
|
#step_name(keyword, step_match, status, source_indent, background) ⇒ Object
70
71
72
73
74
75
|
# File 'lib/cucumber/formatter/json.rb', line 70
def step_name(keyword, step_match, status, source_indent, background)
@current_step[:status] = status
@current_step[:keyword] = keyword
@current_step[:name] = "#{step_match.name || step_match.format_args}"
@current_step[:file_colon_line] = step_match.file_colon_line
end
|
#table_cell_value(value, status) ⇒ Object
105
106
107
|
# File 'lib/cucumber/formatter/json.rb', line 105
def table_cell_value(value, status)
@current_row[:cells] << {:text => value, :status => status}
end
|