Created
March 20, 2010 10:07
-
-
Save anonymous/338594 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class Product | |
attr_writer :price, :supplier | |
def price | |
@supplier ? @supplier.price_of(self) : @price | |
end | |
end | |
class Supplier | |
def price_of(product) | |
1599 | |
end | |
end | |
describe Product do | |
before do | |
@product = Product.new | |
@product.price = 1999 | |
end | |
it "should use own price as its price" do | |
@product.price.should == 1999 | |
end | |
context "with supplier" do | |
before do | |
@supplier = Supplier.new | |
@product.supplier = @supplier | |
end | |
it "should use supplier's price as its price" do | |
@product.price.should == @supplier.price_of(@product) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment