<div dir="ltr">+1<br><br>If I approached RSpec without any existing knowledge, my assumption would be that the stubbed method would return the value. Anything we can do to preserve that sort of learning via discovery is a win.<br>
<br><div class="gmail_quote">On Fri, Sep 12, 2008 at 10:44 AM, Pat Maddox <span dir="ltr"><<a href="mailto:pergesu@gmail.com">pergesu@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hey guys,<br>
<br>
Here's a pretty simple spec<br>
<br>
describe AccountService do<br>
before(:each) do<br>
@account = stub("account", :balance => 12345)<br>
@service = AccoutnService.new<br>
end<br>
<br>
it "should check the balance" do<br>
@account.should_receive(:balance)<br>
@service.get_balance(@account)<br>
end<br>
end<br>
<br>
Ignore the fact that it's totally lame :)<br>
<br>
Right now, in the example, @account.balance will return nil. Any<br>
other specs that call it will get back 12345. What do you guys think<br>
about making it return the same value by default, instead of nil? So<br>
basically, instead of totally shadowing that method, we simply tighten<br>
up the constraints on the mock object by adding an expectation.<br>
<br>
Pros:<br>
- Less verbose - it expresses intent better, I think. You don't<br>
really care what it returns in that case. Just that it gets that<br>
method called, and everything works<br>
- No duplication. I can't think of a single instance where I stubbed<br>
a call, and then in my expectation I wanted it to return nil. I<br>
*always* duplicate it<br>
<br>
Cons:<br>
- Less verbose :) maybe some people would think it's not explicit enough?<br>
<br>
Personally, I'm all for it. What do you guys think?<br>
<br>
Pat<br>
_______________________________________________<br>
rspec-devel mailing list<br>
<a href="mailto:rspec-devel@rubyforge.org">rspec-devel@rubyforge.org</a><br>
<a href="http://rubyforge.org/mailman/listinfo/rspec-devel" target="_blank">http://rubyforge.org/mailman/listinfo/rspec-devel</a><br>
</blockquote></div><br></div>