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

Methods for Step Definitions #168

Closed
wants to merge 6 commits into from
Closed

Conversation

gga
Copy link
Contributor

@gga gga commented Nov 7, 2011

I'd like to be able to write step definitions without attaching a block directly in-line. Like so:

Given /^I am using "([^"]+)" as the payment recipient$/, :select_recipient

Where select_recipient(name) is a method on the current World. Additionally, I'd like to be able to execute the method against any arbitrary object, as long as it could be reach from the World. Like so:

Given /^I am using "([^"]+)" as the payment recipient$/, :select_recipient, :on => lambda { current_user }

Where the lambda under the key :on is executed within the World, and the method is then sent to the returned object.

I feel that using this approach may encourage more maintainable step definition implementations by making it more straightforward to just wire steps up to page and persona objects.

gga and others added 6 commits November 7, 2011 00:16
If a symbol is passed to a step definition, then that symbol will be
sent to the World object. The symbol must therefore refer to a method
defined by the World: either in an included module or on the World
object.

The proc can still be used, but if a symbol is provided the proc will
be ignored.

Also, support executing the symbol against objects other than the World.

If an :on key is provided to the options hash then the proc attached
to this will be evaluated against the World, and then the symbol sent
to the result of that proc, rather than directly to the World itself.
@mattwynne
Copy link
Member

Thanks for this patch - it's a great idea!

Sorry we took so long to merge it in. Your ticket actually prompted a huge long navel-gazing exercise within the core team about what else we could do to make it easier to write maintainable step definitions, and in the mean time we forgot all about your orignal ticket.

Thanks for contributing to Cucumber.

@mattwynne mattwynne closed this in ca3076a Mar 3, 2012
@gga
Copy link
Contributor Author

gga commented Mar 4, 2012

No worries, thanks for pulling it in. I've been wanting to use this for awhile now. Out of curiosity, what are the other things that you can do?

@diabolo
Copy link

diabolo commented Mar 14, 2012

This needs a blog article to tell us all about it. :)

@sfsekaran
Copy link

Wow, very nice addition. Kudos.

@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

Successfully merging this pull request may close these issues.

6 participants