[mocha-developer] Nested matchers

Duncan Beevers duncanbeevers at gmail.com
Mon Jan 28 16:54:38 EST 2008


So we cleared this up by making the kind_of matcher to return true
when tested for equality with an instance of the class it is supposed
to match on.

Diff is attached, the important bit is here in kind_of.rb:

       def matches?(available_parameters)
         parameter = available_parameters.shift
-        parameter.kind_of?(@klass)
+        self == parameter
       end
+
+      def ==(to_compare)
+        to_compare.kind_of?(@klass)
+      end

Feelings?

On Jan 28, 2008 11:36 AM, Duncan Beevers <duncanbeevers at gmail.com> wrote:
> We're encountering a failure with Mocha 0.5.6.
>
> We had this expectation:
>
> game_version.expects(:attributes=).with(:game_file =>
> kind_of(GameFile), :game_id => @game.id)
>
> This expectation was passing with 0.5.5, but fails with 0.5.6.
>
> I added this test to parameter_matcher_acceptance_test.rb, which
> passes in 0.5.5 and fails in 0.5.6
>
>   def test_should_match_nested_parameters
>     test_result = run_test do
>       mock = mock()
>       mock.expects(:method).with(:literal_key => kind_of(Integer))
>       mock.method(:literal_key => 1)
>     end
>     assert_passed(test_result)
>   end
>
> Any insight?
>


More information about the mocha-developer mailing list