[rspec-users] Odd Date-based spec failing

Camilo Torres xtrmclmb at gmail.com
Mon Jun 30 22:40:39 EDT 2008


It seems your Phase.percentage_complete is not working as you expect.
It clearly returns 100 when you are specting 83. The test clearly said
that.

¿What is the implementation of your percentage_complete method?

2008/7/1 Matt Darby <matt at matt-darby.com>:
> 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)
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>


More information about the rspec-users mailing list