[rspec-devel] [ rspec-Bugs-4690 ] Ordering of mock calls doesn't work in block mode

noreply at rubyforge.org noreply at rubyforge.org
Tue Nov 7 06:24:28 EST 2006


Bugs item #4690, was opened at 2006-06-06 23:31
You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=3149&aid=4690&group_id=797

Category: None
Group: None
>Status: Closed
Resolution: None
Priority: 3
Submitted By: Aslak Hellesøy (aslak_hellesoy)
Assigned to: Nobody (None)
Summary: Ordering of mock calls doesn't work in block mode

Initial Comment:
Two failing (and disabled) tests have been added to mock_ordering_test.rb to demonstrate this.

----------------------------------------------------------------------

Comment By: Aslak Hellesøy (aslak_hellesoy)
Date: 2006-11-07 11:16

Message:
I think we can safely reject this RFE. I recorded it for sake of information, not because I really need it.

----------------------------------------------------------------------

Comment By: David Chelimsky (dchelimsky)
Date: 2006-11-07 10:40

Message:
I'm not quite sure how we could possibly get this to work w/o some serious gymnastics. As far as the mock is concerned, it gets two calls with the same signature, and then a block that it executes. It has no relationship to what is inside the block. So we'd have to set up some temporary global to identify the current block being executed and ask all objects to register themselves on that. Eek.

Unless I'm missing something????

And is this really that useful that it would be worth the contortions? My feeling is no, but I would be happy to look at an example.

----------------------------------------------------------------------

Comment By: Brian Takita (btakita)
Date: 2006-10-28 00:46

Message:
Sorry. My mistake. I tried to look into this too late.

----------------------------------------------------------------------

Comment By: David Chelimsky (dchelimsky)
Date: 2006-10-27 16:10

Message:
Brian - in your example, the second should receive says "a1", "b2", but the second call says "b1", "b2". Was that your intent? If you align these the spec passes.

specify "should pass two calls in order to the same method"
do
   @mock.should_receive(:doit).ordered.with("a1", "b1")
   @mock.should_receive(:doit).ordered.with("a1", "b2")
   @mock.doit "a1", "b1"
   @mock.doit "b1", "b2"
   @mock.__verify
end

----------------------------------------------------------------------

Comment By: Brian Takita (btakita)
Date: 2006-10-27 08:01

Message:
I'm getting an issue with the ordered should_receive(:doit) being called twice.

It seems the first expectation wins and the second expectation never gets considered.

It also seems that the block is a red herring.

try:

specify "should pass two calls in order to the same method" do
   @mock.should_receive(:doit).ordered.with("a1", "b1")
   @mock.should_receive(:doit).ordered.with("a1", "b2")
   @mock.doit "a1", "b1"
   @mock.doit "b1", "b2"
   @mock.__verify
end


----------------------------------------------------------------------

Comment By: Aslak Hellesøy (aslak_hellesoy)
Date: 2006-10-14 13:19

Message:
Moving the tests here:

      def FIXME_test_two_in_order_calls_with_block
        @mock.should_receive(:doit).ordered do |a, b|
          a.should_equal "a1"
          a.should_equal "b1"
        end
        @mock.should_receive(:doit).ordered do |a, b|
          a.should_equal "a2"
          a.should_equal "b2"
        end
        @mock.doit "a1", "b1"
        @mock.doit "b1", "b2"
        @mock.__verify
      end

      def FIXME_test_two_out_of_order_calls_with_block
        @mock.should_receive(:doit).ordered do |a, b|
          a.should_equal "a1"
          a.should_equal "b1"
        end
        @mock.should_receive(:doit).ordered do |a, b|
          a.should_equal "a2"
          a.should_equal "b2"
        end
        @mock.doit "b1", "b2"
        @mock.doit "a1", "b1"
        @mock.__verify
      end


----------------------------------------------------------------------

You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=3149&aid=4690&group_id=797


More information about the rspec-devel mailing list