Re: [specflow] Optional arguments in the feature file description

1,155 views
Skip to first unread message

Oliver Friedrich

unread,
May 13, 2013, 5:43:41 AM5/13/13
to spec...@googlegroups.com
At first, I thought there was an easy solution to this, but investigating a bit deeper it turns out there isn't. Wrote a short blog post about your question and my investigation here:

http://shades-of-orange.com/post/2013/05/13/SpecFlow-Step-Definition-with-Optional-Parameter.aspx

In short: use two methods and delegate execution from one to the other.
--


2013/5/12 <dv....@gmail.com>
Hi,
How would you solve the following:
Assuming I would like to define in Gherkin the following:

1. When I send some argument xxx with parameter aaa and another parameter bbb
2. When I send some argument xxx with parameter aaa

And I would like to have only one reusable function, something like this:

[When(@"I send some argument (.*) with parameter (.*) and another parameter (.*)")]
public void foo(string paramA, string paramB)
{
  // check if paramB is null and do something
}

I am aware of the table feature (pipe separated values) but I would like to stick with this text-alike syntax. 

Thanks a lot

--
You received this message because you are subscribed to the Google Groups "SpecFlow" group.
To unsubscribe from this group and stop receiving emails from it, send an email to specflow+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

dv....@gmail.com

unread,
May 13, 2013, 6:57:39 AM5/13/13
to spec...@googlegroups.com
Hi Oliver,
First of all, huge Thank you!!!
This post of yours is exactly what I needed. Very detailed and exactly to the point (even using my example :))
The description and the issues you are speaking about in the post are exactly the ones which crossed my mind when dealing with this problem.
I also thought about creating two functions where the one with more parameters calls to the other with fewer, however the usual regex (.*) prevented this solution because of "Multiple matching bindings found" warning (which is justified of course).
The proposed solution is simple and elegant and matches what I need (as long as my params do not include spaces :) ).
Thanks again for the quick reply and for the fantastic explanation.

Oliver Friedrich

unread,
May 13, 2013, 7:40:49 AM5/13/13
to spec...@googlegroups.com
I'm glad it helped. I hope you didn't miss the part about how to make it work for parameter values with spaces: just use ""([^""]*)"" in your regex inside the @-string argument to the step definition.

P.S. I'm terribly sorry for the horrible design of the blog - we just recently worked on something much prettier, just didn't take the time to publish it. The new design will be live in a moment or two, so even the screenshots should then be fully visible.

--


2013/5/13 <dv....@gmail.com>

dv....@gmail.com

unread,
May 13, 2013, 7:45:53 AM5/13/13
to spec...@googlegroups.com
No, I didn't miss the part with this space-supporting-regex, it just didn't seem so nice and simple anymore, but that's me...
Regarding the blog, As long as I get the info I need, I don't care about the looks, but it's me again :) However, I did remove with "Chrome developers tools" the images (adds or menus or something) in order to see the full screenshots :)

Oliver Friedrich

unread,
May 13, 2013, 8:11:12 AM5/13/13
to spec...@googlegroups.com
Glad to hear you overcame that little hurdle ;-)

The new design is finally online, in part thanks to you!

Have a good day!

--


2013/5/13 <dv....@gmail.com>

Oliver Friedrich

unread,
May 13, 2013, 8:17:08 AM5/13/13
to spec...@googlegroups.com
P.S. After updating to a newer version of the .NET BlogEngine it looks like they've added some rewrite sugar to omit the .aspx extension (unfortunately without a redirect), so the correct URL for the post has become http://shades-of-orange.com/post/2013/05/13/SpecFlow-Step-Definition-with-Optional-Parameter.

--


2013/5/13 Oliver Friedrich <oliver.f...@gmail.com>
Reply all
Reply to author
Forward
0 new messages