Class: HeadersTest
Instance Method Summary
collapse
#capture_warnings, jruby?, rbx?, ssl_mode?, #test_default
#live_server, #live_server=, #live_server?
Instance Method Details
#test_delete_key ⇒ Object
120
121
122
123
124
125
126
127
128
|
# File 'test/env_test.rb', line 120
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')
assert_equal 0, @headers.size
assert !@headers.include?('content-type')
assert_equal nil, @headers.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
@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
|
#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
@headers['Content-Type'] = 'application/json'
assert_equal ['Content-Type'], @headers.keys
assert_equal 'application/json', @headers['Content-Type']
assert_equal 'application/json', @headers['CONTENT-TYPE']
assert_equal 'application/json', @headers['content-type']
assert @headers.include?('content-type')
@headers['content-type'] = 'application/xml'
assert_equal ['Content-Type'], @headers.keys
assert_equal 'application/xml', @headers['Content-Type']
assert_equal 'application/xml', @headers['CONTENT-TYPE']
assert_equal 'application/xml', @headers['content-type']
end
|
130
131
132
133
|
# File 'test/env_test.rb', line 130
def
@headers.parse("HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n")
assert_equal %w(Content-Type), @headers.keys
end
|
145
146
147
148
|
# File 'test/env_test.rb', line 145
def
@headers.parse("HTTP/1.1 200 OK\r\n\r\nContent-Type: text/html\r\n\r\n")
assert_equal 'text/html', @headers['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
@headers.parse("HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n")
assert_equal 'text/html', @headers['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
@headers.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/', @headers['location']
end
|