cobweb 1.0.11 → 1.0.12
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +4 -3
- data/lib/cobweb.rb +31 -8
- data/lib/cobweb_crawler.rb +7 -8
- data/lib/cobweb_process_job.rb +1 -1
- data/lib/cobweb_version.rb +1 -1
- data/lib/crawl.rb +11 -4
- data/lib/crawl_finished_worker.rb +27 -0
- data/lib/crawl_helper.rb +250 -0
- data/lib/crawl_job.rb +2 -2
- data/lib/crawl_process_worker.rb +31 -0
- data/lib/crawl_worker.rb +118 -0
- data/lib/sidekiq/cobweb_helper.rb +16 -0
- data/lib/stats.rb +12 -11
- data/lib/uri_helper.rb +8 -0
- data/spec/cobweb/cobweb_crawl_helper_spec.rb +4 -1
- data/spec/cobweb/cobweb_crawl_spec.rb +29 -13
- data/spec/cobweb/cobweb_crawler_spec.rb +33 -14
- data/spec/cobweb/cobweb_links_spec.rb +2 -1
- data/spec/cobweb/cobweb_spec.rb +3 -0
- data/spec/cobweb/content_link_parser_spec.rb +4 -0
- data/spec/cobweb/{cobweb_job_spec.rb → crawl_job_spec.rb} +52 -9
- data/spec/cobweb/crawl_worker_spec.rb +250 -0
- data/spec/cobweb/robots_spec.rb +2 -1
- data/spec/http_stubs.rb +95 -0
- data/spec/samples/sample_site/{boxgrid.html → boxgrid>withsillyname.html} +1 -1
- data/spec/samples/sample_site/dashboard.html +1 -1
- data/spec/samples/sample_site/forms.html +1 -1
- data/spec/samples/sample_site/gallery.html +1 -1
- data/spec/samples/sample_site/more.html +1 -1
- data/spec/samples/sample_site/tables.html +1 -1
- data/spec/samples/sample_site/typography.html +1 -1
- data/spec/spec_helper.rb +6 -88
- metadata +85 -35
- data/spec/cobweb/site_test_spec.rb.tmp +0 -101
@@ -0,0 +1,250 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
#require 'sidekiq/testing'
|
3
|
+
|
4
|
+
describe CrawlWorker, :local_only => true do
|
5
|
+
|
6
|
+
before(:all) do
|
7
|
+
#store all existing resque process ids so we don't kill them afterwards
|
8
|
+
@existing_processes = `ps aux | grep sidekiq | grep -v grep | awk '{print $2}'`.split("\n")
|
9
|
+
puts @existing_processes
|
10
|
+
@existing_processes.should be_empty
|
11
|
+
|
12
|
+
# START WORKERS ONLY FOR CRAWL QUEUE SO WE CAN COUNT ENQUEUED PROCESS AND FINISH QUEUES
|
13
|
+
puts "Starting Workers... Please Wait..."
|
14
|
+
`mkdir log`
|
15
|
+
`rm -rf output.log`
|
16
|
+
io = IO.popen("nohup sidekiq -r ./lib/crawl_worker.rb -q crawl_worker > ./log/output.log &")
|
17
|
+
puts "Workers Started."
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
before(:each) do
|
22
|
+
@base_url = "http://localhost:3532/"
|
23
|
+
@base_page_count = 77
|
24
|
+
|
25
|
+
clear_queues
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "with no crawl limit" do
|
29
|
+
before(:each) do
|
30
|
+
@request = {
|
31
|
+
:crawl_id => Digest::SHA1.hexdigest("#{Time.now.to_i}.#{Time.now.usec}"),
|
32
|
+
:crawl_limit => nil,
|
33
|
+
:quiet => false,
|
34
|
+
:debug => false,
|
35
|
+
:cache => nil,
|
36
|
+
:queue_system => :sidekiq
|
37
|
+
}
|
38
|
+
@cobweb = Cobweb.new @request
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should crawl entire site" do
|
42
|
+
crawl = @cobweb.start(@base_url)
|
43
|
+
@stat = Stats.new({:crawl_id => crawl[:crawl_id]})
|
44
|
+
wait_for_crawl_finished crawl[:crawl_id]
|
45
|
+
CrawlProcessWorker.queue_size.should == @base_page_count
|
46
|
+
end
|
47
|
+
it "detect crawl finished" do
|
48
|
+
crawl = @cobweb.start(@base_url)
|
49
|
+
@stat = Stats.new({:crawl_id => crawl[:crawl_id]})
|
50
|
+
wait_for_crawl_finished crawl[:crawl_id]
|
51
|
+
CrawlFinishedWorker.queue_size.should == 1
|
52
|
+
end
|
53
|
+
end
|
54
|
+
describe "with limited mime_types" do
|
55
|
+
before(:each) do
|
56
|
+
@request = {
|
57
|
+
:crawl_id => Digest::SHA1.hexdigest("#{Time.now.to_i}.#{Time.now.usec}"),
|
58
|
+
:quiet => true,
|
59
|
+
:cache => nil,
|
60
|
+
:queue_system => :sidekiq,
|
61
|
+
:valid_mime_types => ["text/html"]
|
62
|
+
}
|
63
|
+
@cobweb = Cobweb.new @request
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should only crawl html pages" do
|
67
|
+
crawl = @cobweb.start(@base_url)
|
68
|
+
@stat = Stats.new({:crawl_id => crawl[:crawl_id]})
|
69
|
+
wait_for_crawl_finished crawl[:crawl_id]
|
70
|
+
CrawlProcessWorker.queue_size.should == 8
|
71
|
+
|
72
|
+
mime_types = CrawlProcessWorker.queue_items(0, 100).map{|job| JSON.parse(job)["args"][0]["mime_type"]}
|
73
|
+
|
74
|
+
mime_types.count.should == 8
|
75
|
+
mime_types.map{|m| m.should == "text/html"}
|
76
|
+
mime_types.select{|m| m=="text/html"}.count.should == 8
|
77
|
+
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
describe "with a crawl limit" do
|
83
|
+
before(:each) do
|
84
|
+
@request = {
|
85
|
+
:crawl_id => Digest::SHA1.hexdigest("#{Time.now.to_i}.#{Time.now.usec}"),
|
86
|
+
:quiet => true,
|
87
|
+
:queue_system => :sidekiq,
|
88
|
+
:cache => nil
|
89
|
+
}
|
90
|
+
end
|
91
|
+
|
92
|
+
describe "of 1" do
|
93
|
+
before(:each) do
|
94
|
+
@request[:crawl_limit] = 1
|
95
|
+
@cobweb = Cobweb.new @request
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should not crawl the entire site" do
|
99
|
+
crawl = @cobweb.start(@base_url)
|
100
|
+
@stat = Stats.new({:crawl_id => crawl[:crawl_id]})
|
101
|
+
wait_for_crawl_finished crawl[:crawl_id]
|
102
|
+
CrawlProcessWorker.queue_size.should_not == @base_page_count
|
103
|
+
end
|
104
|
+
it "should only crawl 1 page" do
|
105
|
+
crawl = @cobweb.start(@base_url)
|
106
|
+
@stat = Stats.new({:crawl_id => crawl[:crawl_id]})
|
107
|
+
wait_for_crawl_finished crawl[:crawl_id]
|
108
|
+
CrawlProcessWorker.queue_size.should == 1
|
109
|
+
end
|
110
|
+
it "should notify of crawl finished" do
|
111
|
+
crawl = @cobweb.start(@base_url)
|
112
|
+
@stat = Stats.new({:crawl_id => crawl[:crawl_id]})
|
113
|
+
wait_for_crawl_finished crawl[:crawl_id]
|
114
|
+
CrawlFinishedWorker.queue_size.should == 1
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
118
|
+
|
119
|
+
describe "of 5" do
|
120
|
+
before(:each) do
|
121
|
+
@request[:crawl_limit] = 5
|
122
|
+
end
|
123
|
+
|
124
|
+
describe "limiting count to html pages only" do
|
125
|
+
before(:each) do
|
126
|
+
@request[:crawl_limit_by_page] = true
|
127
|
+
@cobweb = Cobweb.new @request
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should only use html pages towards the crawl limit" do
|
131
|
+
crawl = @cobweb.start(@base_url)
|
132
|
+
@stat = Stats.new({:crawl_id => crawl[:crawl_id]})
|
133
|
+
wait_for_crawl_finished crawl[:crawl_id]
|
134
|
+
|
135
|
+
mime_types = CrawlProcessWorker.queue_items(0, 200).map{|job| JSON.parse(job)["args"][0]["mime_type"]}
|
136
|
+
ap mime_types
|
137
|
+
mime_types.select{|m| m=="text/html"}.count.should == 5
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
describe "of 10" do
|
143
|
+
before(:each) do
|
144
|
+
@request[:crawl_limit] = 10
|
145
|
+
@cobweb = Cobweb.new @request
|
146
|
+
end
|
147
|
+
|
148
|
+
it "should not crawl the entire site" do
|
149
|
+
crawl = @cobweb.start(@base_url)
|
150
|
+
@stat = Stats.new({:crawl_id => crawl[:crawl_id]})
|
151
|
+
wait_for_crawl_finished crawl[:crawl_id]
|
152
|
+
CrawlProcessWorker.queue_size.should_not == @base_page_count
|
153
|
+
end
|
154
|
+
it "should notify of crawl finished" do
|
155
|
+
crawl = @cobweb.start(@base_url)
|
156
|
+
@stat = Stats.new({:crawl_id => crawl[:crawl_id]})
|
157
|
+
wait_for_crawl_finished crawl[:crawl_id]
|
158
|
+
CrawlFinishedWorker.queue_size.should == 1
|
159
|
+
end
|
160
|
+
it "should only crawl 10 objects" do
|
161
|
+
crawl = @cobweb.start(@base_url)
|
162
|
+
@stat = Stats.new({:crawl_id => crawl[:crawl_id]})
|
163
|
+
wait_for_crawl_finished crawl[:crawl_id]
|
164
|
+
CrawlProcessWorker.queue_size.should == 10
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
describe "of 100" do
|
169
|
+
before(:each) do
|
170
|
+
@request[:crawl_limit] = 100
|
171
|
+
@cobweb = Cobweb.new @request
|
172
|
+
end
|
173
|
+
|
174
|
+
it "should crawl the entire sample site" do
|
175
|
+
crawl = @cobweb.start(@base_url)
|
176
|
+
@stat = Stats.new({:crawl_id => crawl[:crawl_id]})
|
177
|
+
wait_for_crawl_finished crawl[:crawl_id]
|
178
|
+
CrawlProcessWorker.queue_size.should == @base_page_count
|
179
|
+
end
|
180
|
+
it "should notify of crawl finished" do
|
181
|
+
crawl = @cobweb.start(@base_url)
|
182
|
+
@stat = Stats.new({:crawl_id => crawl[:crawl_id]})
|
183
|
+
wait_for_crawl_finished crawl[:crawl_id]
|
184
|
+
CrawlFinishedWorker.queue_size.should == 1
|
185
|
+
end
|
186
|
+
it "should not crawl 100 pages" do
|
187
|
+
crawl = @cobweb.start(@base_url)
|
188
|
+
@stat = Stats.new({:crawl_id => crawl[:crawl_id]})
|
189
|
+
wait_for_crawl_finished crawl[:crawl_id]
|
190
|
+
CrawlProcessWorker.queue_size.should_not == 100
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
after(:all) do
|
196
|
+
@all_processes = `ps aux | grep sidekiq | grep -v grep | grep -v sidekiq-web | awk '{print $2}'`.split("\n")
|
197
|
+
unless (@all_processes - @existing_processes).empty?
|
198
|
+
command = "kill #{(@all_processes - @existing_processes).join(" ")}"
|
199
|
+
IO.popen(command)
|
200
|
+
end
|
201
|
+
clear_queues
|
202
|
+
end
|
203
|
+
|
204
|
+
end
|
205
|
+
|
206
|
+
def wait_for_crawl_finished(crawl_id, timeout=20)
|
207
|
+
@counter = 0
|
208
|
+
start_time = Time.now
|
209
|
+
while(running?(crawl_id) && Time.now < start_time + timeout) do
|
210
|
+
sleep 1
|
211
|
+
end
|
212
|
+
if Time.now > start_time + timeout
|
213
|
+
raise "End of crawl not detected"
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
def running?(crawl_id)
|
218
|
+
status = @stat.get_status
|
219
|
+
result = true
|
220
|
+
if status == CobwebCrawlHelper::STARTING
|
221
|
+
result = true
|
222
|
+
else
|
223
|
+
if status == @last_stat
|
224
|
+
if @counter > 20
|
225
|
+
raise "Static status: #{status}"
|
226
|
+
else
|
227
|
+
@counter += 1
|
228
|
+
end
|
229
|
+
else
|
230
|
+
result = status != CobwebCrawlHelper::FINISHED && status != CobwebCrawlHelper::CANCELLED
|
231
|
+
end
|
232
|
+
end
|
233
|
+
@last_stat = @stat.get_status
|
234
|
+
result
|
235
|
+
end
|
236
|
+
|
237
|
+
def clear_queues
|
238
|
+
Sidekiq.redis do |conn|
|
239
|
+
conn.smembers("queues").each do |queue_name|
|
240
|
+
conn.del("queue:#{queue_name}")
|
241
|
+
conn.srem("queues", queue_name)
|
242
|
+
end
|
243
|
+
end
|
244
|
+
sleep 2
|
245
|
+
|
246
|
+
CrawlProcessWorker.queue_size.should == 0
|
247
|
+
CrawlFinishedWorker.queue_size.should == 0
|
248
|
+
end
|
249
|
+
|
250
|
+
|
data/spec/cobweb/robots_spec.rb
CHANGED
data/spec/http_stubs.rb
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
module HttpStubs
|
2
|
+
|
3
|
+
def setup_stubs
|
4
|
+
|
5
|
+
@default_headers = {"Cache-Control" => "private, max-age=0",
|
6
|
+
"Date" => "Wed, 10 Nov 2010 09:06:17 GMT",
|
7
|
+
"Expires" => "-1",
|
8
|
+
"Content-Type" => "text/html; charset=UTF-8",
|
9
|
+
"Content-Encoding" => "",
|
10
|
+
"Transfer-Encoding" => "chunked",
|
11
|
+
"Server" => "gws",
|
12
|
+
"X-XSS-Protection" => "1; mode=block"}
|
13
|
+
|
14
|
+
@symbolized_default_headers = {:"Cache-Control" => "private, max-age=0",
|
15
|
+
:"Date" => "Wed, 10 Nov 2010 09:06:17 GMT",
|
16
|
+
:"Expires" => "-1",
|
17
|
+
:"Content-Type" => "text/html; charset=UTF-8",
|
18
|
+
:"Content-Encoding" => "",
|
19
|
+
:"Transfer-Encoding" => "chunked",
|
20
|
+
:"Server" => "gws",
|
21
|
+
:"X-XSS-Protection" => "1; mode=block"}
|
22
|
+
|
23
|
+
|
24
|
+
@mock_http_client = mock(Net::HTTP)
|
25
|
+
@mock_http_request = mock(Net::HTTPRequest)
|
26
|
+
@mock_http_robot_request = mock(Net::HTTPRequest)
|
27
|
+
@mock_http_redirect_request = mock(Net::HTTPRequest)
|
28
|
+
@mock_http_redirect_request2 = mock(Net::HTTPRequest)
|
29
|
+
|
30
|
+
@mock_http_response = mock(Net::HTTPResponse)
|
31
|
+
@mock_http_robot_response = mock(Net::HTTPResponse)
|
32
|
+
@mock_http_redirect_response = mock(Net::HTTPRedirection)
|
33
|
+
@mock_http_redirect_response2 = mock(Net::HTTPRedirection)
|
34
|
+
@mock_http_get = mock(Net::HTTP::Get)
|
35
|
+
|
36
|
+
Net::HTTP.stub!(:new).and_return(@mock_http_client)
|
37
|
+
Net::HTTP::Get.stub!(:new).and_return(@mock_http_request)
|
38
|
+
Net::HTTP::Get.stub!(:new).with("/redirect.html", an_instance_of(Hash)).and_return(@mock_http_redirect_request)
|
39
|
+
Net::HTTP::Get.stub!(:new).with("/robots.txt", an_instance_of(Hash)).and_return(@mock_http_robot_request)
|
40
|
+
Net::HTTP::Get.stub!(:new).with("/redirect2.html", an_instance_of(Hash)).and_return(@mock_http_redirect_request2)
|
41
|
+
Net::HTTP::Get.stub!(:new).with("/redirected.html", an_instance_of(Hash)).and_return(@mock_http_request)
|
42
|
+
|
43
|
+
Net::HTTP::Head.stub!(:new).and_return(@mock_http_request)
|
44
|
+
|
45
|
+
@mock_http_client.stub!(:request).with(@mock_http_request).and_return(@mock_http_response)
|
46
|
+
@mock_http_client.stub!(:request).with(@mock_http_robot_request).and_return(@mock_http_robot_response)
|
47
|
+
@mock_http_client.stub!(:request).with(@mock_http_redirect_request).and_return(@mock_http_redirect_response)
|
48
|
+
@mock_http_client.stub!(:request).with(@mock_http_redirect_request2).and_return(@mock_http_redirect_response2)
|
49
|
+
@mock_http_client.stub!(:read_timeout=).and_return(nil)
|
50
|
+
@mock_http_client.stub!(:open_timeout=).and_return(nil)
|
51
|
+
@mock_http_client.stub!(:start).and_return(@mock_http_response)
|
52
|
+
@mock_http_client.stub!(:address).and_return("www.baseurl.com")
|
53
|
+
@mock_http_client.stub!(:port).and_return("80")
|
54
|
+
|
55
|
+
@mock_http_robot_response.stub!(:code).and_return(200)
|
56
|
+
@mock_http_robot_response.stub!(:body).and_return(File.open(File.dirname(__FILE__) + '/../spec/samples/robots.txt', "r").read)
|
57
|
+
@mock_http_robot_response.stub!(:content_type).and_return("text/plain")
|
58
|
+
@mock_http_robot_response.stub!(:[]).with("Content-Type").and_return(@default_headers["Content-Type"])
|
59
|
+
@mock_http_robot_response.stub!(:[]).with("location").and_return(@default_headers["location"])
|
60
|
+
@mock_http_robot_response.stub!(:[]).with("Content-Encoding").and_return(@default_headers["Content-Encoding"])
|
61
|
+
@mock_http_robot_response.stub!(:content_length).and_return(1024)
|
62
|
+
@mock_http_robot_response.stub!(:get_fields).with('set-cookie').and_return(["session=al98axx; expires=Fri, 31-Dec-1999 23:58:23", "query=rubyscript; expires=Fri, 31-Dec-1999 23:58:23"])
|
63
|
+
@mock_http_robot_response.stub!(:to_hash).and_return(@default_headers)
|
64
|
+
|
65
|
+
@mock_http_response.stub!(:code).and_return(200)
|
66
|
+
@mock_http_response.stub!(:content_type).and_return("text/html")
|
67
|
+
@mock_http_response.stub!(:[]).with("Content-Type").and_return(@default_headers["Content-Type"])
|
68
|
+
@mock_http_response.stub!(:[]).with("location").and_return(@default_headers["location"])
|
69
|
+
@mock_http_response.stub!(:[]).with("Content-Encoding").and_return(@default_headers["Content-Encoding"])
|
70
|
+
@mock_http_response.stub!(:content_length).and_return(1024)
|
71
|
+
@mock_http_response.stub!(:body).and_return("asdf")
|
72
|
+
@mock_http_response.stub!(:get_fields).with('set-cookie').and_return(["session=al98axx; expires=Fri, 31-Dec-1999 23:58:23", "query=rubyscript; expires=Fri, 31-Dec-1999 23:58:23"])
|
73
|
+
@mock_http_response.stub!(:to_hash).and_return(@default_headers)
|
74
|
+
|
75
|
+
@mock_http_redirect_response.stub!(:code).and_return(301)
|
76
|
+
@mock_http_redirect_response.stub!(:content_type).and_return("text/html")
|
77
|
+
@mock_http_redirect_response.stub!(:[]).with("Content-Type").and_return(@default_headers["Content-Type"])
|
78
|
+
@mock_http_redirect_response.stub!(:[]).with("location").and_return("http://redirected-to.com/redirect2.html")
|
79
|
+
@mock_http_redirect_response.stub!(:[]).with("Content-Encoding").and_return(@default_headers["Content-Encoding"])
|
80
|
+
@mock_http_redirect_response.stub!(:content_length).and_return(2048)
|
81
|
+
@mock_http_redirect_response.stub!(:body).and_return("redirected body")
|
82
|
+
@mock_http_redirect_response.stub!(:get_fields).with('set-cookie').and_return(["session=al98axx; expires=Fri, 31-Dec-1999 23:58:23", "query=rubyscript; expires=Fri, 31-Dec-1999 23:58:23"])
|
83
|
+
@mock_http_redirect_response.stub!(:to_hash).and_return(@default_headers)
|
84
|
+
|
85
|
+
@mock_http_redirect_response2.stub!(:code).and_return(301)
|
86
|
+
@mock_http_redirect_response2.stub!(:content_type).and_return("text/html")
|
87
|
+
@mock_http_redirect_response2.stub!(:[]).with("Content-Type").and_return(@default_headers["Content-Type"])
|
88
|
+
@mock_http_redirect_response2.stub!(:[]).with("location").and_return("http://redirected-to.com/redirected.html")
|
89
|
+
@mock_http_redirect_response2.stub!(:[]).with("Content-Encoding").and_return(@default_headers["Content-Encoding"])
|
90
|
+
@mock_http_redirect_response2.stub!(:content_length).and_return(2048)
|
91
|
+
@mock_http_redirect_response2.stub!(:body).and_return("redirected body")
|
92
|
+
@mock_http_redirect_response2.stub!(:get_fields).with('set-cookie').and_return(["session=al98axx; expires=Fri, 31-Dec-1999 23:58:23", "query=rubyscript; expires=Fri, 31-Dec-1999 23:58:23"])
|
93
|
+
@mock_http_redirect_response2.stub!(:to_hash).and_return(@default_headers)
|
94
|
+
end
|
95
|
+
end
|
@@ -71,7 +71,7 @@
|
|
71
71
|
</ul>
|
72
72
|
</li>
|
73
73
|
<li><a href="typography.html">Typography</a></li>
|
74
|
-
<li class="current"><a href="boxgrid.html">Boxes Grid</a></li>
|
74
|
+
<li class="current"><a href="boxgrid>withsillyname.html">Boxes Grid</a></li>
|
75
75
|
<li><a href="forms.html">Forms</a></li>
|
76
76
|
<li><a href="gallery.html">Gallery</a></li>
|
77
77
|
<li><a href="tables.html">Tables</a></li>
|
@@ -71,7 +71,7 @@
|
|
71
71
|
</ul>
|
72
72
|
</li>
|
73
73
|
<li><a href="typography.html">Typography</a></li>
|
74
|
-
<li><a href="boxgrid.html">Boxes Grid</a></li>
|
74
|
+
<li><a href="boxgrid>withsillyname.html">Boxes Grid</a></li>
|
75
75
|
<li><a href="forms.html">Forms</a></li>
|
76
76
|
<li><a href="gallery.html">Gallery</a></li>
|
77
77
|
<li><a href="tables.html">Tables</a></li>
|
@@ -71,7 +71,7 @@
|
|
71
71
|
</ul>
|
72
72
|
</li>
|
73
73
|
<li><a href="typography.html">Typography</a></li>
|
74
|
-
<li><a href="boxgrid.html">Boxes Grid</a></li>
|
74
|
+
<li><a href="boxgrid>withsillyname.html">Boxes Grid</a></li>
|
75
75
|
<li class="current"><a href="forms.html">Forms</a></li>
|
76
76
|
<li><a href="gallery.html">Gallery</a></li>
|
77
77
|
<li><a href="tables.html">Tables</a></li>
|
@@ -71,7 +71,7 @@
|
|
71
71
|
</ul>
|
72
72
|
</li>
|
73
73
|
<li><a href="typography.html">Typography</a></li>
|
74
|
-
<li><a href="boxgrid.html">Boxes Grid</a></li>
|
74
|
+
<li><a href="boxgrid>withsillyname.html">Boxes Grid</a></li>
|
75
75
|
<li><a href="forms.html">Forms</a></li>
|
76
76
|
<li class="current"><a href="gallery.html">Gallery</a></li>
|
77
77
|
<li><a href="tables.html">Tables</a></li>
|
@@ -71,7 +71,7 @@
|
|
71
71
|
</ul>
|
72
72
|
</li>
|
73
73
|
<li><a href="typography.html">Typography</a></li>
|
74
|
-
<li><a href="boxgrid.html">Boxes Grid</a></li>
|
74
|
+
<li><a href="boxgrid>withsillyname.html">Boxes Grid</a></li>
|
75
75
|
<li><a href="forms.html">Forms</a></li>
|
76
76
|
<li><a href="gallery.html">Gallery</a></li>
|
77
77
|
<li><a href="tables.html">Tables</a></li>
|
@@ -71,7 +71,7 @@
|
|
71
71
|
</ul>
|
72
72
|
</li>
|
73
73
|
<li><a href="typography.html">Typography</a></li>
|
74
|
-
<li><a href="boxgrid.html">Boxes Grid</a></li>
|
74
|
+
<li><a href="boxgrid>withsillyname.html">Boxes Grid</a></li>
|
75
75
|
<li><a href="forms.html">Forms</a></li>
|
76
76
|
<li><a href="gallery.html">Gallery</a></li>
|
77
77
|
<li class="current"><a href="tables.html">Tables</a></li>
|
@@ -71,7 +71,7 @@
|
|
71
71
|
</ul>
|
72
72
|
</li>
|
73
73
|
<li class="current"><a href="typography.html">Typography</a></li>
|
74
|
-
<li><a href="boxgrid.html">Boxes Grid</a></li>
|
74
|
+
<li><a href="boxgrid>withsillyname.html">Boxes Grid</a></li>
|
75
75
|
<li><a href="forms.html">Forms</a></li>
|
76
76
|
<li><a href="gallery.html">Gallery</a></li>
|
77
77
|
<li><a href="tables.html">Tables</a></li>
|
data/spec/spec_helper.rb
CHANGED
@@ -1,7 +1,13 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../lib/sidekiq/cobweb_helper')
|
1
2
|
require File.expand_path(File.dirname(__FILE__) + '/../lib/cobweb')
|
2
3
|
require File.expand_path(File.dirname(__FILE__) + '/../spec/samples/sample_server')
|
4
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec/http_stubs')
|
3
5
|
require 'mock_redis'
|
4
6
|
require 'thin' if ENV["TRAVIS_RUBY_VERSION"].nil?
|
7
|
+
require 'sidekiq'
|
8
|
+
|
9
|
+
require 'coveralls'
|
10
|
+
Coveralls.wear!
|
5
11
|
|
6
12
|
# Sets up the environment as test so that exceptions are raised
|
7
13
|
ENVIRONMENT = "test"
|
@@ -32,94 +38,6 @@ RSpec.configure do |config|
|
|
32
38
|
|
33
39
|
#redis_mock.flushdb
|
34
40
|
|
35
|
-
@default_headers = {"Cache-Control" => "private, max-age=0",
|
36
|
-
"Date" => "Wed, 10 Nov 2010 09:06:17 GMT",
|
37
|
-
"Expires" => "-1",
|
38
|
-
"Content-Type" => "text/html; charset=UTF-8",
|
39
|
-
"Content-Encoding" => "",
|
40
|
-
"Transfer-Encoding" => "chunked",
|
41
|
-
"Server" => "gws",
|
42
|
-
"X-XSS-Protection" => "1; mode=block"}
|
43
|
-
|
44
|
-
@symbolized_default_headers = {:"Cache-Control" => "private, max-age=0",
|
45
|
-
:"Date" => "Wed, 10 Nov 2010 09:06:17 GMT",
|
46
|
-
:"Expires" => "-1",
|
47
|
-
:"Content-Type" => "text/html; charset=UTF-8",
|
48
|
-
:"Content-Encoding" => "",
|
49
|
-
:"Transfer-Encoding" => "chunked",
|
50
|
-
:"Server" => "gws",
|
51
|
-
:"X-XSS-Protection" => "1; mode=block"}
|
52
|
-
|
53
|
-
@mock_http_client = mock(Net::HTTP)
|
54
|
-
@mock_http_request = mock(Net::HTTPRequest)
|
55
|
-
@mock_http_robot_request = mock(Net::HTTPRequest)
|
56
|
-
@mock_http_redirect_request = mock(Net::HTTPRequest)
|
57
|
-
@mock_http_redirect_request2 = mock(Net::HTTPRequest)
|
58
|
-
|
59
|
-
@mock_http_response = mock(Net::HTTPResponse)
|
60
|
-
@mock_http_robot_response = mock(Net::HTTPResponse)
|
61
|
-
@mock_http_redirect_response = mock(Net::HTTPRedirection)
|
62
|
-
@mock_http_redirect_response2 = mock(Net::HTTPRedirection)
|
63
|
-
@mock_http_get = mock(Net::HTTP::Get)
|
64
|
-
|
65
|
-
Net::HTTP.stub!(:new).and_return(@mock_http_client)
|
66
|
-
Net::HTTP::Get.stub!(:new).and_return(@mock_http_request)
|
67
|
-
Net::HTTP::Get.stub!(:new).with("/redirect.html", an_instance_of(Hash)).and_return(@mock_http_redirect_request)
|
68
|
-
Net::HTTP::Get.stub!(:new).with("/robots.txt", an_instance_of(Hash)).and_return(@mock_http_robot_request)
|
69
|
-
Net::HTTP::Get.stub!(:new).with("/redirect2.html", an_instance_of(Hash)).and_return(@mock_http_redirect_request2)
|
70
|
-
Net::HTTP::Get.stub!(:new).with("/redirected.html", an_instance_of(Hash)).and_return(@mock_http_request)
|
71
|
-
|
72
|
-
Net::HTTP::Head.stub!(:new).and_return(@mock_http_request)
|
73
|
-
|
74
|
-
@mock_http_client.stub!(:request).with(@mock_http_request).and_return(@mock_http_response)
|
75
|
-
@mock_http_client.stub!(:request).with(@mock_http_robot_request).and_return(@mock_http_robot_response)
|
76
|
-
@mock_http_client.stub!(:request).with(@mock_http_redirect_request).and_return(@mock_http_redirect_response)
|
77
|
-
@mock_http_client.stub!(:request).with(@mock_http_redirect_request2).and_return(@mock_http_redirect_response2)
|
78
|
-
@mock_http_client.stub!(:read_timeout=).and_return(nil)
|
79
|
-
@mock_http_client.stub!(:open_timeout=).and_return(nil)
|
80
|
-
@mock_http_client.stub!(:start).and_return(@mock_http_response)
|
81
|
-
@mock_http_client.stub!(:address).and_return("www.baseurl.com")
|
82
|
-
@mock_http_client.stub!(:port).and_return("80")
|
83
|
-
|
84
|
-
@mock_http_robot_response.stub!(:code).and_return(200)
|
85
|
-
@mock_http_robot_response.stub!(:body).and_return(File.open(File.dirname(__FILE__) + '/../spec/samples/robots.txt', "r").read)
|
86
|
-
@mock_http_robot_response.stub!(:content_type).and_return("text/plain")
|
87
|
-
@mock_http_robot_response.stub!(:[]).with("Content-Type").and_return(@default_headers["Content-Type"])
|
88
|
-
@mock_http_robot_response.stub!(:[]).with("location").and_return(@default_headers["location"])
|
89
|
-
@mock_http_robot_response.stub!(:[]).with("Content-Encoding").and_return(@default_headers["Content-Encoding"])
|
90
|
-
@mock_http_robot_response.stub!(:content_length).and_return(1024)
|
91
|
-
@mock_http_robot_response.stub!(:get_fields).with('set-cookie').and_return(["session=al98axx; expires=Fri, 31-Dec-1999 23:58:23", "query=rubyscript; expires=Fri, 31-Dec-1999 23:58:23"])
|
92
|
-
@mock_http_robot_response.stub!(:to_hash).and_return(@default_headers)
|
93
|
-
|
94
|
-
@mock_http_response.stub!(:code).and_return(200)
|
95
|
-
@mock_http_response.stub!(:content_type).and_return("text/html")
|
96
|
-
@mock_http_response.stub!(:[]).with("Content-Type").and_return(@default_headers["Content-Type"])
|
97
|
-
@mock_http_response.stub!(:[]).with("location").and_return(@default_headers["location"])
|
98
|
-
@mock_http_response.stub!(:[]).with("Content-Encoding").and_return(@default_headers["Content-Encoding"])
|
99
|
-
@mock_http_response.stub!(:content_length).and_return(1024)
|
100
|
-
@mock_http_response.stub!(:body).and_return("asdf")
|
101
|
-
@mock_http_response.stub!(:get_fields).with('set-cookie').and_return(["session=al98axx; expires=Fri, 31-Dec-1999 23:58:23", "query=rubyscript; expires=Fri, 31-Dec-1999 23:58:23"])
|
102
|
-
@mock_http_response.stub!(:to_hash).and_return(@default_headers)
|
103
|
-
|
104
|
-
@mock_http_redirect_response.stub!(:code).and_return(301)
|
105
|
-
@mock_http_redirect_response.stub!(:content_type).and_return("text/html")
|
106
|
-
@mock_http_redirect_response.stub!(:[]).with("Content-Type").and_return(@default_headers["Content-Type"])
|
107
|
-
@mock_http_redirect_response.stub!(:[]).with("location").and_return("http://redirected-to.com/redirect2.html")
|
108
|
-
@mock_http_redirect_response.stub!(:[]).with("Content-Encoding").and_return(@default_headers["Content-Encoding"])
|
109
|
-
@mock_http_redirect_response.stub!(:content_length).and_return(2048)
|
110
|
-
@mock_http_redirect_response.stub!(:body).and_return("redirected body")
|
111
|
-
@mock_http_redirect_response.stub!(:get_fields).with('set-cookie').and_return(["session=al98axx; expires=Fri, 31-Dec-1999 23:58:23", "query=rubyscript; expires=Fri, 31-Dec-1999 23:58:23"])
|
112
|
-
@mock_http_redirect_response.stub!(:to_hash).and_return(@default_headers)
|
113
|
-
|
114
|
-
@mock_http_redirect_response2.stub!(:code).and_return(301)
|
115
|
-
@mock_http_redirect_response2.stub!(:content_type).and_return("text/html")
|
116
|
-
@mock_http_redirect_response2.stub!(:[]).with("Content-Type").and_return(@default_headers["Content-Type"])
|
117
|
-
@mock_http_redirect_response2.stub!(:[]).with("location").and_return("http://redirected-to.com/redirected.html")
|
118
|
-
@mock_http_redirect_response2.stub!(:[]).with("Content-Encoding").and_return(@default_headers["Content-Encoding"])
|
119
|
-
@mock_http_redirect_response2.stub!(:content_length).and_return(2048)
|
120
|
-
@mock_http_redirect_response2.stub!(:body).and_return("redirected body")
|
121
|
-
@mock_http_redirect_response2.stub!(:get_fields).with('set-cookie').and_return(["session=al98axx; expires=Fri, 31-Dec-1999 23:58:23", "query=rubyscript; expires=Fri, 31-Dec-1999 23:58:23"])
|
122
|
-
@mock_http_redirect_response2.stub!(:to_hash).and_return(@default_headers)
|
123
41
|
}
|
124
42
|
|
125
43
|
end
|