Rails testing: assert render action

For future people that find this, the correct method is:

assert_template :new

Let's say you have a controller action for create, as follows:

def create
  @post = Post.new(params[:post])

  respond_to do |format|
    if @post.save
      format.html { redirect_to(@post, :notice => 'Post was successfully created.') }
      format.xml  { render :xml => @post, :status => :created, :location => @post }
    else
      format.html { render :action => "new" }
      format.xml  { render :xml => @post.errors, :status => :unprocessable_entity }
    end
  end
end

And here is the standard Scaffold 'posts#new' view

<h1>New post</h1>

<% form_for(@post) do |f| %>
<%= f.error_messages %>
...... # just to show, it's bigger....

Now, if a Post is succesfully created you want to be redirected, but if it fails, we just want to re-render the NEW action. The test below uses what our main man DJTripleThreat said to use assert_template.

  test "should not create post and instead render new" do
    post :create, :post => { }

    assert_template :new
    #added to doubly verify
    assert_tag :tag => "h1", :child => /New post/
  end

If that still doesn't float your boat, I'd even add an assert_tag to make sure some of the view is coming up, so you know that it is displayed/rendered to the end user.

Hope this helps.