[rspec-users] Do you think it would look cleaner?
dchelimsky at gmail.com
Sat Dec 29 16:14:12 EST 2007
On Dec 29, 2007 6:00 PM, Andrew WC Brown <omen.king at gmail.com> wrote:
> I just see these large blocks of:
> and it would be much clearer if I could list them in a hash instead.
It would definitely be less typing, but I don't think it would be as
clear in terms of intent.
We do have a similar syntax to what you're looking for for stubs:
list = stub("list",
:milk => 'milk'
This makes sense to me for stubs for a couple of reasons. One is that
it is similar to the syntax for creating an OpenStruct, which should
be familiar to any ruby developer.
If we were to do the same with expectations we lose two things. Most
importantly is the line number of the failure when one occurs. Also,
and_return is already problematic for me after should_receive because
it implies an expectation - it should receive this and it should
return that, as opposed to it should receive this and when it does go
ahead and return that so that the example can keep moving :) Combining
these two concepts into one method name would make this even more
confusing in my perception.
There are other mock frameworks that might come closer to the
terseness you desire. You should check out mocha and RR
(http://rubypub.com/gem/rr-0.3.11/) if that's what you're looking for.
They both offer a different "feel" from rspec's framework and some
different features as well.
More information about the rspec-users