Topic: functional testing fails

def test_list
    get :list

    assert_response :success
    assert_template 'list'

    assert_not_nil assigns(:users)
  end
def test_create
    num_users = User.count

   post :create, :user => users(:one).attributes

    assert_response :redirect
    assert_redirected_to :action => 'list'

    assert_equal num_users + 1, User.count
  end


but this gives me error like


Exception: You have a nil object when you didn't expect it!
The error occurred while evaluating nil.user_name
On line #40 of app/views/layouts/user_layout.rhtml

           <table border="0" cellpadding="0" cellspacing="0" height="35">
                     
                 <tbody>
(linenumber40). <h4>Logged in as <font color="red"><%=session['user'].user_name%></font></h4>
                 
     <td class="topnav"><img src="/images/irunway/topnav.gif" height="15" width="15" /></td>

    #{RAILS_ROOT}/app/views/layouts/user_layout.rhtml:40:in `_run_rhtml_47app47views47layouts47user_layout46rhtml'
    C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_view/base.rb:326:in `send'
    C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_view/base.rb:326:in `compile_and_render_template'
    C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_view/base.rb:301:in `render_template'
    C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_view/base.rb:260:in `render_file'
    C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/layout.rb:254:in `render_without_benchmark'

Re: functional testing fails

As you don't have user object in the session ,it is failing at

<%=session['user'].user_name%>

One way could be checking nil conditions before you use them(every where), like
<% if session['user'] %>
     <h4>Logged in as <font color="red"><%=session['user'].user_name%></font></h4>
<% else %>
     Not Logged in
<% end %>

OR making sure that you have user object in the session.

Re: functional testing fails

1. <% if session['user'] %>
   2.      <h4>Logged in as <font color="red"><%=session['user'].user_name%></font></h4>
   3. <% else %>
   4.      Not Logged in
   5. <% end %>

this code is working & session object is passing.my session is not failed.
plz give me help whats the wrong