[rspec-users] Shoulda

Pat Maddox pergesu at gmail.com
Thu Jan 10 19:45:15 EST 2008

On Jan 10, 2008 4:17 PM, Jonathan Leighton <j at jonathanleighton.com> wrote:
> In principle, yes. But what if your association isn't that interesting.
> What if it is literally has_many :posts and that's it. You still want to
> make sure it will work (for instance that the posts.blogger_id column
> actually exists), but you've got nothing interesting to poke it with...

I don't know.  I'm starting to think that this falls under the
category of so simple it's maybe not worth testing.

Using Rails associations in the simplest way, i.e. no special
conditions, is so declarative that I might consider it to be
specification enough.

I'm not sure though.  I'm not totally cool with the idea of trashing
the specs because the code is so expressive that it doesn't need them.

There's always *something* interesting.  If there weren't, it wouldn't
be in the code to begin with, right?  Your example can be something as
simple as

describe Blogger, " who just set up his site" do
  it "should have no posts" do
    Blogger.new.should have(0).posts

That at least tells you that there's a method named #posts, which
responds to length, and has a length of 0 when the blogger is first
instantiated.  That's more behavior-y than specifying the exact
structure of it.

I admit it's not interesting in the "call the sheriff, pa, there's
somethin in the barn" sense, but it is interesting in that it's a
facet of behavior that's worth knowing.


More information about the rspec-users mailing list