有人可以解释我为什么不能通过这个测试吗?我只是用 html 内容测试文章视图。在视图中我通过 html_safe 显示内容
.article_content
= @article.content.html_safe
在我的测试中,我有如下内容:
context 'shows actual article' do
before(:all) { @article = FactoryGirl.build(:article, id: 1,
content: '<h2>aaaaa ddd bbb</h2>') }
before(:each) { render }
it 'show content' do
render.should have_selector('div.article_content',text: @article.content.html_safe)
end
之后我的测试失败了:
Failure/Error: render.should have_selector('div.article_content',text: @article.content.html_safe)
Capybara::ExpectationNotMet:
expected to find css "div.article_content" with text "<h2>aaaaa ddd bbb</h2>"
but there were no matches. Also found "\naaaaa ddd bbb\n", which matched the selector but not all filters.
但是当我从工厂对象的内容测试通过中删除 html 标签时。我不知道为什么 html 标签是 '\n'。在浏览器中一切看起来都不错。