>
> Hi, David,
> Thanks for that. Makes sense that the update_attributes message is to be
> received by the instantiated object and not the class.
>
> I made the following change and yet, I get an error implying that the
> update_attributes message is never called.
>
>
> ----------------- Spec extract starts --------------------------------
>
> context 'saves updates to an existing part object successfully' do
> before do
> part = double('part')
> end
> it 'does its job in saving the update' do
> part.should_receive(:update_attributes).and_return(true)
> Part.should_receive(:find).with(1).and_return(part)
> put :update, :id => 1, :part => {'title' => 'Brake pads'}
> flash[:notice].should eq('Part was successfully updated.')
> end
> end
>
> ----------------- Spec extract ends --------------------------------
>
> and the error reads:
>
>
> ------- Error extract begins -----------------
>
> 1) PartsController saves updates to an existing part object successfully
> does its job in saving the update
> Failure/Error:
> part.should_receive(:update_attributes).and_return(true)
> (Mock "Part_1006").update_attributes(any args)
> expected: 1 time
> received: 0 times
> # ./spec/controllers/parts_controller_spec.rb:56
>
> Finished in 0.25365 seconds
> 8 examples, 1 failure, 1 pending
>
>
> ------- Error extract ends -----------------
>
I found out why.
1. specs parts controller: the 'update_attributes' method is being
assigned with 'true'
2. parts controler: the 'update' method is using 'update_attributes!' and
not 'update_attributes'
Explains why update_attributes never got messaged :) thanks everyone :)
Here's my updated spec which passes :)
----------------- 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!).and_return(true)
put :update, :id => 1, :part => {'title' => 'Brake pads'}
flash[:notice].should eq('Part was successfully updated.')
end
end
----------------- Spec extract ends --------------------------------
thank you, all :)
--
You received this message because you are subscribed to the Google Groups
"rspec" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rspec?hl=en.