describe 'highlighting' do
it 'should highlight account/settings' do
get '/account/settings'
response.should have_tag("a.active[href=?]", account_settings_path, /Account Settings/i)
end
it 'should highlight account/profile' do
get '/account/profile'
response.should have_tag("a.active[href=?]", account_profile_path, /Profile Information/i)
end
it 'should highlight account/picture' do
get '/account/picture'
response.should have_tag("a.active[href=?]", account_picture_path, /Profile Picture/i)
end
it 'should highlight account/notifications' do
get '/account/notifications'
response.should have_tag("a.active[href=?]", account_notifications_path, /Notifications/i)
end
it 'should not highlight Profile' do
get '/account/profile'
response.should_not have_tag("a.active[href=?]", account_settings_path, /Account Settings/i)
end
it 'should not highlight Notifications' do
get '/account/profile'
response.should_not have_tag("a.active[href=?]", account_notifications_path, /Notifications/i)
end
it 'should not highlight Picture' do
get '/account/profile'
response.should_not have_tag("a.active[href=?]", account_picture_path, /Profile Picture/i)
end
end
你可以写更多的测试,特别是对场景“不会对错误的行动突出”,但我认为这已经足够了。
我想测试它的原因是因为它是Rails插件(tabnav),而不是纯粹的设计。如果你在这里看一下这个pastie http://pastie.org/961207,我想你会明白我为什么要测试它。 要回答你的问题,我想测试它是否突出显示在正确的页面上。 tabnav的工作方式是,如果我在某个控制器和操作上,它会突出显示/更改特定链接的颜色。谢谢。 – 2010-05-15 01:49:32
我怀疑tabnav应用CSS类。拉起HTML文档,查看类是什么,然后测试它:)这种情况将归于此答案的第一段HTML结构,而不是最后两段。 – Matchu 2010-05-15 01:53:10
...其实,现在我想通过这个,你应该甚至是测试tabnav的基本功能?如果它已经过全面测试,只需信任它。 – Matchu 2010-05-15 01:57:06