[Ruby] Testing Models in Rails

Ryan Davis ryand-ruby at zenspider.com
Thu Jul 26 23:08:36 PDT 2007


On Jul 26, 2007, at 20:10 , Aaron Patterson wrote:

> On 7/26/07, Ryan Davis <ryand-ruby at zenspider.com> wrote:
>>
>> On Jul 26, 2007, at 10:19 , Aaron Patterson wrote:
>>
>>> On Thu, Jul 26, 2007 at 01:33:31PM -0700, Laurel Fan wrote:
>>>> Why are you trying to avoid hitting the database?  I would imagine
>>>> that avoiding the database makes it hard to test much of anything.
>>>
>>> Because hitting the database is expensive.  Actually I've found that
>>> I can test most of my code without hitting the database.  It  
>>> makes my
>>> tests much faster.  The problem here is that I don't know how to
>>> assert
>>> that my callback is defined *without* hitting the database.
>>
>> it isn't _that_ expensive:
>
> Unfortunately on our application it is expensive.  This app relies on
> database specific behavior, so switching to SQLite isn't really an  
> option.
> Maybe refactoring that functionality should be investigated, but  
> for now not
> hitting the DB gives me the best performance increase.
>
> Finished in 68.773742 seconds.
>> 1891 tests, 12052 assertions, 0 failures, 0 errors
>
> Interesting.  How does your IO break down?  How many tests read/ 
> write to the
> db?

this is hitting mysql over a local domain socket. probably 90%+ of  
the tests hit the db. not sure on the IO ... prolly not too heavy.



More information about the Ruby mailing list