Testing the controller

A couple things I found very handy today while setting up a functional test for a controller.

First off, this controller relies on a user being logged in (but this isn't the controller that actually manages the login process).

The easiest way I found to make sure that I was properly logged in was to temporarily change @controller to the UserController — login — then change back. Like this:

controllerswap.png

A handy pointer regarding testing instance variables from Jeremy Kemper.

To access an instance variable in the controller that you are testing: simply examine what would have been sent to the view, in the response:

something = @response.template.assigns['something'] 

Advertisements

Leave a comment

Filed under Agile Software Dev, rails, Ruby, Test Driven Development (TDD)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s