[rspec-users] stepping across features
f.mischa at gmail.com
Tue Dec 2 18:48:38 EST 2008
Hey, actual code might make it easier to help (maybe others disagree), but
here's a few things:
I'm assuming you're using rails, and has many through.
It sounds like you have something like
model: Picture (has many pagepictures, has many pages through pactures
model; Page (has many pagepictures, has many pictures through pagepictures.)
model PagePicture (belongs to page, belongs to picture) (plus some sort of
position attribute or something.
It sounds like you're testing the pages stuff and the pictures stuff in
separate features, but you need both for both features.
I might do soemthing like:
Given I have a page with a bunch of pictures
then in my step definitions do something like
Given ... do
PagePicture.create!(:position => 3, :picture_id => Picture.make, :page_id =>
This is using machinist (http://github.com/notahat/machinist/tree/master)
blueprints, which save a lot of time in features.
I tend to avoid calling steps in other steps, as right now it appears that
cucumber does not tell you which step within the step is pending if you have
it wrong, but just says that the entire one is pending. I prefer to separate
them. If it's something more complex than the above, I might make a method
that would do the creation, and then call it from both steps. So I guess
that is more like #2 of your question.
I'm sure there are much better ways of doing this though...just my strategy
On Tue, Dec 2, 2008 at 2:41 PM, James Byrne <lists at ruby-forum.com> wrote:
> I am perplexed by a situation that I am creating for myself, probably
> out of ignorance. I have two models connected through a join table
> which itself contains information related to the join. I am testing the
> creation of this join.
> I already have step definitions written for one of the outside models
> that include methods to create new records. I say methods because I
> have broken down the processing to initializing the model instance,
> populating the attributes, and then saving it.
> Now, where I think I may be about to commit a grave error is in the step
> definitions for the features relating to the join model. Which path
> should I take:
> 1. Call the existing step definitions in the outer model to create a
> test instance? or
> 2. Replicate the effect of those existing steps inside the step
> definition file for the join model and create test instances of the
> outer models completely from within that file.
> Posted via http://www.ruby-forum.com/.
> rspec-users mailing list
> rspec-users at rubyforge.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the rspec-users