title: flash[:notice].should_not be_nil failed in rspec
body: <p>Here is rspec code for controller:</p>
  
  <pre><code>it "should render edit if update was not saved" do
    item = Factory(:lease_item)
    session[:corp_head] = true
    post 'update', {:id =&gt; item.id, :name =&gt; 'nil'}
    flash[:notice].should_not be_nil
    response.should render 'edit'    
  end
  </code></pre>
  
  <p>The update in controller is:</p>
  
  <pre><code>  def update
      if (eng? &amp;&amp; dept_head?) || corp_head? || ceo?
        @lease_item = LeaseItem.find(params[:id])
        @lease_item.input_by_id = session[:user_id]
        if @lease_item.update_attributes(params[:lease_item], :as =&gt; :roles_update)
  
          #redirect
          redirect_to URI.escape("/view_handler?index=0&amp;msg=Lease item updated successfully")
        else
          #back to new
          render 'edit', :notice =&gt; "Item NOT updated"
        end
      else
        #back to previous page
        redirect_to URI.escape("/view_handler?index=0&amp;msg=NO right to update lease item")
      end    
    end
  </code></pre>
  
  <p>Here is the error code from rspec:</p>
  
  <pre><code>  1) LeaseItemsController GET 'update' should render edit if update was not saved
       Failure/Error: flash[:notice].should_not be_nil
         expected: not nil
              got: nil
  </code></pre>
  
  <p>"Item NOT updated" was expected in flash. However why there is nothing with flash[:notice]? Or how to rspec there is a message with render 'edit', :notice => 'Item NOT updated'</p>
  
  <p>Thanks.</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>Here is change in controller:</p>
  
  <pre><code>      ...........
        else
          #back to new
          flash[:notice] = "Item NOT updated"
          render 'edit'
        end
        .........
  </code></pre>
  
  <p>Here is the rspec code which passes:</p>
  
  <pre><code>   it "should render edit if update was not saved" do
        item = Factory(:lease_item)
        session[:corp_head] = true
        post 'update', {:id =&gt; item.id, :lease_item =&gt; {:name =&gt; 'nil'}}
        flash.should_not be_nil
        response.should render_template(:action=&gt; "edit")  
      end
  </code></pre>
  
  <p>It did not work if using flash[:notice].should_not be_nil (or .. flash.now[:notice]...). The error is Got nil which is the same as before. Also response.should render 'edit' (or ... render :action => 'edit') did not pass as well. The error is NameError or NoMethodError. Not sure why.</p>