On Tue, May 21, 2013 at 2:17 AM, netzfisch <[email protected]> wrote:

> Am Montag, 20. Mai 2013 13:20:02 UTC+2 schrieb [email protected]:
>
>> On Sun, May 19, 2013 at 2:32 PM, netzfisch <[email protected]> wrote:
>>
>>> I want to *test destroying a user* through the controller, therefore I
>>> do in user users_controller_spec.rb:
>>>
>>>     it "destroys the requested user" do
>>>
>>>
>>>
>>>       user = User.create! valid_attributes
>>>
>>>
>>>
>>>       expect {
>>>         delete :destroy, {:id => user.to_param}, valid_session
>>>
>>>
>>>
>>>       }.to change(User, :count).by(-1)
>>>
>>>
>>>
>>>     end
>>>
>>>
>>> The *valid_session* is generated that way
>>>
>>>   def valid_session
>>>     controller.stub(current_**user: mock_model(User))
>>>
>>>
>>>
>>>   end
>>>
>>> This ^^ returns an RSpec::Mocks::MethodDouble object, which is probably
>> not what you want.
>>
>
> ok, but what would be a sensefull and descriptive way of doing this - just:
>
>   let(:user) { User.create! valid_attributes }
>
>
>
>   def valid_session
>
>
>     { :user_id => user.id }
>
>
>   end
>
>
>
> or not to interfere the test - with the usage of a seperate user:
>   let(:user) { User.create! valid_attributes }
>
>   def valid_session
>     { :user_id => FactoryGirl.create(:user) }
>   end
>
> That depends entirely on the intent of the example. If I understand
correctly, this example specifies that the session user is removing
him/herself from the system, and the outcome is that user record is deleted
and that user's session is invalidated by assigning nil to the :user_id. In
that case, it should be the same user, but I would probably express that
right in the example to make it clear.

-- 
You received this message because you are subscribed to the Google Groups 
"rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rspec/CAKw-oWSpkuFiUvCSueVZkOue-dOG2nuey69KE4qWT8WG8WG-3Q%40mail.gmail.com?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to