[rspec-users] thoughts on mocks and specs

Pat Maddox pergesu at gmail.com
Mon Jan 8 01:19:50 EST 2007

On 1/7/07, Chris Anderson <jchris at mfdz.com> wrote:
> I spent the last couple of days getting my sea legs with Rails and
> RSpec. I'd been waiting til things seemed calmer before jumping in,
> and I'm overall very happy with my experience so far.
> My only real annoyance so far has been forgetting to call "do_post" or
> "do_create" from my specify blocks. My mocks don't get the calls they
> want, and it usually isn't until I've mucked around in my application
> code for a bit that I realize the real problem.
> Wouldn't it be nice to be able to define a callback that gets run
> after every specify block? Maybe it would look like this:
> context "A leaner syntaxed context" do
>   setup do
>     @obj = mock('obj')
>   end
>   body do
>     @obj.whatever
>   end
>   specify "should run the body block after every specification" do
>     @obj.should_receive(:whatever)
>   end
> end
> I know sometimes one might want to put some verification code after
> the body. In that case, you could allow an explicit call to body from
> within the specify block, which would preclude it from being called
> again at the end.
> It seems to me that this feature isn't just a fight for DRY, but also
> encourages good spec design. Situations diverse enough to need
> separate body code could use different contexts anyway.
> If there is a call for this feature, I'd be happy to make a go at
> patching it into RSpec.
> Reactions?
> --
> Chris Anderson
> http://jchris.mfdz.com
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users

You can do that using teardown.


More information about the rspec-users mailing list