[rspec-users] lots of nil problems!

Phillip Koebbe phillipkoebbe at gmail.com
Mon Mar 22 15:53:28 EDT 2010

On 2010-03-20 12:17 PM, David Chelimsky wrote:
> 2. Setup context in before blocks, not expectations
> We want the example names to express the intent of each example.
> The before block in the "with valid id' context sets two expectations,
> and then each example sets one of its own. If "should_not_assign_to
> :message" fails because Message didn't receive :find_by_id, the
> failure has nothing to do with the intent expressed by that example.
> Same goes for @message.should_receive(:destroy).
> If you want those expectations to be part of the spec, then add
> examples for them. If you don't care that they are specified, then
> don't. Either way, prefer stub() over should_receive() in before
> blocks.

I just remembered why I started putting .should_receive in the setup. It 
was because I use Remarkable and I had the action (post :create, get 
:new, whatever) in the before block. Here's an example from what I'm 
working on today:


Before I started using Remarkable, I think I would have put the 
expectation in an example (I can't remember how much I used 
should_receive at that point, so I don't know for sure). When I started 
using Remarkable, I ran into the issue of needing to set the expectation 
before the action was performed, so I moved it into the setup. I had 
forgotten that until today when I was merrily moving the expectations 
back to examples and only having the stub in the setup.

So now my dilemma is to
1) continue doing it the way I have been even though it's not "proper"
2) wrap the Remarkable macros in a context so I can use a before block 
to execute the action
3) stop using Remarkable
4) some other solution I'm not currently aware of

Funny enough, I'm actually leaning toward #3.



More information about the rspec-users mailing list