我开始探索BDD和黄瓜。 所以我想检查一下我的页面是否显示了我有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"'
正如您所见,我希望绘画和错误消息显示内容中有内容。 但不知何故黄瓜没有认识到它。
我是黄瓜的新手,我可能会错过一些东西,但也许有人可以帮助我。
答案 0 :(得分:0)
您正在同时测试三件事,因此很难说出哪些预期失败了。作为第一步,尝试评论除了第一个期望之外的一切,只是为了确保它在你想到的地方失败。
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
如果您仍然遇到同样的问题,请添加调试器,以便您可以尝试并查看测试环境中发生的情况。如果您计划进行大量的黄瓜测试,这是一项值得开发的技能。
Then /^I should see "([^"]*)"$/ do |desc|
debugger
page.should have_content desc
end
从调试控制台,查看desc变量和页面的样子:
p desc
p page.content