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

Optional and alternative words in step definitions #1

Merged
merged 7 commits into from
Oct 28, 2011
Merged

Optional and alternative words in step definitions #1

merged 7 commits into from
Oct 28, 2011

Conversation

cjse
Copy link
Contributor

@cjse cjse commented Oct 26, 2011

Added support for optional and alternative words in step definitions, like so:

step "there is/are :count monster(s)" do |count|
  @monsters = Array.new(count) { Monster.new }
end

That will match both "there is X monster" or "there are X monsters".

To make feature files read better, without duplicating step defitions, you can
now specify alternative words, like this:

  step "there is/are :count monsters" do |count|
    @monsters = Array.new(count) { Monster.new }
  end

That will match either "there is X monsters" or "there are X monsters".
To make feature files read better, without duplicating step defitions,
you can now specify optional parts of words, like this:

  step "cool monster(s)" do |count|
    @monsters = Array.new(count) { Monster.new }
  end

That will match either "cool monster" or "cool monsters".
regexp = regexp.gsub(/(\s):([\w]+)/) do |_|
"#{$1}(?<#{$2}>#{Placeholder.resolve($2.to_sym)})"
end
regexp = regexp.gsub(/(\w+)\/(\w+)/) do |_|
Copy link
Owner

Choose a reason for hiding this comment

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

Maybe it would be nice if this could match any number of words, so that we could do:

step "there is a furry/hairy/shaggy monster" { ... }

Would be cool.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

@cjse
Copy link
Contributor Author

cjse commented Oct 27, 2011

Added support for matching any number of alternative words, and entire words can be optional. Also cleaned things up a bit.

jnicklas added a commit that referenced this pull request Oct 28, 2011
…n_step_definitions

Optional and alternative words in step definitions
@jnicklas jnicklas merged commit 4728793 into jnicklas:master Oct 28, 2011
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.

2 participants