[rspec-users] Testing that named_scope is defined

Helder Ribeiro helder at gmail.com
Tue May 13 22:14:00 EDT 2008


On Tue, May 13, 2008 at 9:20 PM, Pat Maddox <pergesu at gmail.com> wrote:
>
>
>  I wonder why OP doesn't create two records, call #most_recent, and
>  verify that the record returned is the one with the larger timestamp.

I'm sorry about the confusion here. Your idea sounds indeed better
(I'll explain below).

>
>  If the code is "not yours" (and I think you ought to clarify what you
>  mean by that), then you should be testing it at a higher level instead
>  of directly.

As I said, I'm not very familiar with specs and stuff, and I've read
repeatedly on this list and other places that one should only test
one's own code. That is, if you declare a has_many association, you
shouldn't test that the methods actually return the proper model
objects, etc., because that would be testing ActiveRecord. In that
same spirit, I thought I shouldn't test that a named_scope does what
it's supposed to, only that it is declared (because that one line is
all I wrote myself).

But I guess I got a bit carried away, as in that declaration there is
stuff besides the declaration itself, namely, the bit specifying the
order. So it would be better to test for that, rather than just
testing if it was declared or not.

Thanks a lot for your help :)


>
>  Pat
>
>
> _______________________________________________
>  rspec-users mailing list
>  rspec-users at rubyforge.org
>  http://rubyforge.org/mailman/listinfo/rspec-users
>



-- 
Helder Ribeiro

ProFUSION
Embedded Systems
http://profusion.mobi

"If I have not seen as far as others, it is because giants were
standing on my shoulders" -- Jeff Goll


More information about the rspec-users mailing list