Guys,
I need to test the following helper:
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
and I'm wondering if there is a way that I can test the output of this. Basically, I just want to test that the helper gets me the correct number of li elements, and maybe the case when there aren't any courses.
My first thought is to do something like this:
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
and this works just fine. However, if I add the :count option to the have_selector call it suddenly fails, can anybody help me figure out why that is?