Skip to content

Instantly share code, notes, and snippets.

@fivetwentysix
Created April 3, 2012 03:51
Show Gist options
  • Save fivetwentysix/2289157 to your computer and use it in GitHub Desktop.
Save fivetwentysix/2289157 to your computer and use it in GitHub Desktop.
describe Item
describe "#received" do
it "should return the amount of goods received" do
receiving_records = mock_model(ReceivingRecord)
subject.stub(:receiving_records) { receiving_records }
receiving_records.stub(:sum).with(:quantity) { 3 }
subject.received.should == 3
end
end
end
class Item < ActiveRecord::Base
has_many :receiving_records
def received
receiving_records.sum(:amount)
end
end
@fivetwentysix
Copy link
Author

Is there a better way to write this Unit test? I particularly hate how I have to create a really ugly mock just to test a one-liner.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment