开发者

Remove temporary files after doing tests

During doing unit tests in Rails a few temp files are created (associated with model). When test is done I开发者_JAVA技巧 want to remove these files, so I have to find a way to do this no matter the test passes or not. So, what are you suggestions?


Why not put the file creation in a setup and the destruction in a teardown function? Then the creation will run beforehand - no matter what - and the destruction will run afterwards - again, no matter what. If you want setup and teardown of these files only for certain conditions, there's a nice writeup on it here: http://technicalpickles.com/posts/rails-special-sauce-test-unit-setup-and-teardown/


In a meanwhile I've tested something like this:

begin
  ...
  asserts
  ...
ensure
  delete_temporary_files
end

and it also works fine.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜