Forum: RSpec Sample App - TDD with Cucumber and RSpec

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
90e140f8553ecdec1b0d7dbf608a0561?d=identicon&s=25 Pau Cor (phylae)
on 2008-12-01 16:34
Hi,

I just posted a tiny app that I put together for a presentation on
Cucumber.
http://github.com/thoughtless/cuc_demo/tree/master

This essentially mirrors the workflow that I strive towards. (The README
explains more.) I don't want to put myself out there as the standard to
immitate, but I think it will be helpful for people just getting started
with TDD/Cucumber/RSpec.

I'd really appreciate your feedback!

Paul

P.S. Sorry to the guys on IRC who got this message twice.
75cf3e99d398f414c227a63bcdb46b51?d=identicon&s=25 Fernando García Samblas (Guest)
on 2008-12-01 19:57
(Received via mailing list)
Paul,

thanks for sharing your examples. I was just thinking about posting
something that can be introduced nicely with your sample app.

Now in cuc_demo we've got a step definition for /^there are no posties$/
in postie_steps.rb. This way, if we'd need to add a "Given there are no
users" step we should create a user_steps.rb with a similar definition.

IMHO it would be nice to have instead a "context_definitions.rb" with
common "givens" (similar to navigation_definitions.rb) and there a more
general definition, like for instance:

Given /^there are no (.*)$/ do |thing| thing_to_model(thing).destroy_all
end

In our World we should have a thing_to_class method with the mappings
between the names used in features and the model class that implement
them.

I think this mapping is also useful if tomorrow you and/or your client
decides to call it "pasties" instead of "posties" (and is more than
useful if you're writing your features in other language than English,
cause you cannot obtain the class name through transformations of the
original "thing").

Cheers,
nando


Pau Cor
escribió:> Hi,
> I'd really appreciate your feedback!
>
> Paul
>
> P.S. Sorry to the guys on IRC who got this message twice.
>


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

The Cocktail
C/ Salamanca 17
28020 Madrid
+34 91 567 06 05
Cdf378de2284d8acf137122e541caa28?d=identicon&s=25 Matt Wynne (mattwynne)
on 2008-12-02 00:19
(Received via mailing list)
On 1 Dec 2008, at 19:00, Fernando García Samblas wrote:

> users" step we should create a user_steps.rb with a similar
>
> In our World we should have a thing_to_class method with the mappings
> between the names used in features and the model class that
> implement them.
>
> I think this mapping is also useful if tomorrow you and/or your client
> decides to call it "pasties" instead of "posties" (and is more than
> useful if you're writing your features in other language than English,
> cause you cannot obtain the class name through transformations of the
> original "thing").

We have a convention here at Songkick (after a great deal of debate)
that it's OK to refer to key domain concepts like Concerts, Artists,
Venues etc by their Ruby class name from within the scenario. Thus our
thing_to_model function is always a matter of just calling
thing.constantize.

I greatly prefer this to having any kind of custom mapping - it
promotes the 'ubiquitous language' that Eric Evans talks about in the
original DDD book.

Maybe it's different when you're working in another language though -
I guess it's preferable to use English names for classes etc, is it?

Matt Wynne
http://blog.mattwynne.net
http://www.songkick.com
90e140f8553ecdec1b0d7dbf608a0561?d=identicon&s=25 Pau Cor (phylae)
on 2008-12-02 09:04
Fernando García Samblas wrote:
> IMHO it would be nice to have instead a "context_definitions.rb" with
> common "givens" (similar to navigation_definitions.rb) and there a more
> general definition, like for instance:

...

> 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.

Paul
2ce9c0106b5851b2294ba5eb9f5c04bd?d=identicon&s=25 Ashley Moran (Guest)
on 2008-12-02 13:42
(Received via mailing list)
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

--
http://www.patchspace.co.uk/
http://aviewfromafar.net/
75cf3e99d398f414c227a63bcdb46b51?d=identicon&s=25 Fernando García Samblas (Guest)
on 2008-12-02 15:29
(Received via mailing list)
Matt Wynne
escribió:> Maybe it's different when you're working in another language though -
> I guess it's preferable to use English names for classes etc, is it?

Exactly Matt that's it. I forgot to explain that, thanks for mention it.

We use pure English in our code and Spanish in the features.

A business term in Spanish can have a bunch of possible translations to
English. The mapping functions let us now exactly what are we talking
about, reducing ambiguity and improving communication with business
people.

>
> Matt Wynne
> http://blog.mattwynne.net
> http://www.songkick.com
>
> _______________________________________________
> rspec-users mailing list
> rspec-users@rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>


--
Fernando García Samblas
fernando.garcia@the-cocktail.com
http://nando.lacoctelera.com

The Cocktail
C/ Salamanca 17
28020 Madrid
+34 91 567 06 05
42172acdf3c6046f84d644cb0b94642c?d=identicon&s=25 Pat Maddox (pergesu)
on 2008-12-02 20:27
(Received via mailing list)
Ashley Moran <ashley.moran@patchspace.co.uk> writes:

> create anything, rather than destroying existing data.
>
> 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
75cf3e99d398f414c227a63bcdb46b51?d=identicon&s=25 Fernando García Samblas (Guest)
on 2008-12-02 22:13
(Received via mailing list)
Ashley Moran
escribió:> 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
end

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

>
> 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@the-cocktail.com
http://nando.lacoctelera.com

The Cocktail
C/ Salamanca 17
28020 Madrid
+34 91 567 06 05
2ce9c0106b5851b2294ba5eb9f5c04bd?d=identicon&s=25 Ashley Moran (Guest)
on 2008-12-03 11:39
(Received via mailing list)
On 2 Dec 2008, at 19:25, Pat Maddox wrote:

> 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.

Nice idea!  That kind of sanity checking can't hurt.

Ashley

--
http://www.patchspace.co.uk/
http://aviewfromafar.net/
This topic is locked and can not be replied to.