/
url_status_spec.rb
43 lines (37 loc) · 1.18 KB
/
url_status_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
require 'spec_helper'
module Fetcher
describe UrlStatus do
ANY_VALID_URL = "http://www.bing.com"
let( :urlstatus ) { UrlStatus.new ANY_VALID_URL }
[
[HTTP_OK, true],
[HTTP_CREATED, true],
[HTTP_ACCEPTED, true],
[HTTP_NON_AUTHORITATIVE, true],
[HTTP_NO_CONTENT, true],
[HTTP_RESET_CONTENT, true],
[HTTP_BAD_REQUEST, false],
[HTTP_FORBIDDEN, false],
[HTTP_INTERNAL_SERVER_ERROR, false],
].each do |status, expected_result|
it "return { available: true } on #{status}" do
stub_request(:get, ANY_VALID_URL).to_return(status: status)
urlstatus.fetch.should == { available: expected_result }
urlstatus.data.should == { available: expected_result }
end
end
[
HTTParty::RedirectionTooDeep,
HTTParty::ResponseError,
SocketError,
Timeout::Error
].each do |exception|
it "return { available: false } on exception #{exception}" do
stub_request(:get, ANY_VALID_URL).to_raise(exception)
urlstatus.fetch.should == { available: false }
urlstatus.data.should == { available: false }
end
end
it "times out after 30 seconds"
end
end