Class: ResponseTest
Instance Method Summary
collapse
#capture_warnings, jruby?, rbx?, ssl_mode?, #test_default
#live_server, #live_server=, #live_server?
Instance Method Details
152
153
154
155
156
157
|
# File 'test/env_test.rb', line 152
def setup
@env = Faraday::Env.from \
:status => 404, :body => 'yikes',
:response_headers => {'Content-Type' => 'text/plain'}
@response = Faraday::Response.new @env
end
|
#test_apply_request ⇒ Object
194
195
196
197
198
|
# File 'test/env_test.rb', line 194
def test_apply_request
@response.apply_request :body => 'a=b', :method => :post
assert_equal 'yikes', @response.body
assert_equal :post, @response.env[:method]
end
|
#test_body ⇒ Object
185
186
187
|
# File 'test/env_test.rb', line 185
def test_body
assert_equal 'yikes', @response.body
end
|
#test_body_is_parsed_on_finish ⇒ Object
169
170
171
172
173
174
175
|
# File 'test/env_test.rb', line 169
def test_body_is_parsed_on_finish
response = Faraday::Response.new
response.on_complete { |env| env[:body] = env[:body].upcase }
response.finish(@env)
assert_equal "YIKES", response.body
end
|
#test_error_on_finish ⇒ Object
163
164
165
166
167
|
# File 'test/env_test.rb', line 163
def test_error_on_finish
assert_raises RuntimeError do
@response.finish({})
end
end
|
#test_finished ⇒ Object
159
160
161
|
# File 'test/env_test.rb', line 159
def test_finished
assert @response.finished?
end
|
#test_hash ⇒ Object
210
211
212
213
214
215
216
217
|
# File 'test/env_test.rb', line 210
def test_hash
hash = @response.to_hash
assert_kind_of Hash, hash
assert_equal @env.to_hash, hash
assert_equal hash[:status], @response.status
assert_equal hash[:response_headers], @response.
assert_equal hash[:body], @response.body
end
|
189
190
191
192
|
# File 'test/env_test.rb', line 189
def
assert_equal 'text/plain', @response.['Content-Type']
assert_equal 'text/plain', @response['content-type']
end
|
#test_marshal ⇒ Object
200
201
202
203
204
205
206
207
208
|
# File 'test/env_test.rb', line 200
def test_marshal
@response = Faraday::Response.new
@response.on_complete { }
@response.finish @env.merge(:params => 'moo')
loaded = Marshal.load Marshal.dump(@response)
assert_nil loaded.env[:params]
assert_equal %w[body response_headers status], loaded.env.keys.map { |k| k.to_s }.sort
end
|
#test_not_success ⇒ Object
177
178
179
|
# File 'test/env_test.rb', line 177
def test_not_success
assert !@response.success?
end
|
#test_status ⇒ Object
181
182
183
|
# File 'test/env_test.rb', line 181
def test_status
assert_equal 404, @response.status
end
|