Sha256: 6e6c2f95de60a43c79fa6cc71e15640a47b8203b25093bb347c259437d100a2a
Contents?: true
Size: 1.98 KB
Versions: 1
Compression:
Stored size: 1.98 KB
Contents
require 'test_helper' class WebService::ResponseHandlingTest < Test::Unit::TestCase M = WebService::ResponseHandling def test_connection_error_message error_type = M::ConnectionError # Can't use stub since stub(:method => :result) doesn't respond_to?(:method) response = Object.new def response.code; 400 end # Nil response / No custom message err = error_type.new(nil) assert_equal "Failed", err.to_s # Nil response + Custom message err = error_type.new(nil, "message") assert_equal "Failed: message", err.to_s # No response message / No custom message err = error_type.new(response) assert_equal "Failed with 400", err.to_s # Nil response message / No custom message def response.message; nil end err = error_type.new(response) assert_equal "Failed with 400", err.to_s # Blank response message / No custom message def response.message; "" end err = error_type.new(response) assert_equal "Failed with 400", err.to_s # Response message / No custom message def response.message; "Bad Request" end err = error_type.new(response) assert_equal "Failed with 400 (Bad Request)", err.to_s # Response message + Custom message err = error_type.new(response, "message") assert_equal "Failed with 400 (Bad Request): message", err.to_s end # protected def test_handle_response handler = Object.new.extend M assert_raise_with_code = lambda do |code, exc| response = stub(:code => code) assert_raise(exc) do handler.instance_eval { handle_response(response) } end end assert_raise_with_code[406, M::NotAcceptable] assert_raise_with_code[502, M::BadGateway] assert_raise_with_code[503, M::ServiceUnavailable] assert_raise_with_code[504, M::GatewayTimeout] response = stub(:code => 200) result = handler.instance_eval { handle_response(response) } assert_equal response, response end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
Roman2K-web-service-0.1.1 | test/web_service/response_handling_test.rb |