[rspec-users] Prepare for newbie-ness

Scott Taylor mailing_lists at railsnewbie.com
Wed Sep 17 10:59:32 EDT 2008


On Sep 17, 2008, at 9:01 AM, Martin Streicher wrote:

>
> I find the debugger helpful to step through the underlying Rails  
> code when I am perplexed about the (errant) operation of something.  
> The underworld is full of wonderful secrets. Plus, I do make  
> mistakes and misinterpret and the debugger lets me take a look  
> around. I try to avoid making bad smells; the debugger is like  
> Harvey Keitel's character in Pulp Fiction.
>
> What about my other questions? Directions on how to write tests when  
> a model has_many or belongs_to? When to mock? Pointers to examples  
> would be the cheap and easy answer -- is there an open source  
> application with rspec tests?
>

Ultimately, it's all about how comfortable you feel.  Mocks will  
always smell bad with rails' associations because of the law of  
demeter violations that it promotes.  On the other hand, using real  
objects and saving to a database can be slow, but at least they give  
you some *feel* of the objects - that is, how they will actually be  
used in a production system.

One thing that I've realized over the (2) years of testing that I've  
done is that testing is just as much about accustoming you to see  
relevant error message and their context as it is about getting a  
suite green or anything else.  When a real bug pops up when  
integrating, or on staging, you're almost immediately aware of it's  
place and cause.  As I've replaced my test suite with mocks and stubs  
I find that this is less and less true, and I have less and less  
confidence that I'm shipping really solid software.

So, it's always a tradeoff.  Bend in the directly you feel more  
comfortable.

Scott


> Martin
>
>
>
> On Sep 16, 2008, at 3:41 PM, rspec-users-request at rubyforge.org wrote:
>
>>> require 'ruby-debug'
>>> debugger
>>>
>>> at the point in my code where I want to break into the debugger.  
>>> Then
>>> running the specs via most any means (including autotest, but not
>>> spec_server) will start up the debugger at that point. Frankly,  
>>> though, I'll
>>> often just stick in some p statements to show some data. Actually,  
>>> I use
>>> this little function:
>
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users



More information about the rspec-users mailing list