title: Failure/Error: expect(response).to render_template(:new)
body: <p>What am I doing wrong? I keep getting this error when I run rspec:</p>
  
  <blockquote>
    <p>Failures:</p>
    
    <p>1) AccountsController POST :create an account that already exists renders the :new template
         Failure/Error: expect(response).to render_template(:new)
           <strong>expecting &lt;"new"> but rendering with &lt;[]></strong>
         # ./spec/controllers/accounts_controller_spec.rb:131:in `block (4 levels) in '</p>
    
    <p>Finished in 0.26832 seconds
    34 examples, 1 failure</p>
    
    <p>Failed examples:</p>
    
    <p>rspec ./spec/controllers/accounts_controller_spec.rb:128 # AccountsController POST :create an account that already exists renders the :new template</p>
  </blockquote>
  
  <p>I verify that my code is written correctly by running it in the rails console. And true enough, it renders the :new template and even returns a 200. I do this by using the app object in the rails console. The output is below:</p>
  
  <pre><code>Started POST "/accounts" for 127.0.0.1 at 2014-03-26 21:18:06 -0700
  Processing by AccountsController#create as HTML
  Parameters: {"account"=&gt;{"name"=&gt;"name", "description"=&gt;"desc", "opening_balance"=&gt;"1.0"}}
   (0.1ms)  begin transaction
  Account Exists (0.2ms)  SELECT 1 AS one FROM "accounts" WHERE "accounts"."name" = 'name' LIMIT 1
   [deprecated] I18n.enforce_available_locales will default to true in the future. If you really want to skip validation of your locale you can set I18n.enforce_available_locales = false to avoid this message.
   (0.1ms)  rollback transaction
  **Rendered accounts/new.html.erb within layouts/application (1.4ms)**
  Completed 200 OK in 44ms (Views: 32.8ms | ActiveRecord: 0.3ms)
   =&gt; 200
  </code></pre>
  
  <p>This creates the same account twice. I expect that, it will fail and then redirect to :new template. The rspec code is here:</p>
  
  <pre><code>  context 'an account that already exists' do
  
       it 'renders the :new template' do
         call_post_create_verb
         call_post_create_verb
         **expect(response).to render_template(:new)**
       end
  
     end  
  </code></pre>
  
  <p>Look in the else condition and you will find where I render :new. The controller code is here:</p>
  
  <pre><code>def ceate
     @account = Account.new(account_params)
     if @account.save
       redirect_to @account
     else
       **render :new**
     end
  end
  </code></pre>
  
  <p>This is my setup:
  ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-darwin13.0]
  rails (4.0.3)
  rspec-rails (2.14.1)</p>