Ruby-on-rails – Rspec, Rails: how to test private methods of controllers

rspecruby-on-rails

I have controller:

class AccountController < ApplicationController
  def index
  end

  private
  def current_account
    @current_account ||= current_user.account
  end
end

How to test private method current_account with rspec?

P.S. I use Rspec2 and Ruby on Rails 3

Best Answer

Use #instance_eval

@controller = AccountController.new
@controller.instance_eval{ current_account }   # invoke the private method
@controller.instance_eval{ @current_account }.should eql ... # check the value of the instance variable