Parent

Included Modules

Class Index [+]

Quicksearch

Cucumber::Formatter::Json

The formatter used for --format json

Public Class Methods

new(step_mother, io, options) click to toggle source
    # File lib/cucumber/formatter/json.rb, line 13
13:       def initialize(step_mother, io, options)
14:         @io      = ensure_io(io, "json")
15:         @options = options
16:       end

Public Instance Methods

after_background(background) click to toggle source
    # File lib/cucumber/formatter/json.rb, line 37
37:       def after_background(background)
38:         @current_object = last_feature
39:       end
after_feature_element(feature_element) click to toggle source
     # File lib/cucumber/formatter/json.rb, line 120
120:       def after_feature_element(feature_element)
121:         # change current object back to the last feature
122:         @current_object = last_feature
123:       end
after_features(features) click to toggle source
     # File lib/cucumber/formatter/json.rb, line 125
125:       def after_features(features)
126:         @io.write json_string
127:         @io.flush
128:       end
after_step(step) click to toggle source
    # File lib/cucumber/formatter/json.rb, line 77
77:       def after_step(step)
78:         @current_step = nil
79:       end
after_table_row(row) click to toggle source
     # File lib/cucumber/formatter/json.rb, line 109
109:       def after_table_row(row)
110:         if row.exception
111:           @current_row[:exception] = exception_hash_for(row.exception)
112:         end
113:         @current_row = nil
114:       end
before_background(background) click to toggle source
    # File lib/cucumber/formatter/json.rb, line 31
31:       def before_background(background)
32:         background = {}
33:         @current_object[:background] = background
34:         @current_object = background
35:       end
before_examples(examples) click to toggle source
    # File lib/cucumber/formatter/json.rb, line 81
81:       def before_examples(examples)
82:         @current_object[:examples] = {}
83:       end
before_feature(feature) click to toggle source
    # File lib/cucumber/formatter/json.rb, line 22
22:       def before_feature(feature)
23:         @current_object = {:file => feature.file, :name => feature.name}
24:         @json[:features] << @current_object
25:       end
before_feature_element(feature_element) click to toggle source
    # File lib/cucumber/formatter/json.rb, line 41
41:       def before_feature_element(feature_element)
42:         elements = @current_object[:elements] ||= []
43: 
44:         # change current object to the feature_element
45:         @current_object = {}
46:         elements << @current_object
47:       end
before_features(features) click to toggle source
    # File lib/cucumber/formatter/json.rb, line 18
18:       def before_features(features)
19:         @json = {:features => []}
20:       end
before_outline_table(*args) click to toggle source
    # File lib/cucumber/formatter/json.rb, line 89
89:       def before_outline_table(*args)
90:         @current_object[:examples][:table] = []
91:       end
before_step(step) click to toggle source
    # File lib/cucumber/formatter/json.rb, line 59
59:       def before_step(step)
60:         @current_step = {}
61:         @current_object[:steps] << @current_step
62:       end
before_step_result(keyword, step_match, multiline_arg, status, exception, source_indent, background) click to toggle source
    # File lib/cucumber/formatter/json.rb, line 64
64:       def before_step_result(keyword, step_match, multiline_arg, status, exception, source_indent, background)
65:         if exception
66:           @current_step[:exception] = exception_hash_for(exception)
67:         end
68:       end
before_steps(steps) click to toggle source
    # File lib/cucumber/formatter/json.rb, line 55
55:       def before_steps(steps)
56:         @current_object[:steps] = []
57:       end
before_table_row(row) click to toggle source
     # File lib/cucumber/formatter/json.rb, line 93
 93:       def before_table_row(row)
 94:         @current_row = {:cells => []}
 95: 
 96:         if @current_object.member? :examples
 97:           @current_object[:examples][:table] << @current_row
 98:         elsif @current_step
 99:           (@current_step[:table] ||= []) << @current_row
100:         else
101:           internal_error
102:         end
103:       end
before_tags(tags) click to toggle source
    # File lib/cucumber/formatter/json.rb, line 27
27:       def before_tags(tags)
28:         @current_object[:tags] = tags.tag_names.to_a
29:       end
embed(file, mime_type) click to toggle source
     # File lib/cucumber/formatter/json.rb, line 130
130:       def embed(file, mime_type)
131:         obj = @current_step || @current_object
132:         obj[:embedded] ||= []
133: 
134:         obj[:embedded] << {
135:           :file      => file,
136:           :mime_type => mime_type,
137:           :data      => [File.read(file)].pack("m*") # base64
138:         }
139:       end
examples_name(keyword, name) click to toggle source
    # File lib/cucumber/formatter/json.rb, line 85
85:       def examples_name(keyword, name)
86:         @current_object[:examples][:name] = "#{keyword} #{name}"
87:       end
py_string(string) click to toggle source
     # File lib/cucumber/formatter/json.rb, line 116
116:       def py_string(string)
117:         @current_step[:py_string] = string
118:       end
scenario_name(keyword, name, file_colon_line, source_indent) click to toggle source
    # File lib/cucumber/formatter/json.rb, line 49
49:       def scenario_name(keyword, name, file_colon_line, source_indent)
50:         @current_object[:keyword] = keyword
51:         @current_object[:name] = name
52:         @current_object[:file_colon_line] = file_colon_line
53:       end
step_name(keyword, step_match, status, source_indent, background) click to toggle source
    # File lib/cucumber/formatter/json.rb, line 70
70:       def step_name(keyword, step_match, status, source_indent, background)
71:         @current_step[:status]          = status
72:         @current_step[:keyword]         = keyword
73:         @current_step[:name]            = "#{step_match.name || step_match.format_args}"
74:         @current_step[:file_colon_line] = step_match.file_colon_line
75:       end
table_cell_value(value, status) click to toggle source
     # File lib/cucumber/formatter/json.rb, line 105
105:       def table_cell_value(value, status)
106:         @current_row[:cells] << {:text => value, :status => status}
107:       end

Private Instance Methods

exception_hash_for(e) click to toggle source
     # File lib/cucumber/formatter/json.rb, line 151
151:       def exception_hash_for(e)
152:         {
153:           :class     => e.class.name,
154:           :message   => e.message,
155:           :backtrace => e.backtrace
156:         }
157:       end
internal_error() click to toggle source
     # File lib/cucumber/formatter/json.rb, line 159
159:       def internal_error
160:         raise Error, "you've found a bug in the JSON formatter!"
161:       end
json_string() click to toggle source
     # File lib/cucumber/formatter/json.rb, line 143
143:       def json_string
144:         @json.to_json
145:       end
last_feature() click to toggle source
     # File lib/cucumber/formatter/json.rb, line 147
147:       def last_feature
148:         @json[:features].last
149:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.