[rspec-users] Then I should be on /users/3/posts/8/comments/2/edit

Pat Maddox pat.maddox at gmail.com
Fri Apr 10 12:40:09 EDT 2009

On Fri, Apr 10, 2009 at 8:49 AM, Lenny Marks <lenny at aps.org> wrote:
> On Apr 10, 2009, at 12:51 AM, Ben Mabey wrote:
>> Gavin Hughes wrote:
>>> "Then I should be on /users/3/posts/8/comments/2/edit"
>>> What's the solution for parsing out and matching and arbitrarily deep
>>> nested route?
>> Hi Gavin,
>> Let me try to answer your question without actually answering it. :)
>> I generally don't test my URLs.  IMO, for the majority of cases the URL is
>> merely an implementation detail of the application.  For example I could
>> easily see the URL in your example (/users/3/posts/8/comments/2/edit) as
>> being "/posts/8/comments/2/edit" or "/comments/2/edit" or
>> "/posts/the-name/comments/2/edit".  The user would be fine with all of these
>> cases, they really don't care one way or the other.  Instead of focusing on
>> an implementation detail of the application scenarios should be focused on
>> the behaviour that the user would like to see.  In your particular case what
>> the user really cares about is being able to edit a comment, correct?  So,
>> instead of just verifying that the user is on the right page after clicking
>> on "Edit Comment", you should have the user actually fill out the form to
>> edit the comment.  Then verify that the comment is actually updated on the
>> post's page after they submit the comment editing form.
> One place I've actually been interested in testing URLs was to verify that
> the app actually redirected after a form submission. The user facing reason
> for this is to verify that the app works as expected(e.g. doesn't repost a
> comment or something) when the user refreshes to get fresh data. Of course,
> sticking to what the user cares about, it would probably be best to have
> this tested in a separate scenario for 'user refreshes page after posting
> comment' .

I would just test that at the controller level

it "should redirect to the comment's article" do
  post :create, :article_id => @article.to_param, :comment => {:body => "wooo"}
  response.should redirect_to(@article)


More information about the rspec-users mailing list