From 8a1ecc5f10402885916769706eb710f8882e3331 Mon Sep 17 00:00:00 2001 From: Ethan Burrow Date: Thu, 30 Aug 2012 12:53:42 -0500 Subject: [PATCH] adding convenience ok? instance method to HTTP::Message --- lib/httpclient/http.rb | 5 +++++ test/test_httpclient.rb | 11 +++++++++++ 2 files changed, 16 insertions(+) diff --git a/lib/httpclient/http.rb b/lib/httpclient/http.rb index 290ea57e..29455405 100644 --- a/lib/httpclient/http.rb +++ b/lib/httpclient/http.rb @@ -1027,6 +1027,11 @@ def cookies } end end + + # Convenience method to return boolean of whether we had a successful request + def ok? + HTTP::Status.successful?(status) + end end diff --git a/test/test_httpclient.rb b/test/test_httpclient.rb index 0e96257b..d4a76fa8 100644 --- a/test/test_httpclient.rb +++ b/test/test_httpclient.rb @@ -1313,6 +1313,17 @@ def test_response_cookies assert_equal('PART_NUMBER', res.cookies[1].name) end + def test_ok_response_success + res = HTTP::Message.new_response('response') + assert_true res.ok? + res.status = 404 + assert_false res.ok? + res.status = 500 + assert_false res.ok? + res.status = 302 + assert_false res.ok? + end + if !defined?(JRUBY_VERSION) and RUBY_VERSION < '1.9' def test_timeout_scheduler assert_equal('hello', @client.get_content(serverurl + 'hello'))