| 1 |
diff -Naru --exclude=.svn --exclude='*~' tarantula.orig/lib/relevance/tarantula/form.rb tarantula.hpricot/lib/relevance/tarantula/form.rb |
|---|
| 2 |
--- tarantula.orig/lib/relevance/tarantula/form.rb 2008-05-03 18:49:16.000000000 -0400 |
|---|
| 3 |
+++ tarantula.hpricot/lib/relevance/tarantula/form.rb 2008-05-03 23:47:25.000000000 -0400 |
|---|
| 4 |
@@ -1,6 +1,6 @@ |
|---|
| 5 |
class Relevance::Tarantula::Form |
|---|
| 6 |
extend Forwardable |
|---|
| 7 |
- def_delegators("@tag", :find_all) |
|---|
| 8 |
+ def_delegators("@tag", :search) |
|---|
| 9 |
|
|---|
| 10 |
def initialize(tag) |
|---|
| 11 |
@tag = tag |
|---|
| 12 |
@@ -15,7 +15,7 @@ |
|---|
| 13 |
end |
|---|
| 14 |
|
|---|
| 15 |
def rails_method_hack |
|---|
| 16 |
- (tag = @tag.find(:tag => 'input', :attributes => { :name => '_method'})) && tag["value"] |
|---|
| 17 |
+ (tag = @tag.at('input[@name="_method"]')) && tag["value"] |
|---|
| 18 |
end |
|---|
| 19 |
|
|---|
| 20 |
end |
|---|
| 21 |
diff -Naru --exclude=.svn --exclude='*~' tarantula.orig/lib/relevance/tarantula/form_submission.rb tarantula.hpricot/lib/relevance/tarantula/form_submission.rb |
|---|
| 22 |
--- tarantula.orig/lib/relevance/tarantula/form_submission.rb 2008-05-03 18:49:16.000000000 -0400 |
|---|
| 23 |
+++ tarantula.hpricot/lib/relevance/tarantula/form_submission.rb 2008-05-03 23:47:25.000000000 -0400 |
|---|
| 24 |
@@ -17,7 +17,7 @@ |
|---|
| 25 |
end |
|---|
| 26 |
|
|---|
| 27 |
def create_random_data_for(form, tag_selector) |
|---|
| 28 |
- form.find_all(tag_selector).inject({}) do |form_args, input| |
|---|
| 29 |
+ form.search(tag_selector).inject({}) do |form_args, input| |
|---|
| 30 |
# TODO: test |
|---|
| 31 |
form_args[input['name']] = random_data(input) if input['name'] |
|---|
| 32 |
form_args |
|---|
| 33 |
@@ -25,16 +25,16 @@ |
|---|
| 34 |
end |
|---|
| 35 |
|
|---|
| 36 |
def mutate_inputs(form) |
|---|
| 37 |
- create_random_data_for(form, :tag => 'input') |
|---|
| 38 |
+ create_random_data_for(form, 'input') |
|---|
| 39 |
end |
|---|
| 40 |
|
|---|
| 41 |
def mutate_text_areas(form) |
|---|
| 42 |
- create_random_data_for(form, :tag => 'textarea') |
|---|
| 43 |
+ create_random_data_for(form, 'textarea') |
|---|
| 44 |
end |
|---|
| 45 |
|
|---|
| 46 |
def mutate_selects(form) |
|---|
| 47 |
- form.find_all(:tag => 'select').inject({}) do |form_args, select| |
|---|
| 48 |
- options = select.find_all(:tag => 'option') |
|---|
| 49 |
+ form.search('select').inject({}) do |form_args, select| |
|---|
| 50 |
+ options = select.search('option') |
|---|
| 51 |
option = options.rand |
|---|
| 52 |
form_args[select['name']] = option['value'] |
|---|
| 53 |
form_args |
|---|
| 54 |
@@ -46,6 +46,7 @@ |
|---|
| 55 |
when /amount/ : random_int |
|---|
| 56 |
when /_id$/ : random_whole_number |
|---|
| 57 |
when /uploaded_data/ : nil |
|---|
| 58 |
+ when /^_method$/ : input['value'] |
|---|
| 59 |
when nil : input['value'] |
|---|
| 60 |
else random_int |
|---|
| 61 |
end |
|---|
| 62 |
diff -Naru --exclude=.svn --exclude='*~' tarantula.orig/lib/relevance/tarantula/html_document_handler.rb tarantula.hpricot/lib/relevance/tarantula/html_document_handler.rb |
|---|
| 63 |
--- tarantula.orig/lib/relevance/tarantula/html_document_handler.rb 2008-05-03 18:49:16.000000000 -0400 |
|---|
| 64 |
+++ tarantula.hpricot/lib/relevance/tarantula/html_document_handler.rb 2008-05-03 23:49:03.000000000 -0400 |
|---|
| 65 |
@@ -1,3 +1,5 @@ |
|---|
| 66 |
+require 'hpricot' |
|---|
| 67 |
+ |
|---|
| 68 |
class Relevance::Tarantula::HtmlDocumentHandler |
|---|
| 69 |
extend Forwardable |
|---|
| 70 |
def_delegators("@crawler", :queue_link, :queue_form) |
|---|
| 71 |
@@ -10,7 +12,7 @@ |
|---|
| 72 |
def html_doc_without_stderr_noise(html) |
|---|
| 73 |
body = nil |
|---|
| 74 |
Recording.stderr do |
|---|
| 75 |
- body = HTML::Document.new html |
|---|
| 76 |
+ body = Hpricot html |
|---|
| 77 |
end |
|---|
| 78 |
body |
|---|
| 79 |
end |
|---|
| 80 |
@@ -19,14 +21,14 @@ |
|---|
| 81 |
url = result.url |
|---|
| 82 |
return unless response.html? |
|---|
| 83 |
body = html_doc_without_stderr_noise(response.body) |
|---|
| 84 |
- body.find_all(:tag=>'a').each do |tag| |
|---|
| 85 |
+ body.search('a').each do |tag| |
|---|
| 86 |
queue_link(tag['href'], url) |
|---|
| 87 |
end |
|---|
| 88 |
- body.find_all(:tag=>'link').each do |tag| |
|---|
| 89 |
+ body.search('link').each do |tag| |
|---|
| 90 |
queue_link(tag['href'], url) |
|---|
| 91 |
end |
|---|
| 92 |
- body.find_all(:tag =>'form').each do |form| |
|---|
| 93 |
- form.attributes['action'] = url unless form.attributes['action'] |
|---|
| 94 |
+ body.search('form').each do |form| |
|---|
| 95 |
+ form['action'] = url unless form['action'] |
|---|
| 96 |
queue_form(form, url) |
|---|
| 97 |
end |
|---|
| 98 |
nil |
|---|
| 99 |
diff -Naru --exclude=.svn --exclude='*~' tarantula.orig/test/relevance/tarantula/crawler_test.rb tarantula.hpricot/test/relevance/tarantula/crawler_test.rb |
|---|
| 100 |
--- tarantula.orig/test/relevance/tarantula/crawler_test.rb 2008-05-03 18:49:16.000000000 -0400 |
|---|
| 101 |
+++ tarantula.hpricot/test/relevance/tarantula/crawler_test.rb 2008-05-03 23:49:38.000000000 -0400 |
|---|
| 102 |
@@ -82,7 +82,7 @@ |
|---|
| 103 |
|
|---|
| 104 |
it 'queues and remembers forms' do |
|---|
| 105 |
crawler = Crawler.new |
|---|
| 106 |
- form = HTML::Document.new('<form action="/action" method="post"/>').find(:tag =>'form') |
|---|
| 107 |
+ form = Hpricot('<form action="/action" method="post"/>').at('form') |
|---|
| 108 |
signature = FormSubmission.new(Form.new(form)).signature |
|---|
| 109 |
crawler.queue_form(form) |
|---|
| 110 |
crawler.forms_to_crawl.size.should == 1 |
|---|
| 111 |
@@ -286,4 +286,4 @@ |
|---|
| 112 |
crawler = Crawler.new |
|---|
| 113 |
lambda{crawler.foo}.should.raise(NoMethodError) |
|---|
| 114 |
end |
|---|
| 115 |
-end |
|---|
| 116 |
\ No newline at end of file |
|---|
| 117 |
+end |
|---|
| 118 |
diff -Naru --exclude=.svn --exclude='*~' tarantula.orig/test/relevance/tarantula/form_submission_test.rb tarantula.hpricot/test/relevance/tarantula/form_submission_test.rb |
|---|
| 119 |
--- tarantula.orig/test/relevance/tarantula/form_submission_test.rb 2008-05-03 18:49:16.000000000 -0400 |
|---|
| 120 |
+++ tarantula.hpricot/test/relevance/tarantula/form_submission_test.rb 2008-05-03 23:47:25.000000000 -0400 |
|---|
| 121 |
@@ -4,7 +4,7 @@ |
|---|
| 122 |
|
|---|
| 123 |
# TODO: add more from field types to this example form as needed |
|---|
| 124 |
before do |
|---|
| 125 |
- @tag = HTML::Document.new(<<END) |
|---|
| 126 |
+ @tag = Hpricot(<<END) |
|---|
| 127 |
<form action="/session" method="post"> |
|---|
| 128 |
<input id="email" name="email" size="30" type="text" /> |
|---|
| 129 |
<textarea id="comment" name="comment"value="1" /> |
|---|
| 130 |
@@ -16,7 +16,7 @@ |
|---|
| 131 |
</select> |
|---|
| 132 |
</form> |
|---|
| 133 |
END |
|---|
| 134 |
- @form = Relevance::Tarantula::Form.new(@tag.find(:tag => 'form')) |
|---|
| 135 |
+ @form = Relevance::Tarantula::Form.new(@tag.at('form')) |
|---|
| 136 |
@fs = Relevance::Tarantula::FormSubmission.new(@form) |
|---|
| 137 |
end |
|---|
| 138 |
|
|---|
| 139 |
@@ -26,7 +26,7 @@ |
|---|
| 140 |
end |
|---|
| 141 |
|
|---|
| 142 |
it "can mutate selects" do |
|---|
| 143 |
- Array.any_instance.stubs(:rand).returns(stub(:[] => "2006-stub")) |
|---|
| 144 |
+ Hpricot::Elements.any_instance.stubs(:rand).returns(stub(:[] => "2006-stub")) |
|---|
| 145 |
@fs.mutate_selects(@form).should == {"foo[opened_on(1i)]" => "2006-stub"} |
|---|
| 146 |
end |
|---|
| 147 |
|
|---|
| 148 |
@@ -56,12 +56,12 @@ |
|---|
| 149 |
|
|---|
| 150 |
describe "Relevance::Tarantula::FormSubmission for a crummy form" do |
|---|
| 151 |
before do |
|---|
| 152 |
- @tag = HTML::Document.new(<<END) |
|---|
| 153 |
+ @tag = Hpricot(<<END) |
|---|
| 154 |
<form action="/session" method="post"> |
|---|
| 155 |
<input value="no_name" /> |
|---|
| 156 |
</form> |
|---|
| 157 |
END |
|---|
| 158 |
- @form = Relevance::Tarantula::Form.new(@tag.find(:tag => 'form')) |
|---|
| 159 |
+ @form = Relevance::Tarantula::Form.new(@tag.at('form')) |
|---|
| 160 |
@fs = Relevance::Tarantula::FormSubmission.new(@form) |
|---|
| 161 |
end |
|---|
| 162 |
|
|---|
| 163 |
diff -Naru --exclude=.svn --exclude='*~' tarantula.orig/test/relevance/tarantula/form_test.rb tarantula.hpricot/test/relevance/tarantula/form_test.rb |
|---|
| 164 |
--- tarantula.orig/test/relevance/tarantula/form_test.rb 2008-05-03 18:49:16.000000000 -0400 |
|---|
| 165 |
+++ tarantula.hpricot/test/relevance/tarantula/form_test.rb 2008-05-03 23:47:25.000000000 -0400 |
|---|
| 166 |
@@ -2,7 +2,7 @@ |
|---|
| 167 |
|
|---|
| 168 |
describe "Relevance::Tarantula::Form large example" do |
|---|
| 169 |
before do |
|---|
| 170 |
- @tag = HTML::Document.new(<<END) |
|---|
| 171 |
+ @tag = Hpricot(<<END) |
|---|
| 172 |
<form action="/session" method="post"> |
|---|
| 173 |
<input name="authenticity_token" type="hidden" value="1be0d07c6e13669a87b8f52a3c7e1d1ffa77708d" /> |
|---|
| 174 |
<input id="email" name="email" size="30" type="text" /> |
|---|
| 175 |
@@ -11,7 +11,7 @@ |
|---|
| 176 |
<input name="commit" type="submit" value="Log in" /> |
|---|
| 177 |
</form> |
|---|
| 178 |
END |
|---|
| 179 |
- @form = Relevance::Tarantula::Form.new(@tag.find(:tag => 'form')) |
|---|
| 180 |
+ @form = Relevance::Tarantula::Form.new(@tag.at('form')) |
|---|
| 181 |
end |
|---|
| 182 |
|
|---|
| 183 |
it "has an action" do |
|---|
| 184 |
@@ -26,21 +26,21 @@ |
|---|
| 185 |
|
|---|
| 186 |
describe "A Relevance::Tarantula::Form" do |
|---|
| 187 |
it "defaults method to 'get'" do |
|---|
| 188 |
- @tag = HTML::Document.new("<form/>") |
|---|
| 189 |
- @form = Relevance::Tarantula::Form.new(@tag.find(:tag => 'form')) |
|---|
| 190 |
+ @tag = Hpricot("<form/>") |
|---|
| 191 |
+ @form = Relevance::Tarantula::Form.new(@tag.at('form')) |
|---|
| 192 |
@form.method.should == 'get' |
|---|
| 193 |
end |
|---|
| 194 |
end |
|---|
| 195 |
|
|---|
| 196 |
describe "A Relevance::Tarantula::Form with a hacked _method" do |
|---|
| 197 |
before do |
|---|
| 198 |
- @tag = HTML::Document.new(<<END) |
|---|
| 199 |
+ @tag = Hpricot(<<END) |
|---|
| 200 |
<form action="/foo"> |
|---|
| 201 |
<input name="authenticity_token" type="hidden" value="1be0d07c6e13669a87b8f52a3c7e1d1ffa77708d" /> |
|---|
| 202 |
<input id="_method" name="_method" size="30" type="text" value="PUT"/> |
|---|
| 203 |
</form> |
|---|
| 204 |
END |
|---|
| 205 |
- @form = Relevance::Tarantula::Form.new(@tag.find(:tag => 'form')) |
|---|
| 206 |
+ @form = Relevance::Tarantula::Form.new(@tag.at('form')) |
|---|
| 207 |
end |
|---|
| 208 |
|
|---|
| 209 |
it "has a method" do |
|---|
| 210 |
diff -Naru --exclude=.svn --exclude='*~' tarantula.orig/test/relevance/tarantula/html_document_handler_test.rb tarantula.hpricot/test/relevance/tarantula/html_document_handler_test.rb |
|---|
| 211 |
--- tarantula.orig/test/relevance/tarantula/html_document_handler_test.rb 2008-05-03 18:49:16.000000000 -0400 |
|---|
| 212 |
+++ tarantula.hpricot/test/relevance/tarantula/html_document_handler_test.rb 2008-05-03 23:53:38.000000000 -0400 |
|---|
| 213 |
@@ -30,7 +30,7 @@ |
|---|
| 214 |
end |
|---|
| 215 |
|
|---|
| 216 |
it "queues forms" do |
|---|
| 217 |
- @handler.expects(:queue_form).with{|tag,referrer| HTML::Tag === tag} |
|---|
| 218 |
+ @handler.expects(:queue_form).with{|tag,referrer| Hpricot::Elem === tag} |
|---|
| 219 |
@handler.handle(Result.new(:response => stub(:html? => true, :body => '<form>stuff</form>'))) |
|---|
| 220 |
end |
|---|
| 221 |
|
|---|