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

Stephen Eley sfeley at gmail.com
Fri Apr 10 23:48:31 EDT 2009

On Fri, Apr 10, 2009 at 11:49 AM, Lenny Marks <lenny at aps.org> wrote:
> One place I've actually been interested in testing URLs was to verify that
> the app actually redirected after a form submission.

I can agree with this, and I had a similar need just the other day.  I
had an action that redirected to different places depending on whether
a certain box was checked.  But I didn't spec it by checking the
literal text of URL itself.  Instead I worked with the paths
functionality that was already in Cucumber's support directory, and
made it a bit more flexible.  Here was my situation:

 Scenario: Has an Enclosure
   Given I am a contributor
    When I go to the create episode page
     And I fill in [...blah blah, submitting the form...]
    Then I should have an episode titled "Any title"
     And I should be on the create enclosure page for that episode

...I wanted that "I should be on (foo) for that (bar)" to be general,
so in my application_steps.rb:

Then /^I should be on (.*page) for that (.*)$/ do |page, element|
  current_url.should == path_to(page, instance_variable_get("@#{element}"))

...And finally, I rewrote the path_to method in paths.rb a bit:

  def path_to(page_name, parent_object = nil)
    case page_name
    [ . . . ]
    when /the create enclosure page/i

This all worked, and it worked well.  Though of course, going through
the work of specing and building a separate enclosure model made me
decide that it would really work better as a simple Paperclip
attribute inside episode, so I threw all that away...  But c'est la
vie.  >8->

Have Fun,
   Steve Eley (sfeley at gmail.com)
   ESCAPE POD - The Science Fiction Podcast Magazine

More information about the rspec-users mailing list