Forum: RSpec RSpec testing AR results

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
James B. (Guest)
on 2009-02-10 21:10
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 \
          be(@my_mage_local[my_time_local_before_type_cast])
This topic is locked and can not be replied to.