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

Adds scenario for the ambiguous step reporting #1132

Conversation

MadameSheema
Copy link
Member

@MadameSheema MadameSheema commented Jun 25, 2017

Summary

Added scenario about how the reporting of ambiguous step match should be. See #1113

Details

Spike of an example we think reporting could be.

Motivation and Context

Fixes #1113

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • I've added tests for my code
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.

@MadameSheema
Copy link
Member Author

@enkessler could you please review it? :D

@tooky
Copy link
Member

tooky commented Jun 26, 2017

Thanks @MadameSheema!

I think we need to have a look at exactly what we want the behaviour for ambiguous steps to be.

I think the choice is that the step is either Pending or Failed. This PR recommends Failed.

It could be pending because the user needs to give Cucumber more information so that it can decide what to run here.

It could be failed because there is a problem with the test automation code and Cucumber is unable to execute the step.

@enkessler
Copy link
Contributor

With --strict, an ambiguous step should definitely fail (red) and, with --guess, an ambiguous step should not be auto-failed (green, assuming the step doesn't otherwise raise an error). Lacking either of those flags, I'd lean towards some flavor of 'yellow', which I think means that it ought to be treated similar to a pending/undefined step.

@brasmusson
Copy link
Contributor

I think Cucumber-Ruby should do what Cucumber-JS does and have a result type for Ambiguous. Without --strict I think an Ambiguous result should affect the exit code as Pending and Undefined results (exit code 0 if not --strict, exit code not 0 if --strict). With --guess thinks start to get interesting, then a step is executed (with a pass or fail) - should the result of the step be the result of the execution, or should some extra informations say something about that there were and ambiguity the was resolved by guessing?

@mattwynne
Copy link
Member

It sounds like we'll need at least three scenarios here:

  1. strict mode => exit 1
  2. not in strict mode => exit 0
  3. guess mode => exit 0

I'm pretty sure guess mode has always just quietly done its job in the past. I think we should focus on helping @MadameSheema get this back to working and then deal with making guess mode more fancy. WDYT?

* a step
* an ambiguous step

Scenario: test 2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering why we need this second scenario. I'd find it easier to read this example if it wasn't there. Do we need it to illustrate the behaviour?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matt it's there because the current behaviour is that it just crashes the whole test run and doesn't run he second scenario.

I suppose that if it reported the status correctly it wouldn't matter how many scenarios there are.

"""
Feature:

Scenario: test 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tend to not even bother naming scenarios used as tests unless it adds something to the documentation. In this case I suggest you can leave it blank.

@@ -0,0 +1,63 @@
Feature: Ambiguous Steps
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you tag this feature as @wip then (I think) it will be expected to fail in CI, so your branch will stay green. Once we have it passing we can remove the @wip tag.

@@ -0,0 +1,63 @@
Feature: Ambiguous Steps

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to add some documentation here about this feature. Something like:

When Cucumber searches for a step definition for a step, it might find multiple step
definitions that could match. In that case, it will give you an error that the step 
definitions are ambiguous.

You can also use a `--guess` mode, where it uses magic powers to try and figure 
out which of those two step definitions is most likely to be the one you meant it 
to use. Use it with caution!

@mattwynne
Copy link
Member

@charlierudolph do you alter the behaviour of cucumber-js for ambiguous steps depending on strict mode, or does it just always fail?

@mattwynne
Copy link
Member

@brasmusson I agree about having an Ambiguous result type.

@charlierudolph
Copy link
Member

charlierudolph commented Jun 27, 2017

In cucumber-js ambiguous steps cause a build to fail by default (thus they are more similar to failed steps then undefined / pending), @jbpros and I debated that here: cucumber/cucumber-js#442. Thus the behavior does not change depending on strict mode.

@mattwynne
Copy link
Member

Based on Charlie's comment then I suggest we stay consistent with JS, keep it simple and ignore strict mode for now. So only two scenarios needed - with / without guess mode

@MadameSheema MadameSheema force-pushed the 1123-scenario_gracefully_reporting_ambiguous_steps branch from e0d7784 to 97082b2 Compare July 3, 2017 18:44
@MadameSheema
Copy link
Member Author

@mattwynne could you please take a look to the scenarios? thx :)

@mattwynne
Copy link
Member

mattwynne commented Jul 3, 2017

I like this much better now!

I'm wondering why you've used the * keyword instead of Given / When / Then which is probably more familiar to most people. Is there a reason for that?

You can run again with --guess to make Cucumber be more smart about it
(Cucumber::Ambiguous)

"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the other thing that's important for this scenario is to see the summary report:

1 scenario (1 failed)
2 steps (1 failed, 1 passed)
0m0.012s

I think we see an error like this in the current behaviour, but it also drops out of the running cucumber process and doesn't print the summary report?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tooky right now, when we have an ambiguous step and we execute it without the guess mode the summary report is not displayed. I can add it as an expected behaviour :)
Is there anything else we should take into consideration for this scenario? Thx!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MadameSheema I think we should. The issue that we based this PR on #1113 was reported because the current behaviour is wrong. When we are running without --guess we want to report this as a failed step, and continue the run as normal. So we should see the summary.

Thanks for sticking with this!

@MadameSheema
Copy link
Member Author

@mattwynne because the example we started working on it was written like that 😊

@mattwynne
Copy link
Member

It looks like the problem here is that the Ambiguous exception is being raised too soon - while we're preparing the test cases for execution, rather than when they're actually being run.

I think the change for this needs to be done in https://github.com/cucumber/cucumber-ruby/blob/master/lib/cucumber/filters/activate_steps.rb which is where we search for a step definition for each test step, and activate it with the definition if we find one.

It's probably a matter of altering the method here to understand about ambiguous steps. We could probably use a similar mechanism to the SkippingStepMatch to pass back a block that will raise that ambiguous exception when the step is actually executed.

It's going to take some fiddling around with, and might need a spike / pairing session with someone who knows the code well to avoid a lot of head-scratching. This is essentially a regression from when we went from 1.0 to 2.0 and rewrote a lot of the internals. Unfortunately because this didn't have an acceptance tests we never noticed. Thanks for adding one @MadameSheema!

@MadameSheema MadameSheema force-pushed the 1123-scenario_gracefully_reporting_ambiguous_steps branch from a591f3b to e1c1200 Compare July 9, 2017 19:30
Taught Cucumber how to match against ambiguous steps.
end

def activate(test_step)
return test_step.with_action { raise Core::Test::Result::Ambiguous.new(@error.message) }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the return keyword doing anything here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that return value of a Ruby method is the last thing evaluated? No, it's just there because that's how someone wrote the code that I am basing this code on.

I don't necessarily understand why established patterns are there, but I can at least follow them as I attempt to fix code that I am entirely unfamiliar with. :)

@mattwynne
Copy link
Member

What does the failing test say now? Can you paste the output you're seeing when you run it?

@enkessler
Copy link
Contributor

enkessler commented Jul 10, 2017

@mattwynne Currently we see

Feature: 

  Scenario:                # features/ambiguous.feature:3
    When a step            # features/step_definitions.rb:1
    Then an ambiguous step # features/ambiguous.feature:5

1 scenario (1 failed)
2 steps (1 failed, 1 passed)

but we expect something like

Feature: 

  Scenario:                # features/ambiguous.feature:3
    When a step            # features/step_definitions.rb:1
    Then an ambiguous step # features/ambiguous.feature:5

Ambiguous match of "an ambiguous step":

    features/step_definitions.rb:1:in `/^a.*step$/'
    features/step_definitions.rb:5:in `/^an ambiguous step$/'

    You can run again with --guess to make Cucumber be more smart about it
     (Cucumber::Ambiguous)

1 scenario (1 failed)
2 steps (1 failed, 1 passed)

which is basically what it is already doing except for shoving in the helpful error snippet. This error is already made in the error class itself

    def initialize(step_name, step_definitions, used_guess)
      message = String.new
      message << "Ambiguous match of \"#{step_name}\":\n\n"
      message << step_definitions.map{|sd| sd.backtrace_line}.join("\n")
      message << "\n\n"
      message << "You can run again with --guess to make Cucumber be more smart about it\n" unless used_guess
      super(message)
    end

but it's not getting output anywhere. From what I have seen of the code, I think that outputting it happens somewhere in cucumber-ruby-core. That, or the pretty formatter is supposed to be catching something and handling it.

@brasmusson
Copy link
Contributor

The PR should be rebased to take advantage of the ground work in #1158.

but we expect something like
Ambiguous match of "an ambiguous step":
features/step_definitions.rb:1:in /^a.*step$/' features/step_definitions.rb:5:in /^an ambiguous step$/'
You can run again with --guess to make Cucumber be more smart about it
(Cucumber::Ambiguous)

This is printed by the formatter, so (some of) the formatters need to be updated to handle ambiguous results (and some other things like defining a colour for ambiguous in ansicolor.rb)

To get something up and running I recommend using the progress formatter instead of the pretty formatter, since the pretty formatter uses the legacy_api quagmire.

@brasmusson brasmusson merged commit f8dbb56 into cucumber:master Aug 2, 2017
@aslakhellesoy
Copy link
Contributor

Hi @MadameSheema,

Thanks for your making your first contribution to Cucumber, and welcome to the Cucumber committers team! You can now push directly to this repo and all other repos under the cucumber organization! 🍾

In return for we ask you to:

  • ✅ Please continue to use branches and pull requests. When someone on the core team approves a pull request (yours or someone else's), you're welcome to merge it yourself.
  • 💚 Commit to setting a good example by following and upholding our code of conduct in your interactions with other collaborators and users.
  • 💬 Join the community Slack channel to meet the rest of the team and make yourself at home.
  • ℹ️ Don't feel obliged to help, just do what you can if you have the time and the energy.
  • 🙋 Ask if you need anything. We're looking for feedback about how to make the project more welcoming, so please tell us!

On behalf of the Cucumber core team,
Aslak Hellesøy
Creator of Cucumber

brasmusson added a commit that referenced this pull request Aug 2, 2017
[ci skip]
@brasmusson
Copy link
Contributor

I absolutely think that ambiguous steps should have a separate result type, but I also think that it is not necessary for v3.0.0. However, since I think fixing #1113 is required for v3.0.0, I merge an implementation reporting ambiguous steps as failed steps, and leave the rest for #1168.

@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
🐛 bug Defect / Bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ambiguous steps ruin reporting
9 participants