[rspec-devel] [ rspec-Feature Requests-12985 ] with_block_which_returns(val)

noreply at rubyforge.org noreply at rubyforge.org
Mon Nov 19 00:17:07 EST 2007

Feature Requests item #12985, was opened at 2007-08-10 19:25
You can respond by visiting: 

Category: None
Group: None
Status: Open
Priority: 3
Submitted By: Scott Taylor (smtlaissezfaire)
Assigned to: Nobody (None)
Summary: with_block_which_returns(val)

Initial Comment:

>From the mailing list:

Maybe a better example would be in place.  Consider the following
from the Autotest plugin:

Autotest.add_discovery do
   "rspec" if File.exist?('spec')

How would you go about testing this?

It's easy enough to test that Autotest receives the method
add_discovery.  But how would you deal with the block?

OK - now I'm starting to see. Concrete examples are always helpful.

I guess there's no mocking framework right now that would solve that
for you. What spec do you *wish* you could write?


Maybe something like this:

describe Autotest::Rspec "discovery" do
  it "should take a block returns 'rspec' if the file exists" do
    File.stub!(:exists?).and_return true
    Autotest.should_receive(:add_discovery).with_block_which_returns "rspec"
  it "should take a block which returns nil if the file does not exist" do
    File.stub!(:exists?).and_return false
    Autotest.should_receive(:add_discovery).with_block_which_returns nil

or maybe something like this:

Autotest.should_receive(:add_discovery).with(:val1, :val2).and_block_which_returns "rspec"

I'm open to a less verbose/more terse syntax.


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

Moved to http://rspec.lighthouseapp.com/projects/5645-rspec/tickets/106-12985-with_block_which_returns-val


You can respond by visiting: 

More information about the rspec-devel mailing list