[rspec-users] Route is valid but not found :(

ct9a anexiole at gmail.com
Tue Aug 23 00:14:57 EDT 2011



On Aug 23, 1:55 pm, Justin Ko <jko... at gmail.com> wrote:
> On Mon, Aug 22, 2011 at 9:09 PM, ct9a <anexi... at gmail.com> wrote:
>
> > Thanks, Justin.
>
> > I have the part object mocked up before each spec runs.
>
> > ------- Extract begins -----------------
>
> >    let(:part){
> >        mock_model('Part').as_null_object
> >    }
>
> >    before do
> >        Part.stub(:new).and_return(part)
> >    end
>
> > ------- Extract ends -----------------
>
> > With that in mind, I just made changes to my spec as below:
>
> > ------- Extract begins -----------------
>
> >    it 'saves updates to an existing part object successfully' do
> >         Part.should_receive(:find).with(1).and_return(part)
> >        Part.should_receive(:update).with( 'title' =>
> > 'Grimspeed' ).and_return(part)
>
> Should be:
>
> Part.should_receive(:update_attributes).with('title' =>
> 'Grimspeed').and_return(part)
>
> No where do you call `update` on Part.

Yes, I have done that and the spec looks like below.

------------------ Spec extract begins
------------------------------------------
    context 'saves updates to an existing part object successfully' do
        it 'does its job in saving the update' do
            Part.should_receive(:find).with(1).and_return(part)
            Part.should_receive(:update_attributes).with('title' =>
'Brake pads').and_return(part)
            put :update, :id => 1, :part => {'title' => 'Brake pads'}
        end
    end
------------------ Spec extract ends
------------------------------------------

Alas, it's still giving out an error indicating the update_attributes
message is never called.
I've already got a put request to the 'update' method with an id and
the part hash parameter
and yet it looks like 'update' is not called (which in will call
update_attributes in it).

----------------- Error extract starts
-------------------------------------------------

  1) PartsController saves updates to an existing part object
successfully does its job in saving the update
     Failure/Error:
Part.should_receive(:update_attributes).with('title' => 'Brake
pads').and_return(part)
       (<Part(id: integer, title: string, description: text,
created_by: string, updated_by: string, created_at: datetime,
updated_at: datetime) (class)>).update_attributes({"title"=>"Brake
pads"})
           expected: 1 time
           received: 0 times
     # ./spec/controllers/parts_controller_spec.rb:54

Finished in 0.25483 seconds
8 examples, 1 failure, 1 pending

----------------- Error extract end
-------------------------------------------------

Hmm.... What is missing?




More information about the rspec-users mailing list