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

Fix step definition output for Data Tables #411

Merged
merged 2 commits into from
Jul 29, 2021
Merged

Fix step definition output for Data Tables #411

merged 2 commits into from
Jul 29, 2021

Conversation

karfrank
Copy link
Contributor

Description

This fixes incorrect step definition output for Data Tables.

Motivation & context

The current code doesn't generate a correct function for Data Tables. The
PickleStepArgument_PickleTable type does not exist in the current messages-go package.

For example:

Feature: Test Data Table  
                                                                                                                                                                                                                                                                                                                                                                                                                                                            
  Scenario: Data table                                                                                                                                                                                                                         
    Given there is data:                                                                                                                                                                                                                       
      | A |                                                                                                                                                                                                                                    
      | B |                                                                                                                                                                                                                                    
      | C |                                                                                                                                                                                                                                    
    When I run the scenario                                                                                                                                                                                                                    
    Then Godog should provide show the correct step definition

Generates the following output:

Feature: Test Data Table

  Scenario: Data table                                         # features/test.feature:3
    Given there is data:
      | A |
      | B |
      | C |
    When I run the scenario
    Then Godog should provide show the correct step definition

1 scenarios (1 undefined)
3 steps (3 undefined)
474.442µs

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

func godogShouldProvideShowTheCorrectStepDefinition() error {
        return godog.ErrPending
}

func iRunTheScenario() error {
        return godog.ErrPending
}

func thereIsData(arg1 *messages.PickleStepArgument_PickleTable) error {
        return godog.ErrPending
}

func InitializeScenario(ctx *godog.ScenarioContext) {
        ctx.Step(`^Godog should provide show the correct step definition$`, godogShouldProvideShowTheCorrectStepDefinition)
        ctx.Step(`^I run the scenario$`, iRunTheScenario)
        ctx.Step(`^there is data:$`, thereIsData)
}

This output seems to be wrong:

func thereIsData(arg1 *messages.PickleStepArgument_PickleTable) error {
        return godog.ErrPending
}

There is no PickleStepArgument_PickleTable type defined in https://github.com/cucumber/messages-go/blob/v16.0.1/messages.go, so running the generated code results in the following error:

godog
failed to compile tested package: /playground, reason: exit status 2, output: go: finding module for package github.com/cucumber/messages-go/v16                                           
go: found github.com/cucumber/messages-go/v16 in github.com/cucumber/messages-go/v16 v16.0.1
WORK=/tmp/go-build855275816
# playground [playground.test]
./demo_test.go:16:24: undefined: "github.com/cucumber/messages-go/v16".PickleStepArgument_PickleTable

The update in this PR changes the step definition output to:

func thereIsData(arg1 *godog.Table) error {
        return godog.ErrPending
}

which works as expected.

I hope this all makes sense and is helpful. Please let me know if there are any issues with this PR (it's my first contribution to this project). Thank you!

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Update required of cucumber.io/docs

I couldn't find anything about this in the docs.

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

This fixes incorrect step definition output for Data Tables. The
PickleStepArgument_PickleTable type does not exist in the current
messages-go version.
@codecov
Copy link

codecov bot commented Jul 28, 2021

Codecov Report

Merging #411 (a47f17c) into main (15358d2) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #411   +/-   ##
=======================================
  Coverage   83.72%   83.72%           
=======================================
  Files          26       26           
  Lines        2390     2390           
=======================================
  Hits         2001     2001           
  Misses        296      296           
  Partials       93       93           
Impacted Files Coverage Δ
internal/models/stepdef.go 87.70% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 15358d2...a47f17c. Read the comment docs.

@vearutop
Copy link
Member

Good catch, thank you for fixing this.

@vearutop vearutop merged commit 7d343d4 into cucumber:main Jul 29, 2021
@aslakhellesoy
Copy link
Contributor

Hi @karfrank,

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 this generous offer we hope you will:

  • ✅ 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

@karfrank
Copy link
Contributor Author

Many thanks for merging my PR and the warm welcome @vearutop and @aslakhellesoy!
I'll keep my eyes open for more opportunities to contribute.

@karfrank karfrank deleted the fixtablestepdef branch July 29, 2021 19:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants