2012-05-15 38 views
0

如何使用Rspec的have_selector來驗證DOM元素沒有某些CSS類?如何使用Rspec檢查某些CSS類的缺失?

我想爲此使用CSS語法,但顯然Nokogiri不支持:not()選擇器。

例如:

it "should not add any class to other inputs" do 
    @buffer.output.should have_selector(
    'form input#monster_battle_cry:not(.integer, .decimal, .date, .phone, .zip)' 
) 
end 

這種失敗#Nokogiri::CSS::SyntaxError: # unexpected ':not('

+0

以逗號分隔的語法':not()'是非標準的(截至CSS3),所以我不太確定Nokogiri是否支持這種語法。 – BoltClock

回答

2

像這樣的東西是醜陋的,但應該工作:

it "should not add any class to other inputs" do 
    @buffer.output.should have_xpath(
    "//form//input[@id='monster_battle_cry'][not(contains(@class, 'integer'))]" 
) 
end 

重複[not(contains(@class, 'integer'))]與其他類。

編輯哎呀,CSS應該也行,僅是這樣的::not(.integer):not(.decimal)...

再次編輯不,它不需要有對這個開放式票:CSS selector with multiple :not fails

相關問題