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

noreply at rubyforge.org noreply at rubyforge.org
Wed Sep 19 17:30:17 EDT 2007


Patches item #14082, was opened at 2007-09-19 15: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: Open
Resolution: None
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

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

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