Ruby on rails 在rails助手方法中测试链接到输出
在过去的几天里,我一直在进行rails测试,遇到了一个助手测试的问题。我得到以下错误:Ruby on rails 在rails助手方法中测试链接到输出,ruby-on-rails,ruby-on-rails-4,minitest,helpers,Ruby On Rails,Ruby On Rails 4,Minitest,Helpers,在过去的几天里,我一直在进行rails测试,遇到了一个助手测试的问题。我得到以下错误: 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
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>'
这是主页面\u helper\u 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
需要“测试助手”
类MainPagesHelperTest“发布日期”,
:方向=>“描述”))
结束
结束
我是否应该使用assert_equal作为测试方法?我是否应该使用ActionView::TestCase来测试帮助程序?您对
链接到使用了错误的参数。您应该使用类似于链接到“链接文本”、项目列表路径(排序:“发布日期”、方向:“desc”)
的东西,而您可以使用散列而不是字符串或模型实例,您必须提供控制器和操作。您对链接到使用了错误的参数。您应该使用类似于链接到“链接文本”、项目列表路径(排序:“发布日期”、方向:“desc”)
的东西,而您可以使用散列而不是字符串或模型实例,您必须提供控制器和操作。
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