[rspec-users] testing named_scope

David Chelimsky dchelimsky at gmail.com
Sun Jan 17 21:56:22 EST 2010


On Sun, Jan 17, 2010 at 8:17 PM, Nin <npdepolonia at gmail.com> wrote:

> Hi! I'm new to rspec and was wondering how named_scopes are usually
> tested? Is it enough to test that it's defined? or do you need to test
> the behavior as well? I've been reading around and this seems to be
> the tester's choice, i just want to get people's opinion on this :D
>

_Specify_ the behaviour, don't _test_ the implementation. The fact that a
method is defined with a named_scope declaration is irrelevant to the
behaviour.

One reason for this is keeping things decoupled. Consider the fact that
named_scope just changed to scope today [1]. If your specs specify a call to
named_scope, they'll have to change, whereas if they they only specify the
name you define then you'll only need to update the implementation when you
upgrade.

[1]
http://github.com/rails/rails/commit/d60bb0a9e4be2ac0a9de9a69041a4ddc2e0cc914

That all make sense?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20100117/0988f69a/attachment.html>


More information about the rspec-users mailing list