[rspec-users] Sample App - TDD with Cucumber and RSpec

Fernando García Samblas fernando.garcia at the-cocktail.com
Tue Dec 2 16:16:06 EST 2008

Ashley Moran escribió:
> 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.

Yes, I also agree with you and Pat. Givens should create the scenario
context, not clean the garbage left by others.

But I was using it just as an example of "reusing" common Givens (after
all it was the only Given in Paul's example app), the same way we do
with Whens a Thens.

Take this example instead:

Given /^there is (?:a|an) (.*)$/ do |thing|
  @resources ||= []
  @resources << thing_to_model(thing).create

Using a model factory like FixturesReplacement you can deal with
required data. WDYT?

> 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

Fernando García Samblas
fernando.garcia at the-cocktail.com

The Cocktail
C/ Salamanca 17
28020 Madrid
+34 91 567 06 05

More information about the rspec-users mailing list