我需要测试以下助手:
def display_all_courses
@courses = Course.all
output = ""
for course in @courses do
output << content_tag(:li, :id => course.title.gsub(" ", "-").downcase.strip) do
concat content_tag(:h1, course.title)
concat link_to("Edit", edit_course_path(course))
end
end
return output
end
我想知道是否有一种方法可以测试它的输出。基本上,我只是想测试帮助程序是否为我提供了正确数量的 li 元素,并且可能是没有任何课程的情况。
我的第一个想法是做这样的事情:
describe DashboardHelper do
describe display_all_courses do
it "should return an list of all the courses" do
7.times{Factory(:course)
html = helper.display_all_courses
html.should have_selector(:li)
end
end
end
这很好用。但是,如果我将 :count 选项添加到 have_selector 调用它突然失败,有人可以帮我弄清楚为什么会这样吗?