Class: ResponseMiddlewareTest

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

Defined Under Namespace

Classes: ResponseUpcaser

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


4
5
6
7
8
9
10
11
12
13
# File 'test/response_middleware_test.rb', line 4

def setup
  @conn = Faraday.new do |b|
    b.response :raise_error
    b.adapter :test do |stub|
      stub.get('ok')        { [200, {'Content-Type' => 'text/html'}, '<body></body>'] }
      stub.get('not-found') { [404, {'X-Reason' => 'because'}, 'keep looking'] }
      stub.get('error')     { [500, {'X-Error' => 'bailout'}, 'fail'] }
    end
  end
end

#test_raises_errorObject


33
34
35
36
37
38
39
# File 'test/response_middleware_test.rb', line 33

def test_raises_error
  error = assert_raises Faraday::Error::ClientError do
    @conn.get('error')
  end
  assert_equal 'the server responded with status 500', error.message
  assert_equal 'bailout', error.response[:headers]['X-Error']
end

#test_raises_not_foundObject


25
26
27
28
29
30
31
# File 'test/response_middleware_test.rb', line 25

def test_raises_not_found
  error = assert_raises Faraday::Error::ResourceNotFound do
    @conn.get('not-found')
  end
  assert_equal 'the server responded with status 404', error.message
  assert_equal 'because', error.response[:headers]['X-Reason']
end

#test_successObject


21
22
23
# File 'test/response_middleware_test.rb', line 21

def test_success
  assert @conn.get('ok')
end

#test_upcaseObject


41
42
43
44
# File 'test/response_middleware_test.rb', line 41

def test_upcase
  @conn.builder.insert(0, ResponseUpcaser)
  assert_equal '<BODY></BODY>', @conn.get('ok').body
end