[rspec-users] RSpec testing AR results

James Byrne lists at ruby-forum.com
Tue Feb 10 14:10:22 EST 2009

The TDD/BDD stuff is really quite amazing.  In order to construct tests
on a library that I wrote to implement custom magic columns I have
learned some extremely valuable information respecting date and time
recording in Rails. Which leads to my question:

I am presently testing an AR stored time object thus:

        @my_mage_local[dt_col].to_f.should be_close(
            @my_mage_local[dt_col].to_f +
            @my_mage_local.my_time_local.utc_offset, 0.01)

However, it occurs to me that instead I might wish to compare datetime
values as they are returned from the database without considering their
numeric value, which is dependent upon AR itself.  When I check the
class of a datetime object before casting I see this:

        @my_mage_local["#{dt_col}_before_type_cast"].class => String

Should I be comparing string values instead? For example:

        @my_mage_local["#{dt_col}_before_type_cast"].should \
Posted via http://www.ruby-forum.com/.

More information about the rspec-users mailing list