2012-06-11 58 views
3

我开始探索BDD和黄瓜。 所以我想检查一下我的页面是否显示了我拥有的两篇文章的内容。 这是我使用的检查步骤;如果内容有:检查黄瓜测试网页的内容

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"' 

正如你所看到的,我期望绘画和错误信息显示内容已经在内部绘制。 但不知何故,黄瓜不认识它。

我是新来的黄瓜,我可能错过了一些东西,但也许有人可以帮我在路上。

+1

它看起来像水豚不换行发挥好。你可以尝试用下面这样的东西来解决它们:http://praktikanten.brueckenschlaeger.org/2011/11/15/working-in-cucumber-with-new-lines-and-have_content – DVG

+0

我不认为你需要确定“整个”文章是否有“成功”的测试,可能是检查文章中的随机线? – omarvelous

回答

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 

从调试控制台,请参阅递减变量和页面的样子:

p desc 
p page.content