[rspec-users] Odd Date-based spec failing

Matt Darby matt at matt-darby.com
Mon Jun 30 22:04:38 EDT 2008


Hrm.

I have a spec for a model 'Phase'. a Phase has a start and end date,  
and a method 'percentage_complete' that calculates the percentage of  
time that has already elapsed between said start and end dates.

This spec passes as expected:

module PhaseHelper
   def valid_attributes
     {
       :start_date => Date.today - 5.days,
       :end_date => Date.tomorrow
     }
   end
end

describe Phase do

   include PhaseHelper

   before(:each) do
     @phase = Phase.new(valid_attributes)
   end

   it "should know how to generate the percentage_complete attribute" do
     @phase.percentage_complete.should == 83
   end



However, when I run 'rake spec:models', the spec fails:

'Phase should know how to generate the percentage_complete attribute'  
FAILED
expected: 83,
      got: 100 (using ==)


RSpec and rspec_on_rails are current from GitHub (RSpec gem has been  
reinstalled from source)


More information about the rspec-users mailing list