Class: ResponseTest

Inherits:
Faraday::TestCase show all
Defined in:
test/env_test.rb

Instance Method Summary collapse

Methods inherited from Faraday::TestCase

#capture_warnings, jruby?, rbx?, ssl_mode?, #test_default

Methods included from Faraday::LiveServerConfig

#live_server, #live_server=, #live_server?

Instance Method Details

#setupObject



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_requestObject



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_bodyObject



185
186
187
# File 'test/env_test.rb', line 185

def test_body
  assert_equal 'yikes', @response.body
end

#test_body_is_parsed_on_finishObject



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_finishObject



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_finishedObject



159
160
161
# File 'test/env_test.rb', line 159

def test_finished
  assert @response.finished?
end

#test_hashObject



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.headers
  assert_equal hash[:body], @response.body
end

#test_headersObject



189
190
191
192
# File 'test/env_test.rb', line 189

def test_headers
  assert_equal 'text/plain', @response.headers['Content-Type']
  assert_equal 'text/plain', @response['content-type']
end

#test_marshalObject



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_successObject



177
178
179
# File 'test/env_test.rb', line 177

def test_not_success
  assert !@response.success?
end

#test_statusObject



181
182
183
# File 'test/env_test.rb', line 181

def test_status
  assert_equal 404, @response.status
end