seattlerb/minitest — pull request #79 by chastell (2011-12-28 20:20:40+00:00)
Title: MiniTest::Mock: store and verify same-method expects

Due to `MiniTest::Mock#expect`’s behaviour of populating the `@expected_calls` Hash on a one-method/one-retval+args basis it’s impossible to expect and verify subsequent calls (with different params) to the same method.

I’m hitting this problem quite often:

```Ruby
require 'minitest/autorun'

class Corge
def grault foo
foo.bar :qux
end
end

describe Corge do
describe '#grault'
it 'calls foo.bar twice, with :baz and :qux' do
foo = MiniTest::Mock.new
foo.expect :bar, nil, [:baz]
foo.expect :bar, nil, [:qux]

quux = Corge.new
quux.grault foo

foo.verify
end
end
end
```

(The above passes, even though `foo.bar` was never called with `:baz`.)

The attached patch makes `@expected_calls` store all of the expects to the given method (not just the last one), extends `MiniTest::Mock#method_missing` to handle this and makes sure `MiniTest::Mock#verify` checks for all of the assumptions. The `#method_missing` code still handles the broader expectations that use classes in `#expect`’s args Array.