title: Using ActionView::TestCase::Behavior and the view method in a presenter spec
body: <p>Using the Railscast example, I have written a spec for my presenter which includes <code>ActionView::TestCase::Behavior</code> and passes in the <code>view</code> method to the presenter.</p>
  
  <p><code>spec/spec_helper.rb</code>:</p>
  
  <pre><code>  ... 
    config.include ActionView::TestCase::Behavior, :example_group =&gt; {:file_path =&gt; %r{spec/presenters}}
    ...
  </code></pre>
  
  <p><code>spec/presenters/order_presenter_spec.rb</code>:</p>
  
  <pre><code>  require 'spec_helper'
  
    describe OrderPresenter do
  
      describe "#subtotal" do
        subject { OrderPresenter.new(order, view).subtotal }
  
        let(:order) { stub(:order, working_subtotal: 4500) }
  
        it "renders the subtotal table row" do
          should == "&lt;tr&gt;&lt;th&gt;SUBTOTAL&lt;/th&gt;&lt;td&gt;$45.00&lt;/td&gt;&lt;/tr&gt;"
        end
      end
    end
  </code></pre>
  
  <p>However, this gave me two errors. 
  The first was </p>
  
  <pre><code>  /Users/shevaun/.rvm/gems/ruby-1.9.3-p392/gems/actionpack-3.2.13/lib/action_controller/test_case.rb:12:in `block in &lt;module:TemplateAssertions&gt;': undefined method `setup' for #&lt;Class:0x007fe2343b2f40&gt; (NoMethodError)
  </code></pre>
  
  <p>so I included <code>ActiveSupport::Testing::SetupAndTeardown</code> in the same way as <code>ActionView::TestCase::Behavior</code>.</p>
  
  <p>Fixing that gave me the error:</p>
  
  <pre><code>  NoMethodError:
     undefined method `view_context' for nil:NilClass
  </code></pre>
  
  <p>when calling <code>view</code>. This is caused by the <code>@controller</code> instance variable inside <code>ActionView::TestCase</code> being <code>nil</code>.</p>
  
  <p>I am using Rails 3.2.13 and rspec-rails 2.13.0 and have another application using the same versions which <em>just works</em>.</p>
  
  <p>The only thing I can think of that might make a difference is that this app is using MongoDB so maybe the ActiveRecord application includes something which sets up  <code>@controller</code> for free?</p>
  
  <p>I have got a workaround which makes the presenter specs pass, but I would like to know how <code>@controller</code> normally gets instantiated, and if there's a more elegant way to do this for a MongoDB project (if it is ActiveRecord that's doing the magic).</p>