Class: HeadersTest
Instance Method Summary
collapse
#capture_warnings, jruby?, rbx?, ssl_mode?, #test_default
#live_server, #live_server=, #live_server?
Instance Method Details
82
83
84
|
# File 'test/env_test.rb', line 82
def setup
= Faraday::Utils::.new
end
|
#test_delete_key ⇒ Object
120
121
122
123
124
125
126
127
128
|
# File 'test/env_test.rb', line 120
def test_delete_key
['Content-Type'] = 'application/json'
assert_equal 1, .size
assert .include?('content-type')
assert_equal 'application/json', .delete('content-type')
assert_equal 0, .size
assert !.include?('content-type')
assert_equal nil, .delete('content-type')
end
|
#test_fetch_key ⇒ Object
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
# File 'test/env_test.rb', line 101
def test_fetch_key
['Content-Type'] = 'application/json'
block_called = false
assert_equal 'application/json', .fetch('content-type') { block_called = true }
assert_equal 'application/json', .fetch('Content-Type')
assert_equal 'application/json', .fetch('CONTENT-TYPE')
assert_equal 'application/json', .fetch(:content_type)
assert_equal false, block_called
assert_equal 'default', .fetch('invalid', 'default')
assert_equal false, .fetch('invalid', false)
assert_nil .fetch('invalid', nil)
assert_equal 'Invalid key', .fetch('Invalid') { |key| "#{key} key" }
expected_error = defined?(KeyError) ? KeyError : IndexError
assert_raises(expected_error) { .fetch('invalid') }
end
|
#test_normalizes_different_capitalizations ⇒ Object
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
# File 'test/env_test.rb', line 86
def test_normalizes_different_capitalizations
['Content-Type'] = 'application/json'
assert_equal ['Content-Type'], .keys
assert_equal 'application/json', ['Content-Type']
assert_equal 'application/json', ['CONTENT-TYPE']
assert_equal 'application/json', ['content-type']
assert .include?('content-type')
['content-type'] = 'application/xml'
assert_equal ['Content-Type'], .keys
assert_equal 'application/xml', ['Content-Type']
assert_equal 'application/xml', ['CONTENT-TYPE']
assert_equal 'application/xml', ['content-type']
end
|
130
131
132
133
|
# File 'test/env_test.rb', line 130
def
.parse("HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n")
assert_equal %w(Content-Type), .keys
end
|
145
146
147
148
|
# File 'test/env_test.rb', line 145
def
.parse("HTTP/1.1 200 OK\r\n\r\nContent-Type: text/html\r\n\r\n")
assert_equal 'text/html', ['content-type']
end
|
#test_parse_response_headers_parses_lower_cased_header_name_and_value ⇒ Object
135
136
137
138
|
# File 'test/env_test.rb', line 135
def test_parse_response_headers_parses_lower_cased_header_name_and_value
.parse("HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n")
assert_equal 'text/html', ['content-type']
end
|
#test_parse_response_headers_parses_lower_cased_header_name_and_value_with_colon ⇒ Object
140
141
142
143
|
# File 'test/env_test.rb', line 140
def test_parse_response_headers_parses_lower_cased_header_name_and_value_with_colon
.parse("HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nLocation: http://sushi.com/\r\n\r\n")
assert_equal 'http://sushi.com/', ['location']
end
|