I've actually had that on my TODO list, but your suggestion is much
better than what I had planned. I was just going to overload the
methods to allow you to pass in a format string, but using the
attributes is much nicer.
The only issue I see is that methods can have more than one step
attribute on them. So far, I haven't used that feature myself so it
would probably be rare and OK to just use the first attribute found.
Also, it might be tricky to parse the regular expression to know where
to insert the values, but it might be doable. In the simple example
from the tutorial, it's very obvious, but the patterns can get more
complicated.
We could use a different attribute like:
[Format("the result should be close to {0}"]
It might look like a repetition, but with delegates, you don't even
need the [Then] attribute. So if you're only using delegates, you're
probably not putting the step attributes on your methods and could
optionally put a [Format] attribute on them inside.
What do you think?
--
Jason
This is another great idea. I wish I could come up with these. =)
How about supporting both ideas? If the method has a Format attribute,
that's used.
If it doesn't, then it tries to split the method name up into words
and replace the words that match the parameter names with the
parameter values.
Maybe it only does this step if there's only a single match for every
parameter. If this isn't the case, the names are too ambiguous and it
could fall back on what it does now.
By the way, I already have a regular expression in BehaveN that can
split up method names like "AddingAAndB" into "Adding", "A", "And",
"B" so it will be easy to get your example to work even though I agree
that single letter parameters are usually a bad idea for non-example
code.
--
Jason