RSpec: How to test a helper method that calls a private helper method from a controller?

Here is what I have:

A helper method of the application that calls the helper method of the controller (private) from it.

the 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 cannot be called from RSpec, this 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 to do this? Btw I'm testing an assistant, not a controller

+8
ruby ruby-on-rails ruby-on-rails-3 testing rspec
source share
1 answer

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

see documentation

+1
source share

All Articles