[rspec-devel] [ rspec-Feature Requests-12895 ] mocks with inline stubs
noreply at rubyforge.org
noreply at rubyforge.org
Tue Aug 7 20:51:01 EDT 2007
Feature Requests item #12895, was opened at 2007-08-08 00:51
You can respond by visiting:
http://rubyforge.org/tracker/?func=detail&atid=3152&aid=12895&group_id=797
Category: None
Group: None
Status: Open
Priority: 3
Submitted By: Scott Taylor (smtlaissezfaire)
Assigned to: Nobody (None)
Summary: mocks with inline stubs
Initial Comment:
Oftentimes I find myself with a setup like this:
@mock = mock Object
Object.stub!(:new).and_return @mock
@mock.stub!(:method_one).and_return "foo"
@mock.stub!(:method_two).and_return "bar"
After several mock objects + their stubs in one setup/before block, this can get quite hard to read. This code could be abstracted into a helper method, but I find that generally does not help the readability of the situation.
Would the following solve the problem:
obj = mock Object do |o|
Object.stub!(:new).and_return o
o.stub!(:method_one).and_return "foo"
o.stub!(:method_two).and_return "bar"
end
or with an implicit receiver:
obj = mock Object do
stub!(:method_one).and_return "foo"
stub!(:method_two).and_return "bar"
end
I think this would go along way to making before/setup blocks easier to read, if, for no other reason, then the convention of pretty prettying. WDYT?
----------------------------------------------------------------------
You can respond by visiting:
http://rubyforge.org/tracker/?func=detail&atid=3152&aid=12895&group_id=797
More information about the rspec-devel
mailing list