RSpec mock.with(Hash) expects an Array

The following problem, where RSpec would erroneously fail mock parameter checks in specs, has been fixed in either RSpec 2.13.0 or 2.13.1

RSpec was misinterpreting hash argument expections as arrays. If your expectation was “mock.with(a: 1, b: 2)”, you’d get:

RSpec::Mocks::MockExpectationError: <MyClass (class)> received :my_method with unexpected arguments
  expected: ({:a => 1, :b => 2})
       got: ([:a, 1], [:b, 2])

If you tried wrapping your arguments in a hash “mock.with({a: 1, b: 2})” you’d get the very confusing:

  expected: ([:a, 1], [:b, 2])
       got: ([:a, 1], [:b, 2])

Luckly, as mentioned, this is fixed in the latest version. Update if possible!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.