From efba8595fa373fe78c535dafdd8685bf3236acf5 Mon Sep 17 00:00:00 2001 From: Kenrick Chien Date: Thu, 16 May 2013 18:04:13 -0400 Subject: [PATCH 1/2] Update Gemfile to use rubygems.org to avoid deprecation warning --- Gemfile | 4 ++-- Gemfile.lock | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index 5684c3b..4a09ad4 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,4 @@ -source :rubygems +source 'https://rubygems.org' gemspec -gem 'rspec' \ No newline at end of file +gem 'rspec' diff --git a/Gemfile.lock b/Gemfile.lock index a7b05a5..c537c87 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -4,7 +4,7 @@ PATH simple-decorator (0.2.0) GEM - remote: http://rubygems.org/ + remote: https://rubygems.org/ specs: diff-lcs (1.1.3) rspec (2.10.0) From ee9e50339c90f1165dac7a1b8cdba43362c74535 Mon Sep 17 00:00:00 2001 From: Kenrick Chien Date: Thu, 16 May 2013 18:12:47 -0400 Subject: [PATCH 2/2] Refactor instance variables to #let --- spec/simple_decorator_spec.rb | 52 +++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/spec/simple_decorator_spec.rb b/spec/simple_decorator_spec.rb index 6f3c3ca..b1b93a8 100644 --- a/spec/simple_decorator_spec.rb +++ b/spec/simple_decorator_spec.rb @@ -1,49 +1,53 @@ require 'spec_helper' describe SimpleDecorator do + # User mock object + let(:user) { mock('user') } + + # Interface + let(:decorator) { SimpleDecorator.new(user) } + + # An other decorator + let(:other_decorator) { SimpleDecorator.new(decorator) } + before do - # User mock object - @user = mock('user') - @user.stub('first_name') { 'Foo' } - @user.stub('last_name') { 'Bar' } - @user.stub('count') { 1 } - - # Interface - @decorator = SimpleDecorator.new(@user) - def @decorator.first_name; 'Geronimo' end - def @decorator.count; @component.count + 1 end - - # An other decorator - @other_decorator = SimpleDecorator.new(@decorator) - def @other_decorator.count; @component.count + 2 end + user.stub('first_name') { 'Foo' } + user.stub('last_name') { 'Bar' } + user.stub('count') { 1 } + + def decorator.first_name; 'Geronimo' end + def decorator.count; @component.count + 1 end + + def other_decorator.count; @component.count + 2 end end + describe "is a true decorator" do describe 'Object behavior' do it 'should take an object as an argument for instanciation' do - SimpleDecorator.new(@user).should_not raise_error(ArgumentError) + SimpleDecorator.new(user).should_not raise_error(ArgumentError) end describe 'should be fully transparent' do - it { @decorator.should be_an_instance_of(@user.class) } - it { @decorator.should == @user } + it { decorator.should be_an_instance_of(user.class) } + it { decorator.should == user } end end # Object behavior describe 'Delegation behavior' do it 'should receive any known method an not pass them to the component' do - @decorator.first_name.should == 'Geronimo' - @decorator.first_name.should_not == 'Foo' + decorator.first_name.should == 'Geronimo' + decorator.first_name.should_not == 'Foo' end it 'should delegate unknown methods to the underlying component' do - @decorator.last_name.should == 'Bar' + decorator.last_name.should == 'Bar' end it 'should be able to decorate a decorator' do - @user.count.should == 1 - @decorator.count.should == 2 - @other_decorator.count.should == 4 + user.count.should == 1 + decorator.count.should == 2 + other_decorator.count.should == 4 end end # Delegation behavior end # is a true decorator -end \ No newline at end of file +end