Created
April 3, 2012 03:51
-
-
Save fivetwentysix/2289157 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.