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