[rspec-users] Database.truncate_all

David Salgado david at digitalronin.com
Sat Dec 6 05:47:21 EST 2008


ISTR that "destroy_all" will instantiate each object, before
destroying it. If you just want to clean the database, I think
"delete_all" is the one you want (it just does a "delete from
[table]", if memory serves), and should be a lot quicker.

David


2008/12/6 Mark Wilden <mark at mwilden.com>:
> 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
>
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>


More information about the rspec-users mailing list