[Rspec-users] Mocking causes empty specification blocks
chrisjroos at gmail.com
Tue Jul 25 03:03:19 EDT 2006
On 7/25/06, David Chelimsky <dchelimsky at gmail.com> wrote:
> On 7/24/06, Chris Roos <chrisjroos at gmail.com> wrote:
> > Maybe it would help if I pasted how I would like the code to look..
> > context "A feed validator with one header row but no required headers" do
> > setup do
> > @header_row = mock('header_row')
> > @header_row.should_receive(:header_row?).and_return(true)
> > io = [@header_row]
> > @feed_validator = FeedValidator.new(io)
> > end
> > specify "should not install an empty header validator" do
> > @header_row.should_not_receive(:install_validators)
> > @feed_validator.process
> > end
> > end
> > Anything that was in my original example that is not above was there
> > because otherwise my mock will complain of unexpected methods being
> > called. I don't think I'm able to use the :null_object option as I'm
> > relying on the fact that my mock complains if the install_validators
> > message is sent. Note the made up 'should_not_reveive' method above.
> > Maybe if I had something like this then I could indeed use the
> > null_object option?
> > As for having the feed_validator.process line in the setup, that was
> > kinda taken from the rSpec tutorial (re 'should not be empty after
> > push'). I was thinking along the lines of this object already being
> > processed.
> null_object only ignores things that you do not specify. If you
> specify that something should not be received, it should complain if
> it receives it. If it does not complain, raise a bug! That's how it
> should work.
Ahh, I couldn't previously find anyway of specifying that something
should not be called (I was trying should_not). I've just realised
that I need to do should_receive(:foo).never.
Not sure if it's possible but I'd guess the should_not_receive may be
With this info, I'll tidy my specs and see how they now look.
Thanks for all the help.
More information about the Rspec-users