spec/redfinger/client_spec.rb in redfinger-0.0.6 vs spec/redfinger/client_spec.rb in redfinger-0.1.0

- old
+ new

@@ -23,9 +23,27 @@ it 'should make an HTTP request if HTTPS cannot connect' do stub_request(:get, 'https://example.com/.well-known/host-meta').to_raise(Errno::ECONNREFUSED) stub_request(:get, 'http://example.com/.well-known/host-meta').to_raise(HaltSuccessError) lambda{Redfinger::Client.new('acct:abc@example.com').send(:retrieve_template_from_xrd)}.should raise_error(HaltSuccessError) end + + it 'should make an HTTP request if the HTTPS request times out in Net::HTTP' do + stub_request(:get, 'https://example.com/.well-known/host-meta').to_raise(Errno::ETIMEDOUT) + stub_request(:get, 'http://example.com/.well-known/host-meta').to_raise(HaltSuccessError) + lambda{Redfinger::Client.new('acct:abc@example.com').send(:retrieve_template_from_xrd)}.should raise_error(HaltSuccessError) + end + + it 'should make an HTTP request if the HTTPS request times out in RestClient' do + stub_request(:get, 'https://example.com/.well-known/host-meta').to_raise(RestClient::RequestTimeout) + stub_request(:get, 'http://example.com/.well-known/host-meta').to_raise(HaltSuccessError) + lambda{Redfinger::Client.new('acct:abc@example.com').send(:retrieve_template_from_xrd)}.should raise_error(HaltSuccessError) + end + + it 'should make an HTTP request if the server throws a 403 forbidden on the HTTPS request' do + stub_request(:get, 'https://example.com/.well-known/host-meta').to_return(:status => [403, "Forbidden"]) + stub_request(:get, 'http://example.com/.well-known/host-meta').to_raise(HaltSuccessError) + lambda{Redfinger::Client.new('acct:abc@example.com').send(:retrieve_template_from_xrd)}.should raise_error(HaltSuccessError) + end it 'should raise Redfinger::ResourceNotFound if HTTP fails as well' do stub_request(:get, 'https://example.com/.well-known/host-meta').to_raise(Errno::ECONNREFUSED) stub_request(:get, 'http://example.com/.well-known/host-meta').to_raise(Errno::ECONNREFUSED) lambda{Redfinger::Client.new('acct:abc@example.com').send(:retrieve_template_from_xrd)}.should raise_error(Redfinger::ResourceNotFound) \ No newline at end of file