From 01a0a2d15c32f5b6c5cea88a6f778da59652d1a3 Mon Sep 17 00:00:00 2001 From: Yossef Mendelssohn Date: Mon, 17 Aug 2009 15:13:21 -0500 Subject: [PATCH] Adding instance-level summary. --- lib/punch/instance.rb | 4 +++ spec/punch_instance_spec.rb | 50 +++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/lib/punch/instance.rb b/lib/punch/instance.rb index fccb6f6..3bc4394 100644 --- a/lib/punch/instance.rb +++ b/lib/punch/instance.rb @@ -37,6 +37,10 @@ def log(message, options = {}) self.class.log(project, message, options) end + def summary(options = {}) + self.class.summary(project, options) + end + def ==(other) project == other.project end diff --git a/spec/punch_instance_spec.rb b/spec/punch_instance_spec.rb index 7160c9e..30c8591 100644 --- a/spec/punch_instance_spec.rb +++ b/spec/punch_instance_spec.rb @@ -382,6 +382,56 @@ end end + it 'should give project summary' do + @punch.should.respond_to(:summary) + end + + describe 'giving project summary' do + before do + @summary = 'summary val' + Punch.stub!(:summary).and_return(@summary) + end + + it 'should accept options' do + lambda { @punch.summary(:format => true) }.should.not.raise(ArgumentError) + end + + it 'should not require options' do + lambda { @punch.summary }.should.not.raise(ArgumentError) + end + + it 'should delegate to the class' do + Punch.should.receive(:summary) + @punch.summary + end + + it 'should pass the project when delegating to the class' do + Punch.should.receive(:summary) do |proj, _| + proj.should == @project + end + @punch.summary + end + + it 'should pass the options when delegating to the class' do + options = { :format => true } + Punch.should.receive(:summary) do |_, opts| + opts.should == options + end + @punch.summary(options) + end + + it 'should pass an empty hash if no options given' do + Punch.should.receive(:summary) do |_, opts| + opts.should == {} + end + @punch.summary + end + + it 'should return the value returned by the class method' do + @punch.summary.should == @summary + end + end + describe 'equality' do it 'should be equal to another instance for the same project' do Punch.new('proj').should == Punch.new('proj')