summaryrefslogtreecommitdiff
path: root/tests/helpers/http_helper.rb
diff options
context:
space:
mode:
authorelijah <elijah@riseup.net>2016-04-08 10:41:54 -0700
committerelijah <elijah@riseup.net>2016-04-08 10:41:54 -0700
commit82b15a8a071ba099cf52bb00c66caebdbd265273 (patch)
tree3f27b0673839be7d10ed5b401216ab79e43ce751 /tests/helpers/http_helper.rb
parent44666c42ce836fb611dfd9c1b549e955c470814c (diff)
parenteac3056c237d523f4786593922fe8f88eb65dff7 (diff)
Merge branch 'feature/mxtest' into develop
Diffstat (limited to 'tests/helpers/http_helper.rb')
-rw-r--r--tests/helpers/http_helper.rb27
1 files changed, 19 insertions, 8 deletions
diff --git a/tests/helpers/http_helper.rb b/tests/helpers/http_helper.rb
index 2fcdc910..0d0bb7d5 100644
--- a/tests/helpers/http_helper.rb
+++ b/tests/helpers/http_helper.rb
@@ -81,20 +81,31 @@ class LeapTest
#
# calls http_send, yielding results if successful or failing with
- # descriptive infor otherwise.
+ # descriptive info otherwise.
+ #
+ # options:
+ # - error_msg: custom error message to display.
+ # - ok_codes: in addition to 2xx, codes in this array will not produce an error.
#
def assert_http_send(method, url, params=nil, options=nil, &block)
options ||= {}
error_msg = options[:error_msg] || (url.respond_to?(:memo) ? url.memo : nil)
http_send(method, url, params, options) do |body, response, error|
- ok = response && response.code.to_i >= 200 && response.code.to_i < 300
- if body && ok
- if block
- yield(body) if block.arity == 1
- yield(response, body) if block.arity == 2
+ if response
+ code = response.code.to_i
+ ok = code >= 200 && code < 300
+ if options[:ok_codes]
+ ok ||= options[:ok_codes].include?(code)
+ end
+ if ok
+ if block
+ yield(body) if block.arity == 1
+ yield(body, response) if block.arity == 2
+ yield(body, response, error) if block.arity == 3
+ end
+ else
+ fail ["Expected success code from #{method} #{url}, but got #{response.code} instead.", error_msg, body].compact.join("\n")
end
- elsif response && !ok
- fail ["Expected a 200 status code from #{method} #{url}, but got #{response.code} instead.", error_msg, body].compact.join("\n")
else
fail ["Expected a response from #{method} #{url}, but got \"#{error}\" instead.", error_msg, body].compact.join("\n"), error
end