[rspec-devel] [ rspec-Feature Requests-12985 ] with_block_which_returns(val)
noreply at rubyforge.org
noreply at rubyforge.org
Fri Aug 10 19:25:30 EDT 2007
Feature Requests item #12985, was opened at 2007-08-10 23:25
You can respond by visiting:
http://rubyforge.org/tracker/?func=detail&atid=3152&aid=12985&group_id=797
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:
(me):
Maybe a better example would be in place. Consider the following
from the Autotest plugin:
Autotest.add_discovery do
"rspec" if File.exist?('spec')
end
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?
(David:)
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"
end
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
end
end
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.
----------------------------------------------------------------------
You can respond by visiting:
http://rubyforge.org/tracker/?func=detail&atid=3152&aid=12985&group_id=797
More information about the rspec-devel
mailing list