Skip to content

Commit

Permalink
testing fix for #20
Browse files Browse the repository at this point in the history
  • Loading branch information
MarioRuiz committed Feb 24, 2020
1 parent 646b9c8 commit 807ef46
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions spec/nice_http/logs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,16 @@
end

it "logs to nice_http_YY-mm-dd-HHMMSS.log when :file specified" do
Dir.glob("./*.log").each { |file| File.delete(file) }
sleep 1
#Dir.glob("./*.log").each { |file| File.delete(file) }
files_orig = Dir["./nice_http_20*.log"]
klass.log = :file
http = klass.new("https://example.com")
http.logger.info "testing"
files = Dir["./nice_http_*.log"]
expect(files.size).to eq 1

content = File.read(files[0])
files_final = Dir["./nice_http_20*.log"]
files_final.sort!
expect(files_final.size-files_orig.size).to eq 1
content = File.read(files_final[-1])
expect(content).to match /testing/
end

Expand All @@ -109,7 +111,7 @@
end

it "raises error if log file not possible to be created" do
Dir.glob("./*.log").each { |file| File.delete(file) }
#Dir.glob("./*.log").each { |file| File.delete(file) }
klass.log = "./"
klass.new("https://example.com") rescue err = $ERROR_INFO
expect(err.class).to eq NiceHttp::InfoMissing
Expand All @@ -118,9 +120,9 @@
end

it "doesn't create any log file when exception on creating" do
klass.log = "./"
klass.log = "./tmp/lgs11/"
klass.new("https://example.com") rescue err = $ERROR_INFO
files = Dir["./*.log"]
files = Dir["./tmp/lgs11/*.log"]
expect(files.size).to eq 0
end

Expand All @@ -132,10 +134,11 @@
end

it 'logs data to relative path starting by slash' do
Dir.glob("./spec/nice_http/*.log").each { |file| File.delete(file) }
klass.log = '/nice_http_example.log'
#Dir.glob("./spec/nice_http/*.log").each { |file| File.delete(file) }
klass.log = '/nice_http_example123.log'
File.delete(klass.log) if File.exists?(klass.log)
klass.new("https://example.com")
expect(File.exist?('./spec/nice_http/nice_http_example.log')).to eq true
expect(File.exist?('./spec/nice_http/nice_http_example123.log')).to eq true
end

it "cannot close a connection that is already closed" do
Expand Down

0 comments on commit 807ef46

Please sign in to comment.