[Rspec-devel] mocks with blocks

David Chelimsky dchelimsky at gmail.com
Sat Sep 2 12:59:05 EDT 2006

A pet peeve of mine is having to maintain two ways to do the same
thing - especially when one is far simpler to understand than the

The following syntax is currently supported for defining expected
arguments and return values in a block:

@mock.should_receive(:random_call) do | a, b |
  a.should_equal "a"
  b.should_equal "b"

Given the above, this passes:

assert_equal("booh", @mock.random_call("a", "b"))

But you could just as easily do this:


which is far more clear IMO.

Admittedly, the block syntax is a bit more flexible, as it allows you
to provide custom matching like this:

@mock.should_receive(:msg) do |val|
  val.should_be_close 0.25, 0.001

But I'm not convinced that anyone is actually using it and I'd like to
kill it as the supporting code is just gumming up the works. Are any
of you using it?


More information about the Rspec-devel mailing list