Are you using rspec? You could use:

expect(date).to be_within(1.second).of(reference_date)

https://relishapp.com/rspec/rspec-expectations/v/3-8/docs/built-in-matchers/be-within-matcher


On Sat, Feb 9, 2019 at 3:07 PM Hillary Hueter <[email protected]> wrote:

> So i have to validate in a test that the date is being correctly written
> to the database.
>
> My Date function uses the following to get the date from an xml document
>
> DateTime.parse(@response.deep_select('TI').sort.reverse.first).strftime('%Y-%m-%d
> %H:%M:%S %z')
>
> TI will have a value like "2019-02-06T18:52:10.9986708-08:00"
>
> '%Y-%m-%d %H:%M:%S %z' is the database format.
>
> Where my test is failing is the process that writes to the database (which
> i can't update), is rounding this timestamp to the nearest second so the
> database value is 2019-02-06 18:52:11.000. So my tests are sometimes
> failing.
>
> So my question is how can i get this
> DateTime.parse(@response.deep_select('TI').sort.reverse.first).strftime('%Y-%m-%d
> %H:%M:%S %z') to include rounding to the nearest second so that my test
> will pass, since the rounding is acceptable.
>
>
>
>
>
>
>
>
>
>
> --
> --
> SD Ruby mailing list
> [email protected]
> http://groups.google.com/group/sdruby
> ---
> You received this message because you are subscribed to the Google Groups
> "SD Ruby" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>
-- 
--
Ylan Segal
[email protected]

-- 
-- 
SD Ruby mailing list
[email protected]
http://groups.google.com/group/sdruby
--- 
You received this message because you are subscribed to the Google Groups "SD 
Ruby" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to