Spider Test, an Introduction

January 3rd, 2008

Since I recently blogged about Spider Test I have had a few people asking questions. In an attempt to clear some things up I will show a sample of how to put the test together. First install the plugin into your rails app

# script/plugin install svn://caboo.se/plugins/court3nay/spider_test

Then generate an integration test

# script/generate integration_test spider
Now put the essentials into your test
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

require "#{File.dirname(__FILE__)}/../test_helper"

class SpiderTest < ActionController::IntegrationTest
  fixtures :all
  
  include Caboose::SpiderIntegrator

  def test_spider
    get '/account/login'
    assert_response :success
    post '/account/login', :login => 'quentin', :password => 'test'
    assert session[:user]
    assert_response :redirect
    assert_redirected_to '/'
    follow_redirect!

    spider(@response.body, '/', 
      :ignore_urls => ['/login', %r{^.+logout}, %r{^.+delete.?}, %r{^.+/destroy.?},
      :ignore_forms => [], :verbose => true)
  end
end
This simulates a logged in user. When you run this test it will find and follow any link it finds and fill out any form it comes in contact with. This is just a primer, so use this to get you started and then go nuts on your own. You will really appreciate this plugin in short order!

Sorry, comments are closed for this article.

-U:**- index.html.erb   (Ruby RoR RHTML)
M-x visit-site http://aaronbedra.com