# RSpec comparison of datetime objects failing

**URL:** <https://discuss.circleci.com/t/rspec-comparison-of-datetime-objects-failing/1111>\
**Category:** Bug Reports\
**Created:** [December 14, 2015, 9:37pm UTC](https://discuss.circleci.com/t/rspec-comparison-of-datetime-objects-failing/1111 "2015-12-14T21:37:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![shterrett](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/shterrett/32/736_2.png) [@shterrett](https://discuss.circleci.com/u/shterrett)\
**Post date:** [December 14, 2015, 9:37pm UTC](https://discuss.circleci.com/t/rspec-comparison-of-datetime-objects-failing/1111/1 "2015-12-14T21:37:19Z")

</div>

Comparison of `DateTime` objects in nested data structures is failing when the objects are equal. Two separate tests that were comparing hashes that had `DateTime` objects as values both failed on CircleCI, but passed locally (on multiple developer machines).

We are using:  
rspec (3.2.0)  
rails (4.2.1)  
ruby 2.1.6

Examples of the two tests:

```
expect({ start_date: <A DateTime Object> }).to include({ start_date: <Another DateTime object> })

expect([{ start_date: <A DateTime Object> }, { start_date: <A DateTime Object> }]).to(
  match_array([{ start_date: <A DateTime Object> }, { start_date: <A DateTime Object> }]
)

```

Both of these tests passed in CircleCI when `to_s` was called on the `DateTime` objects.

---

<div class="post-metadata">

**Author:** ![Laszlo](https://avatars.discourse-cdn.com/v4/letter/l/cc9497/32.png) [@Laszlo](https://discuss.circleci.com/u/Laszlo)\
**Post date:** [July 18, 2017, 3:17pm UTC](https://discuss.circleci.com/t/rspec-comparison-of-datetime-objects-failing/1111/2 "2017-07-18T15:17:28Z")

</div>

We came across this same issue.

We are using:  
rspec (3.5.2)  
rails (5.0.1)  
ruby (2.3.0)

Ended up updating the tests to compare the specific `DateTime` object details that are important for us through `.strftime`.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/circleci/original/3X/5/1/511608acda8e85906e15909b57bd0a46c1dbe291.png) [@system](https://discuss.circleci.com/u/system)\
**Post date:** [June 18, 2018, 11:33am UTC](https://discuss.circleci.com/t/rspec-comparison-of-datetime-objects-failing/1111/3 "2018-06-18T11:33:55Z")

</div>


