Html RSpec have_tag()与without_tag()/with_tag()组合
我希望以下几点能够通过,但事实并非如此:Html RSpec have_tag()与without_tag()/with_tag()组合,html,rspec,Html,Rspec,我希望以下几点能够通过,但事实并非如此: specify do '<p class="qwe rty" id="qwerty"><strong><em><span>Para</span></em></strong>graph</p>'.should have_tag('p > strong > em') do without_tag('em') end
specify do
'<p class="qwe rty" id="qwerty"><strong><em><span>Para</span></em></strong>graph</p>'.should have_tag('p > strong > em') do
without_tag('em')
end
end
这将失败,我看不到任何方法使它按我想要的方式工作。我想我误解了一些基本的东西
非常感谢你的帮助
更新
在浏览了一些其他项目的规范之后,这似乎真的不可能。例如,Formtastic有很多:
it 'should generate a label containing the input' do
output_buffer.should_not have_tag('label.label')
output_buffer.should have_tag('form li label', :count => 1)
output_buffer.should have_tag('form li label[@for="post_allow_comments"]')
output_buffer.should have_tag('form li label', /Allow comments/)
output_buffer.should have_tag('form li label input[@type="checkbox"]', :count => 1)
output_buffer.should have_tag('form li input[@type="hidden"]', :count => 1)
output_buffer.should_not have_tag('form li label input[@type="hidden"]', :count => 1) # invalid HTML5
end
这当然有效,但对我来说,这是一个地狱的大量重复!在我看来,像这样的事情更可取:
it 'should generate a label containing the input' do
output_buffer.should_not have_tag('label.label')
output_buffer.should have_tag('form', :count => 1) do |form|
form.should have_tag('li') do |li|
li.should have_tag('label') do |label|
label.should have_content(/Allow comments/)
label.should have_tag('input[@type="checkbox"]', :count => 1)
label.should_not have_tag('input[@type="hidden"]', :count => 1) # invalid HTML5
end
li.should have_tag('input[@type="hidden"]', :count => 1)
end
end
end
我在想什么事吗?经验是否表明,第一种方法更务实?至少,我的会更有效,我想。。。?对此有何看法?在我的问题中添加了更新部分。
it 'should generate a label containing the input' do
output_buffer.should_not have_tag('label.label')
output_buffer.should have_tag('form li label', :count => 1)
output_buffer.should have_tag('form li label[@for="post_allow_comments"]')
output_buffer.should have_tag('form li label', /Allow comments/)
output_buffer.should have_tag('form li label input[@type="checkbox"]', :count => 1)
output_buffer.should have_tag('form li input[@type="hidden"]', :count => 1)
output_buffer.should_not have_tag('form li label input[@type="hidden"]', :count => 1) # invalid HTML5
end
it 'should generate a label containing the input' do
output_buffer.should_not have_tag('label.label')
output_buffer.should have_tag('form', :count => 1) do |form|
form.should have_tag('li') do |li|
li.should have_tag('label') do |label|
label.should have_content(/Allow comments/)
label.should have_tag('input[@type="checkbox"]', :count => 1)
label.should_not have_tag('input[@type="hidden"]', :count => 1) # invalid HTML5
end
li.should have_tag('input[@type="hidden"]', :count => 1)
end
end
end