[rspec-devel] [ rspec-Feature Requests-8484 ] should_receive with blocks and cardinality

noreply at rubyforge.org noreply at rubyforge.org
Wed Feb 7 20:48:37 EST 2007


Feature Requests item #8484, was opened at 2007-02-07 19:28
You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=3152&aid=8484&group_id=797

Category: mock module
Group: None
>Status: Closed
Priority: 3
Submitted By: Micah Martin (slagyr)
Assigned to: David Chelimsky (dchelimsky)
Summary: should_receive with blocks and cardinality

Initial Comment:
the mock.should_receive method should accept cardinatliy along with blocks.

  specify "mock should receive call twice with block" do
    my_mock = mock("my mock")
    
    calls = 0
    my_mock.should_receive(:foo).twice { calls = calls + 1 }
    
    my_mock.foo
    my_mock.foo
    
    calls.should_eql 2
  end
  
  specify "mock should receive exactly 10 times with param" do
    my_mock = mock("my mock")
    
    sum = 0
    my_mock.should_receive(:foo).exactly(10).times { |i| sum = sum + i }
    
    10.times { |i| my_mock.foo(i) }
    
    sum.should_eql 45 
  end

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

>Comment By: David Chelimsky (dchelimsky)
Date: 2007-02-08 01:48

Message:
Added to trunk rev 1478.

a mock message receiving a block
- should call the block after #should_receive
- should call the block after #once
- should call the block after #twice
- should call the block after #times
- should call the block after #any_number_of_times
- should call the block after #with
- should call the block after #ordered


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

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


More information about the rspec-devel mailing list