Rails functional test : what to test?

What to test in a functiona test?

Then what we need to test ?

  1. Assert that the page action rendered and returned successful HTTP response code, i.e. 200.
  2. Assert that the correct template was rendered.
  3. assert that the correct flash message was rendered
  4. Assert that action assigns a value to the @user variable.
  5. Assert that the right @user object was loaded.

class Admin::UserController
 def test_show
    get :show, :id => 1
    # assert that the http response was 200
    assert_response :success
    # assert that the correct template was rendered
    assert_template 'admin/userr/show'
    # assert that the variable  @user was assigned
    assert assigns( :user)
    # assert that the variable  @user was assigned with the correct values
    assert_equal 'Joel', assigns(:user).first_name
    assert_equal 'Spolsky', assigns(:user).last_name
  end
end
About these ads

No comments yet

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

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: