【发布时间】:2012-06-11 19:34:46
【问题描述】:
我开始探索 BDD 和 Cucumber。 所以我想检查我的页面是否显示我拥有的 2 篇文章的内容。 这是我正在使用检查内容是否存在的步骤:
Then /^I should see "([^"]*)"$/ do |desc|
page.should have_content desc
expected = Article.find_by_description(desc)
page.should have_content(expected.navision_code)
page.should have_content(expected.category.name)
end
通常我猜这应该可以解决问题,但是当我运行测试时,我收到了以下错误消息:
expected there to be content "---\n- tenetur\n" in "Alfa Paints Order System\n\n\n\nAlfa Paints\n\n\n\nSeth abernathy, admin\n\n\nVerander paswoord\n\nLogout\n\n\n\n\n\n\n\n\n\n\n\nAlfa Paints\nordering system\n\n\n\n\n\nOverzicht van alle artikelen\n\n\n\nBack\n\n\n\n\n\n\nProduct ID\nBeschrijving\nCategorie\n3001\nPaint\n---\n- tenetur\n\n3002\nBrush\n---\n- tenetur\n\n\n\n\n\n\n\n\n\n\n
(RSpec::Expectations::ExpectationNotMetError)
./features/step_definitions/admin_articles_steps.rb:41:in `/^I should see "([^"]*)"$/'
features/admin_articles.feature:10:in `Then I should see "Paint"'
如您所见,我期望绘制,错误消息显示内容内部有绘制。 但不知何故,黄瓜不认识它。
我是黄瓜新手,我可能遗漏了一些东西,但也许有人可以帮助我。
【问题讨论】:
-
看起来 Capybara 不能很好地使用换行符。你可以尝试用这样的方式去除它们:praktikanten.brueckenschlaeger.org/2011/11/15/…
-
我认为您不需要确定“整个”文章是否存在“成功”测试,也许检查文章中的随机行?
标签: ruby-on-rails selenium cucumber capybara bdd