Class: Gherkin::Formatter::JSONFormatter
- Inherits:
-
Object
- Object
- Gherkin::Formatter::JSONFormatter
- 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
- #eof ⇒ Object
- #examples(examples) ⇒ Object
- #feature(feature) ⇒ Object
-
#initialize(io) ⇒ JSONFormatter
constructor
Creates a new instance that writes the resulting JSON to
io
. - #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
15 16 17 |
# File 'lib/gherkin/formatter/json_formatter.rb', line 15 def initialize(io) @io = io end |
Instance Attribute Details
#gherkin_object ⇒ Object (readonly)
Returns the value of attribute gherkin_object.
10 11 12 |
# File 'lib/gherkin/formatter/json_formatter.rb', line 10 def gherkin_object @gherkin_object end |
Instance Method Details
#background(background) ⇒ Object
28 29 30 |
# File 'lib/gherkin/formatter/json_formatter.rb', line 28 def background(background) feature_elements << background.to_hash end |
#eof ⇒ Object
48 49 50 |
# File 'lib/gherkin/formatter/json_formatter.rb', line 48 def eof @io.write(@gherkin_object.to_json) if @io end |
#examples(examples) ⇒ Object
40 41 42 |
# File 'lib/gherkin/formatter/json_formatter.rb', line 40 def examples(examples) all_examples << examples.to_hash end |
#feature(feature) ⇒ Object
24 25 26 |
# File 'lib/gherkin/formatter/json_formatter.rb', line 24 def feature(feature) @gherkin_object = feature.to_hash end |
#scenario(scenario) ⇒ Object
32 33 34 |
# File 'lib/gherkin/formatter/json_formatter.rb', line 32 def scenario(scenario) feature_elements << scenario.to_hash end |
#scenario_outline(scenario_outline) ⇒ Object
36 37 38 |
# File 'lib/gherkin/formatter/json_formatter.rb', line 36 def scenario_outline(scenario_outline) feature_elements << scenario_outline.to_hash end |
#step(step) ⇒ Object
44 45 46 |
# File 'lib/gherkin/formatter/json_formatter.rb', line 44 def step(step) steps << step.to_hash end |
#uri(uri) ⇒ Object
19 20 21 22 |
# File 'lib/gherkin/formatter/json_formatter.rb', line 19 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 |