过去几天我一直在进行我的测试,并且通过帮助测试遇到了麻烦。我收到以下错误:
ActionController::UrlGenerationError: No route matches {:action=>"index", :direction=>"asc", :sort=>"publish_date"}
app/helpers/main_pages_helper.rb:14:in `sortable'
test/helpers/main_pages_helper_test.rb:24:in `block in <class:MainPagesHelperTest>'
帮助程序基于#228 railscast,主要是main_pages_helper.rb代码:
module MainPagesHelper
def sortable(column, title = nil)
direction = (column == params[:sort] && params[:direction] == "asc") ?
"desc" : "asc"
# check if sort parameter is being used
if params[:sort] == column
title += direction == "asc" ? " ▾" : " ▴"
end
link_to title, :sort => column, :direction => direction
end
# Not yet tested
def categorizable(category)
category_select = params[:cat_sort] == category ?
params[:cat_sort] = nil : category
link_to category, :cat_sort => category_select,
:sort => params[:sort], :direction => params[:direction]
end
end
这是main_pages_helper_test.rb代码:
require 'test_helper'
class MainPagesHelperTest < ActionView::TestCase
include MainPagesHelper
test "should sort time descending" do
assert_equal(sortable("publish_date", "proj_list"),
(link_to "proj_list", :sort => "publish_date",
:direction => "desc"))
end
end
我不应该使用assert_equal作为测试方法吗?我是否应该使用ActionView :: TestCase来测试助手?