9

Here's what I have:

An application helper method that calls a controller helper method (private) from it.

Code:

ApplicationHelper:

def ordenar(coluna, titulo = nil)  
    titulo ||= coluna.titleize  
    css_class = (coluna == **coluna_ordenacao**) ? "#{**direcao_ordenacao**}" : "ordenavel"  
    direcao = (coluna == **coluna_ordenacao** and **direcao_ordenacao** == "asc") ? :desc : :asc  
    link_to titulo, {:sort => coluna, :direction => direcao}, {:class => css_class}  
end  

ApplicationController:

helper_method :coluna_ordenacao, :direcao_ordenacao  
private  
def coluna_ordenacao  
    return params[:sort] if params[:sort] and params[:sort].split(' ').size == 1  
    return :created_at  
end  

def direcao_ordenacao  
    return %w[asc desc].include?(params[:direction]) ? params[:direction] : :desc  
end  

And here is the problem: The coluna_ordenacao and direcao_ordenacao methods can't be called from RSpec, it gives me the following error:

undefined local variable or method `coluna_ordenacao' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_2:0x7fbf0a9fe3d8>

Is there any way for that to work? Btw I'm testing the helper, not the controller

Vasiliy Ermolovich
  • 24,459
  • 5
  • 79
  • 77

1 Answers1

2

You can access private methods in tests using .send(:private_methods_name)

see documentation

mlunoe
  • 4,422
  • 4
  • 32
  • 43
fuzzyalej
  • 5,903
  • 2
  • 31
  • 49