[rspec-users] ActiveRecordAssociationMatcher

Steve Tooke steve.tooke at gmail.com
Fri Aug 10 10:29:47 EDT 2007


I've started to put together a custom expectation matcher for
specifying AR associations. Its not quite complete and I really need
to put some specs together for it, but I'd appreciate any comments.

It lets you spec your associations like this:

describe Record do
  include ActiveRecordAssociationMatchers

  it "should belong to artist and use a counter cache" do
    Record.should belong_to(:artist).with_options(:counter_cache => true)
  end

  it "should have_many tracks" do
    Record.should
have_many(:tracks).with_class_name("Song).and_options(:include =>
:writers)
  end
end

Please see my blog entry or the pastie for more details.

http://stevetooke.karmatrading.co.uk/2007/8/10/simple-rails-association-matching-with-rspec
http://pastie.caboo.se/86604


More information about the rspec-users mailing list