From a02a7d66a92b6defa25548283f77e516232383f7 Mon Sep 17 00:00:00 2001 From: Sam Saffron Date: Tue, 28 May 2019 11:33:08 +1000 Subject: [PATCH] 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. --- spec/components/file_helper_spec.rb | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/spec/components/file_helper_spec.rb b/spec/components/file_helper_spec.rb index 495bd02068b..910a4c8434e 100644 --- a/spec/components/file_helper_spec.rb +++ b/spec/components/file_helper_spec.rb @@ -52,16 +52,19 @@ describe FileHelper do 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") - found = FileHelper.download( - url, - max_file_size: 10000, - tmp_file_name: 'trouttmp', - follow_redirect: true - ) + begin + found = FileHelper.download( + url, + max_file_size: 10000, + tmp_file_name: 'trouttmp', + follow_redirect: true + ) - expect(found.read).to eq("i am the body") - found.close - found.unlink + expect(found.read).to eq("i am the body") + ensure + found&.close + found&.unlink + end end 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)) ensure tmpfile&.close + tmpfile&.unlink end end @@ -109,6 +113,7 @@ describe FileHelper do expect(Base64.encode64(tmpfile.read)).to eq(Base64.encode64(png)) ensure tmpfile&.close + tmpfile&.unlink end end @@ -135,6 +140,7 @@ describe FileHelper do expect(tmpfile.closed?).to eq(false) ensure tmpfile&.close + tmpfile&.unlink end end end @@ -157,6 +163,7 @@ describe FileHelper do expect(File.extname(tmpfile)).to eq('.png') ensure tmpfile&.close + tmpfile&.unlink end end end