On 10/14/07, Zach D. [email protected] wrote:
create_a_user_who_works_for_a_company_that_sells_cartoons(“joe”)
Another option would be to not use a helper method at all and do the
I prefer hiding the implementation in well named helper methods as to
etc…
This makes more sense to me then passing in something which adds no
value to the test, like the user’s name “Joe”
That’s a fair argument against this example, however I think that the
point of the example is that there will be cases with more than one
variable. For example:
Given “a ? account with ? dollars”
We could limit ourselves to one argument per method:
Given “a savings account”
And “500 dollars in the account”
But that strikes me as less user friendly as:
Given “a savings account with 500 dollars”
The syntax Dan introduced earlier in this thread comes from a
conversation he and I had a while back about FitLibrary’s DoFixture,
which uses Smalltalk-style keyword messages where every other cell is
part of a method name:
Given “a user of type”, “Admin”, “making a request for”, “user list”
This would result in a call to
a_user_of_type_making_a_request_for(“Admin”, “user list”). One way we
might be able to tie that Zach’s ideal (a normal sentence w/ lots of
helper methods) and make it a bit smarter would be something like
this:
def a__account_with__dollars(account_type, amount)
account = account_types[account_type].new(amount)
end
When the runner sees anything sent to Given, When or Then (or And)
that matches /^a\b(.+?)\baccount with\b(.+?)\bdollars$/, it would pass
$1.strip() and $2.strip() to this method.
The only problem with this is that I can easily imagine such patterns
starting to overlap in a larger story set, potentially producing
unwanted results. But perhaps that’s not as big a problem as I think?
Thoughts?
Dan - I’m curious as to your thoughts re: this supporting the perfect
vision of customer-readable/writable Acceptance Tests that Zach is
looking for.
Thoughts?
Cheers,
David