Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How disable http logs from Rspec output?

I'm writing tests for my rails application. I want to see only '.' and '*' symbols, when rspec running. But I'm watching HTTP logs and don't know how disable them. Piece of rspec output from my terminal:



.............get http://0.0.0.0:3000/device_info/?api_session=%23%7Bapi_session%7D
User-Agent: "Faraday v0.8.7"
404
content-type: "text/html"
x-cascade: "pass"
connection: "close"
server: "thin 1.5.1 codename Straight Razor"
.....get http://0.0.0.0:3000/device_info/12345?api_session=%23%7Bapi_session%7D
User-Agent: "Faraday v0.8.7"
400
..

I assume that the reason may be configuration of 'faraday' gem. How can I disable this logs from my rspec output?

like image 701
bmalets Avatar asked Jul 25 '13 12:07

bmalets


2 Answers

faraday does not log anything per default:

irb(main):001:0> require "faraday"
=> true
irb(main):002:0> Faraday.get 'http://sushi.com/nigiri/sake.json'
=> #<Faraday::Response:0x007ff48f0422a8 @env={:method=>:get, :body=>"", :url=>#<URI::HTTP:0x007ff48f03bd40 URL:http://sushi.com/nigiri/sake.json>, :request_headers=>{"User-Agent"=>"Faraday v0.8.7"}, :parallel_manager=>nil, :request=>{:proxy=>nil}, :ssl=>{}, :status=>302, :response_headers=>{"date"=>"Thu, 25 Jul 2013 14:36:42 GMT", "server"=>"Apache/2.2.22 (Ubuntu)", "x-powered-by"=>"PHP/5.3.10-1ubuntu3.6", "location"=>"http://sushi.com/?f", "vary"=>"Accept-Encoding", "content-length"=>"20", "connection"=>"close", "content-type"=>"text/html", "set-cookie"=>"WEBUK=WUK08; path=/"}, :response=>#<Faraday::Response:0x007ff48f0422a8 ...>}, @on_complete_callbacks=[]>

i assume that you have some configuration block in your app like this:

conn = Faraday.new(:url => 'http://sushi.com') do |faraday|
  faraday.request  :url_encoded
  faraday.response :logger
  faraday.adapter  Faraday.default_adapter
end
conn.get '/nigiri/sake.json'

if you remove the logger line, than there should not be any output to STDOUT.

like image 167
phoet Avatar answered Sep 18 '22 19:09

phoet


Just remove the response :logger config when testing (!Rails.env.test?)

  Faraday.new(url: endpoint) do |faraday|
    faraday.request :url_encoded
    faraday.response :logger if !Rails.env.test?
    faraday.adapter Faraday.default_adapter
  end
like image 45
Rafael Oliveira Avatar answered Sep 17 '22 19:09

Rafael Oliveira