ruby on rails - RSpec: How to test a helper method that calls a private helper method from the controller? -


here's have:

an application helper method calls controller helper method (private) it.

code:

applicationhelper:

def ordenar(coluna, titulo = nil)       titulo ||= coluna.titleize       css_class = (coluna == **coluna_ordenacao**) ? "#{**direcao_ordenacao**}" : "ordenavel"       direcao = (coluna == **coluna_ordenacao** , **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] , 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 problem: coluna_ordenacao , direcao_ordenacao methods can't called rspec, gives me following error:

undefined local variable or method `coluna_ordenacao' #<rspec::core::examplegroup::nested_1::nested_2:0x7fbf0a9fe3d8> 

is there way work? btw i'm testing helper, not controller

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

see documentation


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -