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

No errors or snippets for undefined parameter types #1411

Closed
aslakhellesoy opened this issue Apr 26, 2020 · 2 comments
Closed

No errors or snippets for undefined parameter types #1411

aslakhellesoy opened this issue Apr 26, 2020 · 2 comments
Labels
🐛 bug Defect / Bug

Comments

@aslakhellesoy
Copy link
Contributor

Summary

Referencing a parameter type that isn't defined doesn't give me an error, nor does it suggest that I need to define a parameter type.

Expected Behavior

Given the following source:

Given leg LHR-OSL is cancelled
Given('leg LHR-OSL is cancelled') do
  log date.to_s
end

When I change the Cucumber Expression to:

Given('leg {flight-leg} is cancelled') do
  log date.to_s
end

Then I would expect:

The parameter flight-leg is not defined. You can define a new one with:

ParameterType(
  name:        'flight-leg',
  regexp:      /some regexp here/,
  type:        FlightLeg,
  # The transformer takes as many arguments as there are capture groups in the regexp,
  # or just one if there are none.
  transformer: ->(s) { FlightLeg.new(s) }
)

Or alternatively (not as user friendly) just an error:

Could not parse Cucumber Expression "leg {flight-leg} is cancelled" because flight-leg
is not a known parameter type. Please define it.

Current Behavior

No error, no parameter type snippet. The Gherkin step is considered undefined and a step definition snippet is printed:

You can implement step definitions for undefined steps with these snippets:

Given('leg LHR-OSL is cancelled') do
  pending # Write code here that turns the phrase above into concrete actions
end

Possible Solution

I haven't looked at the code, but I assume Cucumber is ignoring and swallowing an exception from cucumber-expressions when trying to parse the expression with the undefined type.

It should emit an UndefinedParameterType message on the bus, and this should be handled at the end of the run to print a parameter type snippet.

Context & Motivation

We want to make it easier for people to define parameter types, and we should give them as much help as possible. Ignoring errors is confusing for users.

Your Environment

  • Version used: 4.0.0.rc.6
  • Operating System and version: MacOS
  • Link to your project:
@aslakhellesoy aslakhellesoy added the 🐛 bug Defect / Bug label Apr 26, 2020
vincent-psarga added a commit that referenced this issue Apr 27, 2020
@vincent-psarga
Copy link
Contributor

It should emit an UndefinedParameterType message on the bus, and this should be handled at the end of the run to print a parameter type snippet.

Note: there's a message emitted in that case but it is directly an enveloppe, so only the message and html formatter are looking at those right now.
I'll add a more "classic" event in such case that can be listened by the other formatters.

@vincent-psarga
Copy link
Contributor

Fixed with #1413

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Defect / Bug
Projects
None yet
Development

No branches or pull requests

2 participants