[rspec-users] Sample App - TDD with Cucumber and RSpec
Pat Maddox
pergesu at gmail.com
Tue Dec 2 14:25:31 EST 2008
Ashley Moran <ashley.moran at patchspace.co.uk> writes:
> On 2 Dec 2008, at 08:04, Pau Cor wrote:
>
>>> Given /^there are no (.*)$/ do |thing|
>>
>> I really like that. It will make it much more clear since "Given there
>> are no" will be a very common step.
>
> Hmmm, I personally think it's safer to set up each scenario from a
> blank slate. I've used "Given there are no X" steps before, but they
> are just stubs to make the scenario read right, ie they simply don't
> create anything, rather than destroying existing data.
>
> The current implementation,
> Given /^there are no posties$/ do
> Postie.destroy_all
> end
>
> strikes me more of a when step, eg
> When /^all posties are destroyed$/ do
> Postie.destroy_all
> end
>
> A Before block to destroy the Posties (and any other models) will
> probably reduce issues in the long run if Postie began to depend on
> another object, and was trapped by a database constraint.
>
> Ashley
I'm with you on this. In fact, I think my implementation would be
Given ...
Postie.count.should == 0
end
It's just an assertion (in the C sense of the word, not testing). You
should be starting off with a clean slate anyway...but having a couple
assertions before you run can be very helpful for localization. Plus
this step can obviously be reused as a When.
Pat
More information about the rspec-users
mailing list