Backports a fix for https://github.com/thoughtbot/shoulda-matchers/issues/913. This can be removed once new shoulda-matchers version is released.