こんにちは私は現在、テストに関するチュートリアルを行っています。ナビゲーションバーのタブを強調表示するためのヘルパーメソッドを構築しています。ヘルパーメソッドは次のとおりです。
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
これがテストの1つです:
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
。ありがとう。