Class: Adapters::LoggerTest
- Inherits:
-
Faraday::TestCase
- Object
- MiniTest::Test
- Faraday::TestCase
- Adapters::LoggerTest
- Defined in:
- test/adapters/logger_test.rb
Instance Method Summary collapse
- #conn(logger, logger_options = {}) ⇒ Object
- #setup ⇒ Object
- #test_does_not_log_request_body_by_default ⇒ Object
- #test_does_not_log_response_body_by_default ⇒ Object
- #test_log_request_and_response_body ⇒ Object
- #test_log_request_body ⇒ Object
- #test_log_response_body ⇒ Object
- #test_log_response_body_object ⇒ Object
- #test_logs_method_and_url ⇒ Object
- #test_logs_request_headers ⇒ Object
- #test_logs_response_headers ⇒ Object
- #test_still_returns_output ⇒ Object
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
#conn(logger, logger_options = {}) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'test/adapters/logger_test.rb', line 7 def conn(logger, ={}) rubbles = ['Barney', 'Betty', 'Bam Bam'] Faraday.new do |b| b.response :logger, logger, b.adapter :test do |stubs| stubs.get('/hello') { [200, {'Content-Type' => 'text/html'}, 'hello'] } stubs.post('/ohai') { [200, {'Content-Type' => 'text/html'}, 'fred'] } stubs.get('/ohno') { [200, {'Content-Type' => 'text/html'}, 'wilma'] } stubs.post('/ohyes') { [200, {'Content-Type' => 'text/html'}, 'pebbles'] } stubs.get('/rubbles') { [200, {'Content-Type' => 'application/json'}, rubbles] } end end end |
#setup ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'test/adapters/logger_test.rb', line 22 def setup @io = StringIO.new @logger = Logger.new(@io) @logger.level = Logger::DEBUG @conn = conn(@logger) @resp = @conn.get '/hello', nil, :accept => 'text/html' end |
#test_does_not_log_request_body_by_default ⇒ Object
47 48 49 50 |
# File 'test/adapters/logger_test.rb', line 47 def test_does_not_log_request_body_by_default @conn.post '/ohai', 'name=Unagi', :accept => 'text/html' refute_match %(name=Unagi), @io.string end |
#test_does_not_log_response_body_by_default ⇒ Object
52 53 54 55 |
# File 'test/adapters/logger_test.rb', line 52 def test_does_not_log_response_body_by_default @conn.post '/ohai', 'name=Toro', :accept => 'text/html' refute_match %(fred), @io.string end |
#test_log_request_and_response_body ⇒ Object
69 70 71 72 73 74 |
# File 'test/adapters/logger_test.rb', line 69 def test_log_request_and_response_body app = conn(@logger, :bodies => true) app.post '/ohyes', 'name=Ebi', :accept => 'text/html' assert_match %(name=Ebi), @io.string assert_match %(pebbles), @io.string end |
#test_log_request_body ⇒ Object
57 58 59 60 61 |
# File 'test/adapters/logger_test.rb', line 57 def test_log_request_body app = conn(@logger, :bodies => { :request => true }) app.post '/ohyes', 'name=Tamago', :accept => 'text/html' assert_match %(name=Tamago), @io.string end |
#test_log_response_body ⇒ Object
63 64 65 66 67 |
# File 'test/adapters/logger_test.rb', line 63 def test_log_response_body app = conn(@logger, :bodies => { :response => true }) app.get '/ohno', :accept => 'text/html' assert_match %(wilma), @io.string end |
#test_log_response_body_object ⇒ Object
76 77 78 79 80 |
# File 'test/adapters/logger_test.rb', line 76 def test_log_response_body_object app = conn(@logger, :bodies => true) app.get '/rubbles', nil, :accept => 'text/html' assert_match %([\"Barney\", \"Betty\", \"Bam Bam\"]\n), @io.string end |
#test_logs_method_and_url ⇒ Object
35 36 37 |
# File 'test/adapters/logger_test.rb', line 35 def test_logs_method_and_url assert_match "get http:/hello", @io.string end |
#test_logs_request_headers ⇒ Object
39 40 41 |
# File 'test/adapters/logger_test.rb', line 39 def test_logs_request_headers assert_match %(Accept: "text/html), @io.string end |
#test_logs_response_headers ⇒ Object
43 44 45 |
# File 'test/adapters/logger_test.rb', line 43 def test_logs_response_headers assert_match %(Content-Type: "text/html), @io.string end |
#test_still_returns_output ⇒ Object
31 32 33 |
# File 'test/adapters/logger_test.rb', line 31 def test_still_returns_output assert_equal 'hello', @resp.body end |