Class: Gherkin::Formatter::JSONFormatter
- Inherits:
-
Object
- Object
- Gherkin::Formatter::JSONFormatter
- Includes:
- Base64
- Defined in:
- lib/gherkin/formatter/json_formatter.rb
Instance Attribute Summary collapse
-
#gherkin_object ⇒ Object
readonly
Returns the value of attribute gherkin_object.
Instance Method Summary collapse
- #background(background) ⇒ Object
- #embedding(mime_type, data) ⇒ Object
- #eof ⇒ Object
- #examples(examples) ⇒ Object
- #feature(feature) ⇒ Object
-
#initialize(io) ⇒ JSONFormatter
constructor
Creates a new instance that writes the resulting JSON to
io
. - #match(match) ⇒ Object
- #result(result) ⇒ Object
- #scenario(scenario) ⇒ Object
- #scenario_outline(scenario_outline) ⇒ Object
- #step(step) ⇒ Object
- #uri(uri) ⇒ Object
Constructor Details
#initialize(io) ⇒ JSONFormatter
Creates a new instance that writes the resulting JSON to io
. If io
is nil, the JSON will not be written, but instead a Ruby object can be retrieved with #gherkin_object
17 18 19 |
# File 'lib/gherkin/formatter/json_formatter.rb', line 17 def initialize(io) @io = io end |
Instance Attribute Details
#gherkin_object ⇒ Object (readonly)
Returns the value of attribute gherkin_object.
12 13 14 |
# File 'lib/gherkin/formatter/json_formatter.rb', line 12 def gherkin_object @gherkin_object end |
Instance Method Details
#background(background) ⇒ Object
30 31 32 |
# File 'lib/gherkin/formatter/json_formatter.rb', line 30 def background(background) feature_elements << background.to_hash end |
#embedding(mime_type, data) ⇒ Object
58 59 60 |
# File 'lib/gherkin/formatter/json_formatter.rb', line 58 def (mime_type, data) << {'mime_type' => mime_type, 'data' => encode64s(data)} end |
#eof ⇒ Object
62 63 64 |
# File 'lib/gherkin/formatter/json_formatter.rb', line 62 def eof @io.write(@gherkin_object.to_json) if @io end |
#examples(examples) ⇒ Object
42 43 44 |
# File 'lib/gherkin/formatter/json_formatter.rb', line 42 def examples(examples) all_examples << examples.to_hash end |
#feature(feature) ⇒ Object
26 27 28 |
# File 'lib/gherkin/formatter/json_formatter.rb', line 26 def feature(feature) @gherkin_object = feature.to_hash end |
#match(match) ⇒ Object
50 51 52 |
# File 'lib/gherkin/formatter/json_formatter.rb', line 50 def match(match) last_step['match'] = match.to_hash end |
#result(result) ⇒ Object
54 55 56 |
# File 'lib/gherkin/formatter/json_formatter.rb', line 54 def result(result) last_step['result'] = result.to_hash end |
#scenario(scenario) ⇒ Object
34 35 36 |
# File 'lib/gherkin/formatter/json_formatter.rb', line 34 def scenario(scenario) feature_elements << scenario.to_hash end |
#scenario_outline(scenario_outline) ⇒ Object
38 39 40 |
# File 'lib/gherkin/formatter/json_formatter.rb', line 38 def scenario_outline(scenario_outline) feature_elements << scenario_outline.to_hash end |
#step(step) ⇒ Object
46 47 48 |
# File 'lib/gherkin/formatter/json_formatter.rb', line 46 def step(step) steps << step.to_hash end |
#uri(uri) ⇒ Object
21 22 23 24 |
# File 'lib/gherkin/formatter/json_formatter.rb', line 21 def uri(uri) # We're ignoring the uri - we don't want it as part of the JSON # (The pretty formatter uses it just for visual niceness - comments) end |