这就是我所拥有的:
码:
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
这是问题:无法从RSpec调用coluna_ordenacao和direcao_ordenacao方法,它给出了以下错误:
undefined local variable or method `coluna_ordenacao' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_2:0x7fbf0a9fe3d8>
有没有办法让它起作用?顺便说一下,我正在测试助手,而不是控制器
解决方法
您可以使用.send(private_methods_name)访问测试中的私有方法