Permalink
Browse files

report some error cases when reading cctray.xml

  • Loading branch information...
1 parent 788f590 commit b0300924cd3c66da0de654f1ad0aa086c98a61b7 @perryn committed Jan 2, 2013
@@ -0,0 +1,52 @@
+---
+http_interactions:
+- request:
+ method: get
+ uri: https://api.travis-ci.org/repositories/markryall/chicanery/cc.xml
+ body:
+ encoding: US-ASCII
+ string: ''
+ headers:
+ accept:
+ - ! '*/*'
+ user-agent:
+ - Ruby
+ response:
+ status:
+ code: 200
+ message: OK
+ headers:
+ access-control-allow-credentials:
+ - 'true'
+ access-control-allow-origin:
+ - ! '*'
+ access-control-expose-headers:
+ - Content-Type, Cache-Control, Expires, Etag, Last-Modified
+ cache-control:
+ - no-cache
+ content-type:
+ - application/json;charset=utf-8
+ date:
+ - Sat, 15 Dec 2012 02:39:04 GMT
+ etag:
+ - ! '"aa451983b94cbec99aa94346f358b5b0"'
+ status:
+ - 200 OK
+ strict-transport-security:
+ - max-age=31536000
+ vary:
+ - Accept,Accept-Encoding
+ x-accepted-oauth-scopes:
+ - public
+ x-oauth-scopes:
+ - public
+ content-length:
+ - '217'
+ connection:
+ - keep-alive
+ body:
+ encoding: US-ASCII
+ string: ! "Nothing here but us chickens"
+ http_version: '1.1'
+ recorded_at: Sat, 15 Dec 2012 02:39:09 GMT
+recorded_with: VCR 2.3.0
@@ -0,0 +1,52 @@
+---
+http_interactions:
+- request:
+ method: get
+ uri: https://api.travis-ci.org/repositories/markryall/chicanery/cc.xml
+ body:
+ encoding: US-ASCII
+ string: ''
+ headers:
+ accept:
+ - ! '*/*'
+ user-agent:
+ - Ruby
+ response:
+ status:
+ code: 301
+ message: Redirect
+ headers:
+ access-control-allow-credentials:
+ - 'true'
+ access-control-allow-origin:
+ - ! '*'
+ access-control-expose-headers:
+ - Content-Type, Cache-Control, Expires, Etag, Last-Modified
+ cache-control:
+ - no-cache
+ content-type:
+ - application/json;charset=utf-8
+ date:
+ - Sat, 15 Dec 2012 02:39:04 GMT
+ etag:
+ - ! '"aa451983b94cbec99aa94346f358b5b0"'
+ status:
+ - 200 OK
+ strict-transport-security:
+ - max-age=31536000
+ vary:
+ - Accept,Accept-Encoding
+ x-accepted-oauth-scopes:
+ - public
+ x-oauth-scopes:
+ - public
+ content-length:
+ - '217'
+ connection:
+ - keep-alive
+ body:
+ encoding: US-ASCII
+ string: ! "hhh"
+ http_version: '1.1'
+ recorded_at: Sat, 15 Dec 2012 02:39:09 GMT
+recorded_with: VCR 2.3.0
@@ -25,12 +25,14 @@ def get
res = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https', verify_mode: OpenSSL::SSL::VERIFY_NONE) do |https|
https.request(req)
end
+ res.value #check for success via a spectactulalry poorly named method
res.body
end
def jobs
jobs = {}
- Nokogiri::XML(get).css("Project").each do |project|
+ response_body = get
+ Nokogiri::XML(response_body).css("Project").each do |project|
job = {
activity: project[:activity] == 'Sleeping' ? :sleeping : :building,
last_build_status: parse_build_status(project[:lastBuildStatus]),
@@ -40,6 +42,7 @@ def jobs
}
jobs[project[:name]] = job unless filtered project[:name]
end
+ raise "could not find any jobs in response: [#{response_body}]" if jobs.empty?
jobs
end
@@ -52,4 +52,17 @@
}
end
end
+
+ it 'should complain if there are no jobs in response' do
+ VCR.use_cassette('no_projects') do
+ expect{server.jobs}.to raise_error "could not find any jobs in response: [Nothing here but us chickens]"
+ end
+ end
+
+ it 'should complain if it gets a non 2xx response' do
+ VCR.use_cassette('redirect') do
+ expect{server.jobs}.to raise_error Net::HTTPRetriableError
+ end
+ end
+
end

0 comments on commit b030092

Please sign in to comment.