[rspec-users] Database.truncate_all

Mark Wilden mark at mwilden.com
Sat Dec 6 01:32:20 EST 2008


On Fri, Dec 5, 2008 at 6:32 AM, Jeff Talbot <jeff.a.talbot at gmail.com> wrote:

> There is a seemingly very useful line of code in the cucumber wiki
> that I'd like to use:
>
>  After do
>    # Scenario teardown
>    Database.truncate_all
>  end
>

That's just an example of some code you might call in an After. A little
lower, you see

TempFileManager.clean_up

which also looks like non-Rails/Cucumber code.

A simple way to achieve the former would be

class Database
  def self.truncate
    TheModel.destroy_all
    TheOtherModel.destroy_all
    # etc
 end
end

destroy_all isn't exactly the same as SQL TRUNCATE, but it might serve your
purpose.

///ark
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20081205/b21ca7df/attachment.html>


More information about the rspec-users mailing list