mirror of
https://github.com/discourse/discourse.git
synced 2025-03-23 17:25:42 +08:00
DEV: properly clean up temp files in FileHelper spec
Followup to 74297003 , also noticed other specs were not properly cleaning up so fixed that as well.
This commit is contained in:
parent
7429700389
commit
a02a7d66a9
@ -52,6 +52,7 @@ describe FileHelper do
|
|||||||
stub_request(:get, url).to_return(status: 302, body: "", headers: { location: url2 })
|
stub_request(:get, url).to_return(status: 302, body: "", headers: { location: url2 })
|
||||||
stub_request(:get, url2).to_return(status: 200, body: "i am the body")
|
stub_request(:get, url2).to_return(status: 200, body: "i am the body")
|
||||||
|
|
||||||
|
begin
|
||||||
found = FileHelper.download(
|
found = FileHelper.download(
|
||||||
url,
|
url,
|
||||||
max_file_size: 10000,
|
max_file_size: 10000,
|
||||||
@ -60,8 +61,10 @@ describe FileHelper do
|
|||||||
)
|
)
|
||||||
|
|
||||||
expect(found.read).to eq("i am the body")
|
expect(found.read).to eq("i am the body")
|
||||||
found.close
|
ensure
|
||||||
found.unlink
|
found&.close
|
||||||
|
found&.unlink
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "correctly raises an OpenURI HTTP error if it gets a 404" do
|
it "correctly raises an OpenURI HTTP error if it gets a 404" do
|
||||||
@ -95,6 +98,7 @@ describe FileHelper do
|
|||||||
expect(Base64.encode64(tmpfile.read)).to eq(Base64.encode64(png))
|
expect(Base64.encode64(tmpfile.read)).to eq(Base64.encode64(png))
|
||||||
ensure
|
ensure
|
||||||
tmpfile&.close
|
tmpfile&.close
|
||||||
|
tmpfile&.unlink
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -109,6 +113,7 @@ describe FileHelper do
|
|||||||
expect(Base64.encode64(tmpfile.read)).to eq(Base64.encode64(png))
|
expect(Base64.encode64(tmpfile.read)).to eq(Base64.encode64(png))
|
||||||
ensure
|
ensure
|
||||||
tmpfile&.close
|
tmpfile&.close
|
||||||
|
tmpfile&.unlink
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -135,6 +140,7 @@ describe FileHelper do
|
|||||||
expect(tmpfile.closed?).to eq(false)
|
expect(tmpfile.closed?).to eq(false)
|
||||||
ensure
|
ensure
|
||||||
tmpfile&.close
|
tmpfile&.close
|
||||||
|
tmpfile&.unlink
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -157,6 +163,7 @@ describe FileHelper do
|
|||||||
expect(File.extname(tmpfile)).to eq('.png')
|
expect(File.extname(tmpfile)).to eq('.png')
|
||||||
ensure
|
ensure
|
||||||
tmpfile&.close
|
tmpfile&.close
|
||||||
|
tmpfile&.unlink
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user