Skip to content

Commit

Permalink
added some unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Falkén committed Apr 1, 2014
1 parent 07a1079 commit 5d698eb
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 3 deletions.
1 change: 1 addition & 0 deletions art_deco.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ Gem::Specification.new do |spec|

spec.add_development_dependency "bundler", "~> 1.5"
spec.add_development_dependency "rake"
spec.add_development_dependency "rspec-rails"
end
2 changes: 1 addition & 1 deletion lib/art_deco.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def self.current=(context)
@@current = context
end

cattr_reader :current
cattr_reader :current if self.respond_to? :cattr_reader
end


Expand Down
8 changes: 6 additions & 2 deletions lib/art_deco/decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def self.wrap(collection)

def method_missing(method_name, *args, &block)
if @component.respond_to?(method_name)
@component.try(method_name)
@component.send(method_name)
else
super
end
Expand All @@ -34,7 +34,11 @@ def respond_to_missing?(method_name, include_private = false)
end

def self.factory(component)
"#{component.class.name}Decorator".constantize.new(component) rescue ArtDeco::Decorator.new(component)
begin
"#{component.class.name}Decorator".constantize.new(component)
rescue
ArtDeco::Decorator.new(component)
end
end

end
Expand Down
19 changes: 19 additions & 0 deletions spec/fixtures/fixtures.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class Dummy
def get_data
'data'
end

def shared_method
'original'
end
end

class DummyDecorator < ArtDeco::Decorator
def get_additional_data
'additional data'
end

def shared_method
'overridden'
end
end
9 changes: 9 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require 'bundler/setup'
Bundler.setup
require 'art_deco'

RSpec.configure do |config|
config.color_enabled = true
config.tty = true
config.formatter = :documentation
end
22 changes: 22 additions & 0 deletions spec/unit/art_deco_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
require 'spec_helper'
require 'fixtures/fixtures'

describe ArtDeco do

before(:each) do
dummy = Dummy.new
@decorator = DummyDecorator.new(dummy)
end

it 'exposes components methods' do
expect( @decorator.get_data ).to eq('data')
end

it 'adds decorator methods' do
expect( @decorator.get_additional_data ).to eq('additional data')
end

it 'overrides components methods' do
expect( @decorator.shared_method ).to eq('overridden')
end
end

0 comments on commit 5d698eb

Please sign in to comment.