[rspec-users] Do people write specs for the code in their steps? How?
matt at mattwynne.net
Sat Jan 3 08:19:50 EST 2009
On 30 Dec 2008, at 04:17, Erik Pukinskis wrote:
>> The approach I like to take is to follow the guidance of the system
>> (cucumber + rspec) every step of the way. Right now there are no
>> passing steps, so I'd write the code for the 1st pending step, run
>> features and find the first thing that is missing or failing.
> This is one thing I don't get. I just started implementing steps, but
> I feel like THAT code is all completely untested. I don't know if my
> regular expression is correct, I don't know if it does what I think it
> should do. What I really want to do is write something like this:
> describe "steps for withdrawing money"
> describe "Given user has a balance"
> before :each
> cucumber "Given user has $50 dollars"
> it "should match a particular step"
> it "should create an account"
> it "should set the account balance to $50"
> But is there such a "cucumber" method? And how do you check that your
> regular expressions are going to the right place?
> Maybe the best thing to do is write your cucumber steps like this:
> user_has_a_balance = /user has $(.*) dollars/
> Given user_has_a_balance do |balance|
> And then in your spec you can do:
> user_has_a_balance.match("user has $20 dollars").should_not == nil
> How do people write specs for their cucumber steps? And if you don't
> write specs, how do you live with the uncertainty?
It seems like at least part of the uncertainty you're talking about is
that the step matcher in your step definition ruby code won't match
all the steps defined in your features files that you intended it to.
I have also worried about this, particularly after refactoring steps
in a codebase with a large number of features.
A while back, I suggested a feature for cucumber, which would allow
you to run it in a 'strict' mode, where the build would fail if any of
the steps in features were not matched to a ruby step definition. I'm
not sure whether this ticket has been implemented or not - I had a
feeling it was, but I can't see anything in the help for 0.1.13, and
the ticket hasn't been updated. Plus it's Christmas and my brain is
pickled. Anyway, take a look at the ticket:
More information about the rspec-users