私は次のことが通過することを期待していますが、そうではありません:
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
結果:
Failure/Error: without_tag('em')
expected following:
<em><span>Para</span></em>
ブロックがチェックするHTMLはであると思います<span>Para</span>
が、実際はです<em><span>Para</span></em>
。なんで?このように、aに同じタイプtag
の他のものが含まれていないことを確認することは不可能に思えます。tag
specify do
'<div><div>bla</div></div>'.should have_tag('div') do
without_tag('div')
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
私は何か間違ったことを考えていますか?経験は、最初の方法がより実用的であることを示していますか?少なくとも、私の方がパフォーマンスが高いと思いますが...?これについて何か意見はありますか?