[rspec-users] Specing Law of Demeter methods...

Britt Mileshosky mileshosky at hotmail.com
Thu Jul 17 21:13:46 EDT 2008

It's been suggested that instead of doing

-- organization.events.find(params[:id])

that you should be writing

-- organization.get_event( params[:id] )

and the orgs 'get_event' method should look like

-- def get_event( event_id )
--   self.events.find( event_id )
-- end

So are the following valid / efficient specs or am I testing what isn't my own code?

  it "should return a particular event" do
    event = stub("an event")
    events = stub("event association")
    @organization.get_event("1").should == event
  it "should raise error if it can't find event" do
    lambda{ @organization.get_event("1") }.should raise_error(ActiveRecord::RecordNotFound)

Any other suggestions?
Stay in touch when you're away with Windows Live Messenger.

More information about the rspec-users mailing list