Archive for the ‘functionals tests’ Category

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