test/env_test.rb in faraday-0.9.0.rc5 vs test/env_test.rb in faraday-0.9.0.rc6
- old
+ new
@@ -96,10 +96,29 @@
assert_equal 'application/xml', @headers['Content-Type']
assert_equal 'application/xml', @headers['CONTENT-TYPE']
assert_equal 'application/xml', @headers['content-type']
end
+ def test_fetch_key
+ @headers['Content-Type'] = 'application/json'
+ block_called = false
+ assert_equal 'application/json', @headers.fetch('content-type') { block_called = true }
+ assert_equal 'application/json', @headers.fetch('Content-Type')
+ assert_equal 'application/json', @headers.fetch('CONTENT-TYPE')
+ assert_equal 'application/json', @headers.fetch(:content_type)
+ assert_equal false, block_called
+
+ assert_equal 'default', @headers.fetch('invalid', 'default')
+ assert_equal false, @headers.fetch('invalid', false)
+ assert_nil @headers.fetch('invalid', nil)
+
+ assert_equal 'Invalid key', @headers.fetch('Invalid') { |key| "#{key} key" }
+
+ expected_error = defined?(KeyError) ? KeyError : IndexError
+ assert_raises(expected_error) { @headers.fetch('invalid') }
+ end
+
def test_delete_key
@headers['Content-Type'] = 'application/json'
assert_equal 1, @headers.size
assert @headers.include?('content-type')
assert_equal 'application/json', @headers.delete('content-type')
@@ -187,6 +206,5 @@
assert_equal hash[:status], @response.status
assert_equal hash[:response_headers], @response.headers
assert_equal hash[:body], @response.body
end
end
-