Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confusing error message from json formatter #197

Closed
flashquartermaster opened this issue Dec 2, 2011 · 14 comments
Closed

Confusing error message from json formatter #197

flashquartermaster opened this issue Dec 2, 2011 · 14 comments
Assignees
Milestone

Comments

@flashquartermaster
Copy link

$ cucumber -t @step_matcher -f json_pretty
Feature file being parsed is https://github.com/flashquartermaster/Cuke4AS3/blob/master/Cuke4AS3/test/features/cuke4as3/step-matcher.feature

only generation of JSON objects or arrays allowed (JSON::GeneratorError)
/Library/Ruby/Gems/1.8/gems/json-1.6.0/lib/json/common.rb:278:in 'generate'
/Library/Ruby/Gems/1.8/gems/json-1.6.0/lib/json/common.rb:278:in 'pretty_generate'
/Library/Ruby/Gems/1.8/gems/cucumber-1.0.5/bin/../lib/cucumber/formatter/json_pretty.rb:8:in 'after_features'
/Library/Ruby/Gems/1.8/gems/cucumber-1.0.5/bin/../lib/cucumber/ast/tree_walker.rb:173:in '__send__'
/Library/Ruby/Gems/1.8/gems/cucumber-1.0.5/bin/../lib/cucumber/ast/tree_walker.rb:173:in 'send_to_all'
/Library/Ruby/Gems/1.8/gems/cucumber-1.0.5/bin/../lib/cucumber/ast/tree_walker.rb:171:in 'each'
/Library/Ruby/Gems/1.8/gems/cucumber-1.0.5/bin/../lib/cucumber/ast/tree_walker.rb:171:in 'send_to_all'
/Library/Ruby/Gems/1.8/gems/cucumber-1.0.5/bin/../lib/cucumber/ast/tree_walker.rb:164:in 'broadcast'
/Library/Ruby/Gems/1.8/gems/cucumber-1.0.5/bin/../lib/cucumber/ast/tree_walker.rb:13:in 'visit_features'
/Library/Ruby/Gems/1.8/gems/cucumber-1.0.5/bin/../lib/cucumber/runtime.rb:45:in 'run!'
/Library/Ruby/Gems/1.8/gems/cucumber-1.0.5/bin/../lib/cucumber/cli/main.rb:43:in 'execute!'
/Library/Ruby/Gems/1.8/gems/cucumber-1.0.5/bin/../lib/cucumber/cli/main.rb:20:in 'execute'
/Library/Ruby/Gems/1.8/gems/cucumber-1.0.5/bin/cucumber:14
/usr/bin/cucumber:19:in 'load'
/usr/bin/cucumber:19
@aslakhellesoy
Copy link
Contributor

Do you get the same error with the latest versions of cucumber (1.1.3) ?

@flashquartermaster
Copy link
Author

Yes

only generation of JSON objects or arrays allowed (JSON::GeneratorError)
/Library/Ruby/Gems/1.8/gems/json-1.6.0/lib/json/common.rb:278:in `generate'
/Library/Ruby/Gems/1.8/gems/json-1.6.0/lib/json/common.rb:278:in `pretty_generate'
/Library/Ruby/Gems/1.8/gems/cucumber-1.1.3/bin/../lib/cucumber/formatter/json_pretty.rb:8:in `after_features'
/Library/Ruby/Gems/1.8/gems/cucumber-1.1.3/bin/../lib/cucumber/ast/tree_walker.rb:173:in `__send__'
/Library/Ruby/Gems/1.8/gems/cucumber-1.1.3/bin/../lib/cucumber/ast/tree_walker.rb:173:in `send_to_all'
/Library/Ruby/Gems/1.8/gems/cucumber-1.1.3/bin/../lib/cucumber/ast/tree_walker.rb:171:in `each'
/Library/Ruby/Gems/1.8/gems/cucumber-1.1.3/bin/../lib/cucumber/ast/tree_walker.rb:171:in `send_to_all'
/Library/Ruby/Gems/1.8/gems/cucumber-1.1.3/bin/../lib/cucumber/ast/tree_walker.rb:164:in `broadcast'
/Library/Ruby/Gems/1.8/gems/cucumber-1.1.3/bin/../lib/cucumber/ast/tree_walker.rb:13:in `visit_features'
/Library/Ruby/Gems/1.8/gems/cucumber-1.1.3/bin/../lib/cucumber/runtime.rb:46:in `run!'
/Library/Ruby/Gems/1.8/gems/cucumber-1.1.3/bin/../lib/cucumber/cli/main.rb:43:in `execute!'
/Library/Ruby/Gems/1.8/gems/cucumber-1.1.3/bin/../lib/cucumber/cli/main.rb:20:in `execute'
/Library/Ruby/Gems/1.8/gems/cucumber-1.1.3/bin/cucumber:14
/usr/bin/cucumber:19:in `load'
/usr/bin/cucumber:19

@fuzzyweapon
Copy link

I do too on 1.2.1.
cucumber -f json_pretty --out results.json
only generation of JSON objects or arrays allowed (JSON::GeneratorError)
/Users/jwillson/.rvm/gems/ruby-1.9.2-p320/gems/json-1.7.3/lib/json/common.rb:285:in generate' /Users/jwillson/.rvm/gems/ruby-1.9.2-p320/gems/json-1.7.3/lib/json/common.rb:285:inpretty_generate'
/Users/jwillson/.rvm/gems/ruby-1.9.2-p320/gems/cucumber-1.2.1/lib/cucumber/formatter/json_pretty.rb:8:in after_features' /Users/jwillson/.rvm/gems/ruby-1.9.2-p320/gems/cucumber-1.2.1/lib/cucumber/ast/tree_walker.rb:173:inblock in send_to_all'
/Users/jwillson/.rvm/gems/ruby-1.9.2-p320/gems/cucumber-1.2.1/lib/cucumber/ast/tree_walker.rb:171:in each' /Users/jwillson/.rvm/gems/ruby-1.9.2-p320/gems/cucumber-1.2.1/lib/cucumber/ast/tree_walker.rb:171:insend_to_all'
/Users/jwillson/.rvm/gems/ruby-1.9.2-p320/gems/cucumber-1.2.1/lib/cucumber/ast/tree_walker.rb:164:in broadcast' /Users/jwillson/.rvm/gems/ruby-1.9.2-p320/gems/cucumber-1.2.1/lib/cucumber/ast/tree_walker.rb:13:invisit_features'
/Users/jwillson/.rvm/gems/ruby-1.9.2-p320/gems/cucumber-1.2.1/lib/cucumber/runtime.rb:46:in run!' /Users/jwillson/.rvm/gems/ruby-1.9.2-p320/gems/cucumber-1.2.1/lib/cucumber/cli/main.rb:43:inexecute!'
/Users/jwillson/.rvm/gems/ruby-1.9.2-p320/gems/cucumber-1.2.1/lib/cucumber/cli/main.rb:20:in execute' /Users/jwillson/.rvm/gems/ruby-1.9.2-p320/gems/cucumber-1.2.1/bin/cucumber:14:in<top (required)>'
/Users/jwillson/.rvm/gems/ruby-1.9.2-p320/bin/cucumber:19:in load' /Users/jwillson/.rvm/gems/ruby-1.9.2-p320/bin/cucumber:19:in

'
/Users/jwillson/.rvm/gems/ruby-1.9.2-p320/bin/ruby_noexec_wrapper:14:in eval' /Users/jwillson/.rvm/gems/ruby-1.9.2-p320/bin/ruby_noexec_wrapper:14:in'

@wilken
Copy link

wilken commented Feb 21, 2013

+1

c:\test\auto>cucumber --format json_pretty --out reports/reports.json
*** WARNING: You must use ANSICON 1.31 or higher (http://adoxa.110mb.com/ansicon) to get coloured output on Windows
Started ChromeDriver
port=9515
version=26.0.1383.0
log=c:\test\auto\chromedriver.log
[6048:6828:0221/092725:ERROR:bluetooth_adapter_win.cc(23)] NOT IMPLEMENTED
Started ChromeDriver
port=9515
version=26.0.1383.0
log=c:\test\auto\chromedriver.log
[8676:9012:0221/093332:ERROR:bluetooth_adapter_win.cc(23)] NOT IMPLEMENTED
only generation of JSON objects or arrays allowed (JSON::GeneratorError)
C:/Ruby193/lib/ruby/gems/1.9.1/gems/json-1.7.7/lib/json/common.rb:285:in generate' C:/Ruby193/lib/ruby/gems/1.9.1/gems/json-1.7.7/lib/json/common.rb:285:inpretty_generate'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/cucumber-1.2.1/lib/cucumber/formatter/json_pretty.rb:8:in after_features' C:/Ruby193/lib/ruby/gems/1.9.1/gems/cucumber-1.2.1/lib/cucumber/ast/tree_walker.rb:173:inblock in send_to_all'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/cucumber-1.2.1/lib/cucumber/ast/tree_walker.rb:171:in each' C:/Ruby193/lib/ruby/gems/1.9.1/gems/cucumber-1.2.1/lib/cucumber/ast/tree_walker.rb:171:insend_to_all'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/cucumber-1.2.1/lib/cucumber/ast/tree_walker.rb:164:in broadcast' C:/Ruby193/lib/ruby/gems/1.9.1/gems/cucumber-1.2.1/lib/cucumber/ast/tree_walker.rb:13:invisit_features'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/cucumber-1.2.1/lib/cucumber/runtime.rb:46:in run!' C:/Ruby193/lib/ruby/gems/1.9.1/gems/cucumber-1.2.1/lib/cucumber/cli/main.rb:43:inexecute!'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/cucumber-1.2.1/lib/cucumber/cli/main.rb:20:in execute' C:/Ruby193/lib/ruby/gems/1.9.1/gems/cucumber-1.2.1/bin/cucumber:14:in<top (required)>'
C:/Ruby193/bin/cucumber:23:in load' C:/Ruby193/bin/cucumber:23:in

'

@mattwynne
Copy link
Member

@fuzzyweapon @wilken could you show us the feature file (or ideally pare it down to a representative test case) that causes this?

@wilken
Copy link

wilken commented Feb 21, 2013

Hi, this feature file causes the error:

Feature: Applicant Smoketest
In order to ensure the administration application is working
A user should open all menu items and tabs
And see working pages

Scenario: Log in
    Given that a user opens a browser and visits "http://q.queue-it.net/?c=uniit&e=testnewwl4" and is logged in as user "[email protected]", password "xxxxx"

Scenario Outline: Test that tabs are working
    When user clicks on tab "<tab>"
    Then the page contains "<marker>"

    Examples:
        |tab|marker|
        |Opret ansøgning|Vælg uddannelsessted og uddannelse|
        |Opret ansøgning udveksling|Vælg uddannelsessted og uddannelse|
        |Se status på ansøgninger --fælles--|Status --fælles--|
        |Beskeder --fælles--|Modtaget|

Scenario: Close browser
    Given that a use closes the browser

@mattwynne
Copy link
Member

Thanks Morten. Are any of these steps failing, or undefined?

@wilken
Copy link

wilken commented Feb 21, 2013

No everything is fine and i can produce the report in html and json. only json_pretty fails
The json output is posted below. I have even run it though JSON.pretty_generate without problems.

[{"keyword":"Feature","name":"Applicant Smoketest","line":1,"description":"In order to ensure the administration application is working\nA user should open all menu items and tabs\nAnd see working pages","id":"applicant-smoketest","uri":"features\\smoke_test_applicant.feature","elements":[{"keyword":"Scenario","name":"Log in","line":6,"description":"","id":"applicant-smoketest;log-in","type":"scenario","steps":[{"keyword":"Given ","name":"that a user opens a browser and visits \"http://q.queue-it.net/?c=uniit&e=testnewwl4\" and is logged in as user \"[email protected]\", password \"xxx\"","line":7,"match":{"arguments":[{"offset":40,"val":"http://q.queue-it.net/?c=uniit&e=testnewwl4"},{"offset":111,"val":"[email protected]"},{"offset":143,"val":"kmd123"}],"location":"features/step_definitions/stads_dans_test_steps.rb:5"},"result":{"status":"passed"}}]},{"keyword":"Scenario Outline","name":"Test that tabs are working","line":9,"description":"","id":"applicant-smoketest;test-that-tabs-are-working","type":"scenario_outline","steps":[{"keyword":"When ","name":"user clicks on tab \"<tab>\"","line":10,"match":{"arguments":[{"offset":20,"val":"Opret ansøgning"}],"location":"features/step_definitions/stads_dans_test_steps.rb:22"}},{"keyword":"Then ","name":"the page contains \"<marker>\"","line":11,"match":{"arguments":[{"offset":19,"val":"Vælg uddannelsessted og uddannelse"}],"location":"features/step_definitions/stads_dans_test_steps.rb:38"}}],"examples":[{"keyword":"Examples","name":"","line":13,"description":"","id":"applicant-smoketest;test-that-tabs-are-working;","rows":[{"cells":["tab","marker"],"line":14,"id":"applicant-smoketest;test-that-tabs-are-working;;1"},{"cells":["Opret ansøgning","Vælg uddannelsessted og uddannelse"],"line":15,"id":"applicant-smoketest;test-that-tabs-are-working;;2"},{"cells":["Opret ansøgning udveksling","Vælg uddannelsessted og uddannelse"],"line":16,"id":"applicant-smoketest;test-that-tabs-are-working;;3"},{"cells":["Se status på ansøgninger --fælles--","Status --fælles--"],"line":17,"id":"applicant-smoketest;test-that-tabs-are-working;;4"},{"cells":["Beskeder --fælles--","Modtaget"],"line":18,"id":"applicant-smoketest;test-that-tabs-are-working;;5"}]}]},{"keyword":"Scenario","name":"Close browser","line":20,"description":"","id":"applicant-smoketest;close-browser","type":"scenario","steps":[{"keyword":"Given ","name":"that a use closes the browser","line":21,"match":{"location":"features/step_definitions/stads_dans_test_steps.rb:13"},"result":{"status":"passed"}}]}]}]

@os97673
Copy link
Member

os97673 commented Mar 14, 2013

It looks like the problem is that JsonPretty is outdated :(
It tries to convert content of @obj which is undefined.
And looking at Json formatter implementation it looks the best way to fix this problem is to change Gherkin::Formatter::JSONFormatter to be able to print both regular and pretty json, and after that just pass this formatter (with pretty option enabled) to GherkinFormatterAdapter.

@mattwynne what do you think about this approach?

@ghost ghost assigned os97673 Mar 15, 2013
@mattwynne
Copy link
Member

@os97673 sounds reasonable. Can you show me the code?

@os97673
Copy link
Member

os97673 commented Mar 16, 2013

@mattwynne I've created cucumber/gherkin#243 with gherkin's changes.
With those changes we will be able to change JsonPretty to something like

     class JsonPretty < GherkinFormatterAdapter
      include Io

      def initialize(runtime, io, options)
        @io = ensure_io(io, "json")
        super(Gherkin::Formatter::JSONFormatter.new(@io, :pretty => true), false)
      end
    end

os97673 added a commit that referenced this issue Mar 16, 2013
For now JsonPretty is an empty subclass of Json.  It doesn't produce prettyfied json, but at least id doesn't throws exceptions
@os97673
Copy link
Member

os97673 commented Mar 16, 2013

While we are discussing changes for Gherkin, I've pushed simple fix which make JsonPretty an empty subclass of Json. This way it at least doesn't throw exceptions ;)

@os97673
Copy link
Member

os97673 commented Mar 16, 2013

In cucumber/gherkin#243 we decided to change JSONFormatter to output prettyfied json by default.
Gherkin has been updated, so as soon as it will be released JsonPretty will work correctly.
So, I'm closing this ticket as fixed.

@os97673 os97673 closed this as completed Mar 16, 2013
@lock
Copy link

lock bot commented Oct 25, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Oct 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants