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

[Core] Implement cucumber expressions #1248

Merged
merged 114 commits into from
May 14, 2018
Merged

[Core] Implement cucumber expressions #1248

merged 114 commits into from
May 14, 2018

Conversation

mpkorstanje
Copy link
Contributor

@mpkorstanje mpkorstanje commented Oct 12, 2017

Summary

  • Implements Cucumber expressions
  • Removes XStream
  • Adds DataTables from add datatable/java common#291
  • Introduces the concept of StepExpressions which combines a CucumberExpression and DataTable expression. Currently data table expressions are limited to a name or java type. Currently only the implicit type derived from the method argument is used.

For a working example check the calculator examples.

How to build

Install (mvn install) datatables/java from cucumber/cucumber
Then install this branch. If it fails you may need to remove pax-exam from examples/pom,xml. This is okay.

Todo

  • Fix android examples
    * [ ] Add link to configuration docs in exceptions
  • Test SnippetGenerators and StepdefGenerator icm Idea
    * [ ] Update documentation
  • Write blog post
    * [ ] File IDEA bug about "Pattern expected" warning
  • Undefined parameter type error should be similarly friendly as missing table type

This closes #1041

@mpkorstanje mpkorstanje added this to the 3.0.0 milestone Oct 12, 2017
@mlvandijk
Copy link
Member

mlvandijk commented Apr 13, 2018

Update:
Replacing parameter Integer with Byte in step def:

    @Given("I have {byte} cucumbers in my belly/stomach")
    public void i_have_byte_cucumbers_in_my_belly(Byte byte1) {
        // Write code here that turns the phrase above into concrete actions
        throw new PendingException();
    }

This works for valid values (e.g. 0x7F), but not for invalid values (same stacktrace as above).

Note: Generated snippets contain {int}, e.g.:

@Given("I have {int}x{int}F cucumbers in my belly")
public void i_have_x_F_cucumbers_in_my_belly(Integer int1, Integer int2) {
   // Write code here that turns the phrase above into concrete actions
   throw new PendingException();
}

Some examples here: mlvandijk/cucumber-expression-test@1d58b06

@mpkorstanje
Copy link
Contributor Author

mpkorstanje commented Apr 13, 2018

I've had to look up how those worked again and the rules downright rather complicated because java treats them as 2s-complement numbers.

As a normal person I generally expect 0xff to give me a bit set of 11111111. In java you get 011111111. We could make it follow that expectation but that might just make it confusing for people who are familiar with the regular java behavior.

So as this is all a bit annoying. So lets byte the bullet and drop it. The people who want to use it can sink their teeth in it.

@aslakhellesoy
Copy link
Contributor

I pushed cucumber/common@ecab2ab where {byte} use the same decimal pattern as {short}, {int} and {long}. That's less confusing.

I considered adding a {hex} type with pattern 0[xX][0-9a-fA-F]{1,16} that would resolve to a Long. It could then be down-cast to any integer type when the stepdef gets called. But I resisted the temptation since I should add it to the 3 other implementations as well. If people really want to write hex in Gherkin they can write their own bloody stepdefs! 😈

@mpkorstanje
Copy link
Contributor Author

Hallelujah!

@mpkorstanje
Copy link
Contributor Author

mpkorstanje commented Apr 15, 2018

Explain cucumber.api.Configuration in error message (unless it already exists)

Got the infra structure set up for that. A full blown explanation depending on the existence of the configuration adds too much complexity. As does combining all the messages in a completely sensible way. People can read a stack trace.

Just need to add a link to the documentation.

@mpkorstanje mpkorstanje modified the milestones: 4.0.0, 3.0.0 Apr 26, 2018
@mpkorstanje
Copy link
Contributor Author

Step expression should be completely hidden from the user. They'll only ever see the cucumber.api.TypeRegistry, they won't ever see io.cucumber.stepexpression.TypeRegistry.

The purpose of the package is to abstract the cucumber expressions and data table types and all the transformations involved from the java and java8 step definitions and the step definition match.

This means:

  • Creating a step expresssion from a cucumber expression + optional data table or doc string type
  • Combining the pickle parameters and pickle arguments into a list of method arguments (combining these makes things much simpler)
  • Transforming these arguments into java objects.

This used to be done in PickleStepDefinitionMatch.transformedArgs and ParameterInfo .convert neither of which should be concerned with transformations. Now it has been contained.

It also required LocalizedXStreams to be passed around everywhere. The TypeRegistry goes from the Runtime to the Backend to the StepDefinition and that is it.

@mpkorstanje
Copy link
Contributor Author

mpkorstanje commented May 1, 2018

easier for us to version.

I've automated it a while ago. Break the api, break the build.

https://github.com/cucumber/cucumber-jvm/blob/master/pom.xml#L866

edit: Ofcourse it doesn't catch protocol level changes such as the formatter event streams.

edit; And if you're looking to test revapi. Set the version back to 2.x. Breaks are allowed on majors.

@mpkorstanje
Copy link
Contributor Author

Blog post drafted: https://github.com/cucumber/website/pull/290

@mpkorstanje
Copy link
Contributor Author

@aslakhellesoy StepdefGenerator doesn't appear to be used by IDEA. Or anybody on Github. You sure it's not dead code?

@aslakhellesoy
Copy link
Contributor

Yeah just get rid of StepdefGenerator. It's old dead code.

@mpkorstanje
Copy link
Contributor Author

I'm going to split writing the docs regarding the configuration from this issue. The current docs are talking about a completely different configurations. This will take some work. And while that is being done I'd rather see another PR come in that is going to conflict with everything.

The IDEA people will need a release to work with so that also needs a merge.

@mpkorstanje mpkorstanje merged commit a4a3ad5 into master May 14, 2018
@mpkorstanje mpkorstanje deleted the cucumber-expressions branch May 14, 2018 20:52
mpkorstanje added a commit that referenced this pull request May 14, 2018
@lock
Copy link

lock bot commented May 14, 2019

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 May 14, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for Cucumber Expressions
6 participants