Specing Law of Demeter methods

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”)
events.stub!(:find).with(“1”).and_return(event)
@organization.stub!(:events).and_return(events)
@organization.get_event(“1”).should == event
end

it “should raise error if it can’t find event” do
lambda{ @organization.get_event(“1”) }.should
raise_error(ActiveRecord::RecordNotFound)
end

Any other suggestions?

On Thu, Jul 17, 2008 at 8:13 PM, Britt Mileshosky
[email protected] wrote:

@organization.stub!(:events).and_return(events)
@organization.get_event(“1”).should == event
end

it “should raise error if it can’t find event” do
lambda{ @organization.get_event(“1”) }.should raise_error(ActiveRecord::RecordNotFound)
end

Any other suggestions?

http://plugins.code.lukeredpath.co.uk/browser/demeters_revenge/trunk

Cheers,
David