[rspec-users] testing named_scope

Craig Demyanovich cdemyanovich at gmail.com
Mon Jan 18 14:55:05 EST 2010


On Mon, Jan 18, 2010 at 5:17 AM, David Chelimsky <dchelimsky at gmail.com>wrote:

> On Mon, Jan 18, 2010 at 4:01 AM, Pat Maddox <mailinglists at patmaddox.com>
> wrote:
>

...


> > class User < ActiveRecord::Base
> >  named_scope :admins, :conditions => {:admin => true}
> > end
> >
> > describe User, "admins" do
> >  it "should include users with admin flag" do
> >    admin = User.create! :admin => true
> >    User.admin.should include(admin)
> >  end
> >
> >  it "should not include users without admin flag" do
> >    admin = User.create! :admin => false
> >    User.admin.should_not include(admin)
> >  end
> > end
>
> Small style matter, but I've leaning towards more declarative sounding
> example names:
>
> describe User, ".admins" do
>   it "includes users with admin flag" do
>     admin = User.create! :admin => true
>     User.admin.should include(admin)
>   end
>
>   it "excludes users without admin flag" do
>     non_admin = User.create! :admin => false
>     User.admin.should_not include(non_admin)
>   end
> end
>
> class User < ActiveRecord::Base
>   named_scope :admins, :conditions => {:admin => true}
> end
>
> We still have 'should' in the examples, but this produces more
> 'spec-like' output:
>
> User.admins
>   includes users with admin flag
>   excludes users without admin flag


I agree, David. I've been omitting "should" from the beginning. For me, it
made the start of every example look too similar.

Regards,
Craig
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20100118/37b11a90/attachment-0001.html>


More information about the rspec-users mailing list