title: Using FlexMock in a rails functional test
body: <p>I have the following index action:</p>
  
  <pre><code>class ExpensesController &lt; ApplicationController
  
    def index()
      @expenses = Expense.all
    end
  end
  </code></pre>
  
  <p>I want to mock the call to all in a functional test. I am using flexmock and have written the following test:</p>
  
  <pre><code>require 'test_helper'
  require 'flexmock'
  require 'flexmock/test_unit'
  
  class ExpensesControllerTest &lt; ActionController::TestCase
  
    test "should render index" do
  
      flexmock(Expense).should_receive(:all).and_return([])
  
      get :index
  
      assert_response :success
      assert_template :index
      assert_equal [], assigns(:presentations)
    end
  end
  </code></pre>
  
  <p>The problem is the the last assertion fais with the following error message:</p>
  
  <blockquote>
    <p>&lt;[]> expected but was nil</p>
  </blockquote>
  
  <p>I am confused what I am doing wrong.  Should this not work?</p>