Skip to content

Instantly share code, notes, and snippets.

Created March 20, 2010 10:07
Show Gist options
  • Save anonymous/338594 to your computer and use it in GitHub Desktop.
Save anonymous/338594 to your computer and use it in GitHub Desktop.
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