[rspec-users] Odd Date-based spec failing

David Chelimsky dchelimsky at gmail.com
Thu Jul 3 11:16:21 EDT 2008


On Jun 30, 2008, at 9:43 PM, Matt Darby wrote:

> On Jul 1, 2008, at 10:10 PM, Camilo Torres wrote:
>
>> 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?
>
> It only fails when run via 'rake spec:models'; otherwise, it passes.

Just catching up with this. When you say 'otherwise', how else are you  
running this that it passes?

Can you try these and tell us which ones pass and which ones fail?

rake spec
rake spec:models
script/spec spec
script/spec spec/models
script/spec spec/models -r
script/spec spec/models/phase_spec.rb
script/spec spec/models/phase_spec.rb -r
ruby spec/models/phase_spec.rb
ruby spec/models/phase_spec.rb -r

Thanks,
David

>
>
>  def percentage_complete
>    # Returns an integer representation of a percentage (i.e. '78')
>
>    return 100 if Date.today >= self.end_date
>
>    length_in_days  = (self.end_date - self.start_date).to_f
>    days_into_phase = (Date.today - self.start_date).to_f
>
>    ((days_into_phase / length_in_days) * 100.0).round
>  end
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users



More information about the rspec-users mailing list