In unit or functional test, is there a way to check that a file has been deleted? It seems that running the test does not really execute deleting files, which is good because I don''t want it to actually delete the files. But can I check that the deletion should have been performed in test environment? thanks, - reynard -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060815/61b8207f/attachment.html
Correction, running the test actually deletes the file :( I think we want it to not delete the file but be able to check if the deletion has been performed, right? maybe I''ll try creating mock object for the File class. I''m sure someone else has encountered this need too. any suggestion? thanks - reynard On 8/15/06, Reynard Hilman <reynard.list@gmail.com> wrote:> > > In unit or functional test, is there a way to check that a file has been > deleted? > It seems that running the test does not really execute deleting files, > which is good because I don''t want it to actually delete the files. But can > I check that the deletion should have been performed in test environment? > > thanks, > - reynard >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060815/0504fd30/attachment-0001.html
On 15/08/06, Reynard Hilman <reynard.list@gmail.com> wrote:> Correction, running the test actually deletes the file :( > I think we want it to not delete the file but be able to check if the deletion has been performed, right? maybe I''ll try creating mock object for the File class. > I''m sure someone else has encountered this need too. any suggestion?You could use the Stubba component of Mocha (http://mocha.rubyforge.org) to do something like the following... def test_should_delete_file File.expects(:delete).with(''filename'').returns(1) object = MyClass.new object.method_which_deletes_file File.verify end This test should pass as long as the expected call to the File.delete method is made with the expected parameters. It will not actually delete the file. Make sense? James. http://blog.floehopper.org
Thanks James, that''s exactly what I need. - reynard You could use the Stubba component of Mocha> (http://mocha.rubyforge.org) to do something like the following... > > def test_should_delete_file > File.expects(:delete).with(''filename'').returns(1) > object = MyClass.new > object.method_which_deletes_file > File.verify > end > > This test should pass as long as the expected call to the File.delete > method is made with the expected parameters. It will not actually > delete the file. > > Make sense? > > James. > http://blog.floehopper.org >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060815/357f26ce/attachment.html