public
Description: automagic integration testing for your rails app
Clone URL: git://github.com/courtenay/spider_test.git
Search Repo:
Move to Hpricot (Thanks, Jason)
Court3nay (author)
Mon Apr 14 13:24:38 -0700 2008
commit  8056532373529557bc6a6e4e39a818f966237abd
tree    43f90442ca6ad7b9e01fb3478571bead1e77b893
parent  6c4f27abb6d8231dad3adbb951fd77322d5dd993
...
 
 
 
 
1
2
3
...
1
2
3
4
5
6
7
0
@@ -1,3 +1,7 @@
0
+Added: Now uses Hpricot instead of HTML::Document for a ~10% speedup.
0
+
0
+Moved to GitHub
0
+
0
 Fixed: Workaround for inputs without a name (e.g. input type="button" onclick="...")
0
 Fixed: Now accepts form method="GET" as well as "get"
0
 Fixed: Better static file checking (checks if rails can generate it, THEN checks if the static file exists
...
78
79
80
 
81
82
83
...
115
116
117
118
119
 
 
120
121
122
 
123
124
125
126
 
127
128
129
 
130
131
132
...
78
79
80
81
82
83
84
...
116
117
118
 
 
119
120
121
122
 
123
124
125
126
 
127
128
129
 
130
131
132
133
0
@@ -78,6 +78,7 @@ require 'caboose'
0
 # locations, and up until now this has been impossible to test in an automated fashion
0
 # or without being strongly coupled to your code.
0
 #
0
+require 'hpricot'
0
 module Caboose::SpiderIntegrator
0
 
0
   # Begin spidering your application.
0
@@ -115,18 +116,18 @@ module Caboose::SpiderIntegrator
0
   # todo: use hpricot or something else more fun (we will need to validate
0
   # the html in this case since HTML::Document does it by default)
0
   def consume_page( html, url )
0
- body = HTML::Document.new html
0
- body.find_all(:tag=>'a').each do |tag|
0
+ body = Hpricot html
0
+ body.search('a').each do |tag|
0
       queue_link( tag, url )
0
     end
0
- body.find_all(:tag=>'link').each do |tag|
0
+ body.search('link').each do |tag|
0
       # Strip appended browser-caching numbers from asset paths like ?12341234
0
       queue_link( tag, url )
0
     end
0
- body.find_all(:tag => 'input', :attributes => { :name => nil }) do |input|
0
+ body.search('input[name=""]') do |input|
0
       queue_link( tag, url ) if tag['onclick']
0
     end
0
- body.find_all(:tag =>'form').each do |form|
0
+ body.search('form').each do |form|
0
       form = SpiderableForm.new form
0
       queue_form( form, url )
0
     end
...
 
1
2
3
...
15
16
17
18
19
 
 
20
21
22
23
24
25
 
26
27
28
...
52
53
54
55
 
56
57
58
59
 
 
60
61
62
...
1
2
3
4
...
16
17
18
 
 
19
20
21
22
23
24
25
 
26
27
28
29
...
53
54
55
 
56
57
58
 
 
59
60
61
62
63
0
@@ -1,3 +1,4 @@
0
+require 'hpricot'
0
 module Caboose::SpiderIntegrator
0
   
0
   # This is an abstract representation of a form that we can spider.
0
@@ -15,14 +16,14 @@ module Caboose::SpiderIntegrator
0
       @method = m.downcase if m
0
     end
0
     
0
- def find_all(*args)
0
- @form.find_all(*args)
0
+ def search(*args)
0
+ @form.search(*args)
0
     end
0
     
0
     def mutate_inputs!(mutate_existing_values = false)
0
       input_hash = mutate_existing_values ? { '_mutated' => true } : { '_modified' => true }
0
     
0
- @form.find_all(:tag => 'input').each do |input|
0
+ @form.search('input').each do |input|
0
         if input['name'] == '_method' # and value.in?['put','post',..] # rails is faking the post/put etc
0
           self.method = input['value']
0
         else
0
@@ -52,11 +53,11 @@ module Caboose::SpiderIntegrator
0
           end
0
         end
0
       end
0
- @form.find_all(:tag => 'textarea').each do |input|
0
+ @form.search('textarea').each do |input|
0
         input_hash[ input['name'] ] = create_data(input, mutate_existing_values)
0
       end
0
- @form.find_all(:tag => 'select').each do |select|
0
- options = select.find_all(:tag => 'option')
0
+ @form.search('select').each do |select|
0
+ options = select.search('option')
0
         option = options[ rand(options.length) ]
0
         input_hash[ select['name'] ] = option['value']
0
       end

Comments

    No one has commented yet.