diff --git a/tests/instrumentors/logging_instrumentor_tests.rb b/tests/instrumentors/logging_instrumentor_tests.rb index 3c984a72..128d4c65 100644 --- a/tests/instrumentors/logging_instrumentor_tests.rb +++ b/tests/instrumentors/logging_instrumentor_tests.rb @@ -1,4 +1,5 @@ require 'logger' +require 'tempfile' Shindo.tests('logging instrumentor') do env_init @@ -6,7 +7,7 @@ tests("connection logger").returns(true) do Excon.stub({:method => :get}, {body: 'body', status: 200}) - log_path = "/tmp/excon_#{Time.now.to_i}.txt" + log_path = Tempfile.create.path logger = Logger.new(log_path) # omit datetime to simplify test matcher logger.formatter = proc do |severity, datetime, progname, msg| @@ -19,8 +20,10 @@ logger: logger, mock: true ) + response = connection.request(method: :get, path: '/logger') - File.readlines(log_path)[1..2] == [ + + File.readlines(log_path) == [ "request: http://127.0.0.1/logger\n", "response: body\n" ] @@ -29,7 +32,7 @@ tests("connection logger with query as hash").returns(true) do Excon.stub({:method => :get}, {body: 'body', status: 200}) - log_path = "/tmp/excon_#{Time.now.to_i}.txt" + log_path = Tempfile.create.path logger = Logger.new(log_path) # omit datetime to simplify test matcher logger.formatter = proc do |severity, datetime, progname, msg| @@ -47,7 +50,7 @@ path: '/logger', query: {test: 'test'} ) - File.readlines(log_path)[1..2] == [ + File.readlines(log_path) == [ "request: http://127.0.0.1/logger?test=test\n", "response: body\n" ]