我正在为我的 rails 应用程序编写测试。
我只想看到'.'和 '*' 符号,当 rspec 运行时。
但我在看 HTTP 日志,不知道如何禁用它们。
我的终端的 rspec 输出:
.............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
..
我认为原因可能是“法拉第” gem 的配置。
如何从我的 rspec 输出中禁用此日志?
最佳答案
法拉第默认不记录任何内容:
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=[]>
我假设您的应用程序中有一些配置块,如下所示:
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'
如果删除
logger
行,而不应该有任何输出到 STDOUT。
关于ruby-on-rails - 如何从 Rspec 输出中禁用 http 日志?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17857542/