Ruby on rails 使用RSpec测试Rails中的视图帮助程序
我需要测试以下帮助程序:Ruby on rails 使用RSpec测试Rails中的视图帮助程序,ruby-on-rails,ruby,rspec,helper,Ruby On Rails,Ruby,Rspec,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)
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
这个很好用。但是,如果我将:count选项添加到have_选择器调用中,它会突然失败,有人能帮我找出原因吗?也许将html视为xml会有所帮助? 在那种情况下,我可以帮忙 它定义了一个matcher
have_xml
,它可能正是您所需要的。
虽然我知道如果
have_标记也能处理字符串会更好。也许将html视为xml会有帮助?
在那种情况下,我可以帮忙
它定义了一个matcherhave_xml
,它可能正是您所需要的。
虽然我知道如果have_标记也能在字符串上工作会更好。显然模板是最好的方法。显然模板是最好的方法。我相信你要找的是have_标记和带标记的RSpec助手
describe DashboardHelper do
describe display_all_courses do
it "should return an list of all the courses" do
7.times{ Factory(:course) }
helper.display_all_courses.should have_tag('ul') do
with_tag('li', 3)
end
end
end
end
我相信你要找的是have_tag和with_tag RSpec助手
describe DashboardHelper do
describe display_all_courses do
it "should return an list of all the courses" do
7.times{ Factory(:course) }
helper.display_all_courses.should have_tag('ul') do
with_tag('li', 3)
end
end
end
end
你能解释一下这个答案吗?