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

Embed doesn't work with scenario outlines, JSON formatter and --expand #804

Closed
jfinkhaeuser opened this issue Feb 13, 2015 · 17 comments
Closed

Comments

@jfinkhaeuser
Copy link

Software

  • Cucumber: 1.3.18 (and 1.3.17, probably a lot more)
  • Gherkin: 2.12.2

Expected Behaviour

The embed function should work in all cases.

Actual Behavior

The combination of scenario outlines, the --expand parameter, and the JSON formatter don't seem to work.

Example

Feature: JSON embedding
  Scenario Outline: can't embed in the first step with JSON formatter
    Given I try to embed <something>

    Examples:
      | something |
      | foo       |
Given(/^I try to embed (.*?)$/) do |something|
  embed(something, "application/octet-stream")
end

Then running:

$ cucumber --format json -x 

Produces:

[
  {
    "keyword": "Feature",
    "name": "JSON embedding",
    "line": 1,
    "description": "",
    "id": "json-embedding",
    "uri": "features/json_embed.feature",
    "elements": [
      {
        "keyword": "Scenario Outline",
        "name": "can't embed in the first step with JSON formatter",
        "line": 8,
        "description": "",
        "id": "json-embedding;can't-embed-in-the-first-step-with-json-formatter;;2",
        "type": "scenario",
        "steps": [
          {
            "keyword": "Given ",
            "name": "I try to embed foo",
            "line": 4,
            "match": {
              "arguments": [
                {
                  "offset": 15,
                  "val": "foo"
                }
              ],
              "location": "features/step_definitions/steps.rb:1"
            },
            "result": {
              "status": "failed",
              "error_message": "undefined method `[]' for nil:NilClass (NoMethodError)\n./features/step_definitions/steps.rb:2:in `/^I try to embed (.*?)$/'\nfeatures/json_embed.feature:4:in `Given I try to embed <something>'",
              "duration": 661541
            }
          }
        ]
      }
    ]
  }
]

For easier readability, that stack trace is this:

undefined method `[]' for nil:NilClass (NoMethodError)
./features/step_definitions/steps.rb:2:in `/^I try to embed (.*?)$/'
features/json_embed.feature:4:in `Given I try to embed <something>

Analysis

Further digging shows that the fault is triggered in the JSON formatter in Gherkin, namely that @current_step_or_hook doesn't get initialized before it's referenced.

The variable would get initialized in the formatter's step method, and it should be called in gherkin_formatter_adapter.rb somewhere. In that file, the step method is not called in the case of scenario outlines (see before_step hook).

@mattwynne
Copy link
Member

Thanks very much for the detailed bug report - textbook!

Could you try this again with the cucumber 2.0.0.rc.3 which has a lot of changes in this area. @brasmusson do you happen to know if this specific bug is fixed for 2.0? I can't remember.

@jfinkhaeuser
Copy link
Author

Well, spriteCloud is a QA company, so if I can't provide a good bug report, I'd not set a very good example ;)

Unfortunately, cucumber 2.0.0.rc.3 crashes - whether I run it just with --version or with --format json -x, the result is the same. I'll file a separate issue for it and reference this one.

@jfinkhaeuser
Copy link
Author

With the patch to #805 applied, it works.

However, I've got to say that the JSON output isn't what I'd expect. Let me file a different issue for that, since it's technically a different problem.

@mattwynne
Copy link
Member

OK I'm closing this issue.

brasmusson added a commit that referenced this issue Feb 14, 2015
Delay sending the step output to the gherkin formatter in the
JSONFormatter, until step has been called on the gherkin formatter.
@brasmusson
Copy link
Contributor

After fixing #806, I ported the fix back to the v1.3.x-bugfix branch, so now "Embed does work with scenario outlines, JSON formatter and --expand" also on that branch.

@jfinkhaeuser
Copy link
Author

Awesome sauce, thanks guys!

@jfinkhaeuser
Copy link
Author

So, quick question. What's the expected timeline for 1.3.20, then? That's when we can expect the fix in the wild, it seems? (2.x.rc.y is IMHO viable once the "rc" part vanishes).

@mattwynne
Copy link
Member

@jfinkhaeuser I'd encourage you to try 2.0, despite the RC status - it has only a few minor bugs as far as we know.

@jfinkhaeuser
Copy link
Author

It's not about trying - I have tried it. It's about the "RC" label making some stakeholders nervous.

@mattwynne
Copy link
Member

Can you be more specific about their concerns? I think 2.0 is already much better than 1.3. Maybe we should just ship it...

@jfinkhaeuser
Copy link
Author

If there's no more features to be added or known bugs to be fixed, why not ship it indeed?

The concern, whether valid or not, is about software that's not ready for production. If it is ready for production, why don't you make that statement by releasing it? If it is truly not ready for production, 1.3.x remains the latest stable release line.

@jfinkhaeuser
Copy link
Author

Well, cucumber 2.0.0 seems to do the trick. Thanks, guys!

@mattwynne
Copy link
Member

\o/

@mattwynne
Copy link
Member

By the way @jfinkhaeuser it was your comment above that inspired me to get Cucumber 2.0.0 released - thanks!

@jfinkhaeuser
Copy link
Author

Nice - if we can contribute in whichever small way to cucumber, then that's awesome :)

@mattwynne
Copy link
Member

Live in v1.3.20

@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

3 participants