[rspec-users] Odd Date-based spec failing

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


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

describe Phase do

   include PhaseHelper

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

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

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

'Phase should know how to generate the percentage_complete attribute'  
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