いくつかの HTML スニペット (ajax 呼び出しとして使用される) を提供するコントローラーの場合、次のようなビュー仕様があります。
it "should not contain html element" do
render
rendered.should have_selector('div')
rendered.should_not have_selector('html')
end
私たちの ajax コンテンツ ローダーでは完全な html ページをレンダリングできないため、結果に html タグが含まれていないことを確認したいと思います。
今のところ、結果rendered
は単純な div タグです。
puts rendered
につながる
"<div>Some text</div>"
ただし、テストは失敗します。
Failure/Error: rendered.should_not have_selector('html')
Capybara::ExpectationNotMet:
expected not to find css "html", found 1 match: "Some text"
私もそれを試しました
rendered.should_not have_xpath('//html')
rendered.should_not have_css('html')
rendered.should have_no_xpath('//html')
rendered.should have_no_css('html')
しかし、結果は同じままです。
内のhtml
テキストの一致をチェックするのはなぜですか? のテストでも同じ結果につながります。div
body