[rspec-users] Clear a stub

Pat Maddox pergesu at gmail.com
Sun Jul 27 18:56:38 EDT 2008

On Sun, Jul 27, 2008 at 3:13 PM, Steve <vertebrate at gmail.com> wrote:
> Pat Maddox wrote:
>> Can you paste your code please?  Here's an example I just whipped up
>> that seems to work fine...I'm using a stub defined inline, a stub
>> defined in two steps, and a partially stubbed object.  They all shadow
>> the outer stub.  What does your code look like?
>> Pat
> It looks like I was lead somewhat astray. It wasn't the stubbing, it's
> actually something wrong with the fixture loading. The other fixtures that
> load with it seem to be okay, but the ones I need are just returning empty
> arrays.
> describe ReservationsController, "reservations/GET" do
>  describe "all reservations/ GET", :shared => true do
>    ...snip...
>    describe "with reservations" do
>      fixtures :customers, :users, :products, :reservation_statuses,
> :reservations, :reservation_items
>      before(:each) do
>        res = [reservations(:single), reservations(:cancelled),
> reservations(:surprise)]
>        Reservation.stub!(:find).and_return(res)
>      end
>      it "should group the reservations by date for the view assign" do
>        do_request
>        rd = assigns[:reservation_dates]
>        rd.should have(2).items
>      end
>    end
>  end
> end
> Instead of 'res' containing an array of three reservations, it's just an
> array of three empty arrays. I know the fixtures are good because I have
> used them in other specs. The 'reservations' collection is present, and it
> is aware of appropriate keys, but it just gives back empty arrays. Any
> thoughts on my new and improved problem?

So are you saying that
reservations(:single) == reservations(:cancelled) ==
reservations(:surprised) == []

When you print each of them out, that's what you see?

> I should also note that I'm running off of svn r3312 from around mid
> February. At this time I cannot update to trunk, so if it's a problem, and
> it has been fixed since that time, just let me know.

Well, a lot of stuff has happened since then :)  However, I'm not sure
what your problem is still so I can't tell you that it's been fixed
since then.  It sounds to me like you're saying reservations(:single)
returns a Reservation object in one test, but [] in this one.  Is that


More information about the rspec-users mailing list