[rspec-users] Mocking with Calculated Results

James Hillyerd james at hillyerd.com
Mon Apr 30 17:11:28 EDT 2007


On 4/30/07, s.ross <cwdinfo at gmail.com> wrote:
>
> Yes, I was afraid that might be the answer. Here's the problem. I
> have specs that say:
>
> describe "The Settings edit/update sequence" do
>    it "should succeed with POST and good data"
>    it "should fail with POST and bad data"
>    it "should fail with POST and bad ID"
> end


I don't know if it's right or wrong, but my controller tests have different
contexts for each one of those situations. ie: context "POST /foo/blah with
invalid :xyz param"

I think in some cases where I know find is being called multiple times, I
build an array of items, and then do:

Object.stub!(:find).and_return(*@items)

But that doesn't sound like it would help you.   What about:

Setting.should_receive(:find).with(:all).any_number_of_times.and_return([@setting,
@setting])
Setting.should_receive
(:find).with(1).any_number_of_times.and_return(@setting)

Don't think I've tried that before.

-james



-- 
James A. Hillyerd <james at hillyerd.com>
Chief Technical Officer - ActiveRain Corp
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070430/bb8e7210/attachment.html 


More information about the rspec-users mailing list