嗨,我目前正在阅读有关测试的教程。我们正在构建帮助方法来突出显示导航栏中的选项卡。以下是辅助方法。
module RecipesHelper
def tabs(current_tab)
content_tag(:div, links(current_tab), :id => "tabs")
end
def links(current_tab)
nav_items.map do |tab_name, path|
args = tab_name, path
if tab_name == current_tab
args << {:class => "current"}
end
link_to *args
end.join(separator).html_safe
end
def nav_items
{
"New" => new_recipe_path,
"List" => recipes_path,
"Home" => root_path
}
end
def separator
content_tag(:span, "|", :class => "separator").html_safe
end
end
这是其中一项测试:
require 'test_helper'
class RecipesHelperTest < ActionView::TestCase
test "current tab is correct" do
render :text => tabs("New")
assert_select "a[class='current']" do |anchors|
anchors.each do |anchor|
assert_equal new_recipe_path, anchor.attributes['href']
end
end
end
end
anchors
我的问题是块中传递的变量是什么?与嵌套块相同的问题anchor
。谢谢。