Using FlexMock in a rails functional test.

Posted by dagda1 on Stack Overflow See other posts from Stack Overflow or by dagda1
Published on 2010-03-21T16:55:06Z Indexed on 2010/03/21 17:01 UTC
Read the original article Hit count: 213

Filed under:

Hi,

I have the following index action:

class ExpensesController < ApplicationController

  def index()
    @expenses = Expense.all
  end
end

I want to mock the call to all in a functional test. I am using flexmock and have written the following test:

require 'test_helper'
require 'flexmock'
require 'flexmock/test_unit'

class ExpensesControllerTest < 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

The problem is the the last assertion fais with the following error message:

<[]> expected but was nil

I am confused what I am doing wrong. Should this not work?

Cheers

Paul

© Stack Overflow or respective owner

Related posts about ruby-on-rails