[rspec-users] Can't test for page content after a redirect

Christian Lescuyer lists at ruby-forum.com
Fri Aug 8 13:29:19 EDT 2008


Thanks Zach! It worked like a charm.

Finally I used:

  Scenario: User enters a bookmark URL
    When the user adds 'http://www.gotapi.com/rubyrails' as a bookmark
    Then the database should have a bookmark with url 
'http://www.gotapi.com/rubyrails'
    And  the page should contain 'http://www.gotapi.com/rubyrails'

and in bookmark_steps.rb:

  When "the user adds '$string' as a bookmark" do |string|
    post "/bookmarks/create", :bookmark => { :url => string }
    follow_all_redirects
  end

  Then "the database should have a bookmark with url '$url'" do |url|
    Bookmark.find_by_url(url).should_not be_nil
  end

  Then "the page should contain '$stuff'" do  |stuff|
    response.should have_text(/#{stuff}/)
  end
end

def follow_all_redirects
  if response.content_type == "text/html"
    follow_redirect! while response.redirect?
  end
  true
end

I skipped the Javascript right now, I'll add it when the time comes.

Xtian
-- 
Posted via http://www.ruby-forum.com/.


More information about the rspec-users mailing list