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



186
187
188
189
190
# File 'test/env_test.rb', line 186

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



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

def test_body
  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



202
203
204
205
206
207
208
209
# File 'test/env_test.rb', line 202

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



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

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

#test_marshalObject



192
193
194
195
196
197
198
199
200
# File 'test/env_test.rb', line 192

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



169
170
171
# File 'test/env_test.rb', line 169

def test_not_success
  assert !@response.success?
end

#test_statusObject



173
174
175
# File 'test/env_test.rb', line 173

def test_status
  assert_equal 404, @response.status
end