diff --git a/lib/product.rb b/lib/product.rb index d4d81c3..9dd0b34 100644 --- a/lib/product.rb +++ b/lib/product.rb @@ -1,3 +1,5 @@ +require 'forwardable' + class Product attr_reader :name, :category, :tags @@ -6,6 +8,16 @@ def initialize(name, category, tags = []) @category = category @tags = tags end +end + +class ProductDecorator + extend Forwardable + + def_delegators :@context, :name, :category, :tags + + def initialize(context) + @context = context + end def as_html_row <<~EOF diff --git a/spec/anything_spec.rb b/spec/anything_spec.rb index 0e4a072..0b66070 100644 --- a/spec/anything_spec.rb +++ b/spec/anything_spec.rb @@ -27,6 +27,6 @@ end it 'can be printed as HTML table row' do - expect(tomato.as_html_row).to eq(expected_result) + expect(ProductDecorator.new(tomato).as_html_row).to eq(expected_result) end end