[rspec-devel] [ rspec-Patches-14082 ] [PATCH] allow stubs to yield and return values

noreply at rubyforge.org noreply at rubyforge.org
Sun Nov 18 20:08:40 EST 2007


Patches item #14082, was opened at 2007-09-19 21:30
You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=3151&aid=14082&group_id=797

Category: mock module
Group: None
>Status: Closed
Resolution: Accepted
Priority: 3
Submitted By: Pat Maddox (pergesu)
Assigned to: Nobody (None)
Summary: [PATCH] allow stubs to yield and return values

Initial Comment:
Passing blocks to a builder method is a common pattern.  For example:

    new_workflow = build(:name => "Default") do |w|
      w.add_step :name => "description"
      w.add_step :name => "screenshot_selection"
      w.add_step :name => "preview"
    end

This patch lets you stub a method and specify the object to yield and the object to return.  It's just a chained and_yield(foo).and_return(bar)

@new_workflow = mock_model(Workflow, :add_step => true)
Workflow.stub!(:build).and_yield(@new_workflow).and_return @new_workflow

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

Comment By: Chad Humphries (spicycode)
Date: 2007-11-19 01:00

Message:
Moved to http://rspec.lighthouseapp.com/projects/5645-rspec/tickets/10-allow-stubs-to-yield-and-return-values#ticket-10-2

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

Comment By: Aslak Hellesøy (aslak_hellesoy)
Date: 2007-11-05 23:16

Message:
This causes the following error in r2814:

1)
'a Mock expectation should use block for expectation if provided' FAILED
expected: "booh",
     got: nil (using ==)
./spec/spec/mocks/mock_spec.rb:101:

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

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


More information about the rspec-devel mailing list