Reputation: 157
I am developing a rails API application for an iphone app. Some of the endpoints lead to functions that write data into a file and stores it in a directory. Everything works fine but every time I run a test for one of these specific endpoints a file is written. Is it possible to get the file to automatically be removed once the test is complete?
More info: I am using RSpec with shoulda_matchers and FactoryGirl in case it is any use.
Upvotes: 1
Views: 139
Reputation: 27789
You can remove the file in an after
block, e.g.
context :foo do
let(:filename) { '/foo/bar/baz/qux.txt' }
it { ... }
after do
FileUtil.rm filename
end
end
Upvotes: 2