Capybara :: ExpectationNotMet,链接不合适

时间:2013-12-12 07:35:32

标签: ruby-on-rails ruby-on-rails-3 testing rspec capybara

我已经为我的Rails 3应用程序进行了Rspec / Capybara测试。

其中一项测试开始失败:

it { should have_link(I18n.t('ui.delete'), href: user_path(User.last)) } 

这是一个输出错误:

1) User pages index delete links as an admin user 
 Failure/Error: it { should have_link(I18n.t('ui.delete'), href: user_path(User.last)) }
 Capybara::ExpectationNotMet:
   expected to find link "o'chirish (delete)" but there were no matches. 
Also found   "o'chirish (delete)", "o'chirish (delete)",
"o'chirish (delete)", "o'chirish (delete)", "o'chirish (delete)", "o'chirish (delete)", 
"o'chirish (delete)", "o'chirish (delete)", 
which matched the selector but not all filters.
 # ./spec/requests/user_pages_spec.rb:158:in `block (5 levels) in <top (required)>'

在我的网页上,链接看起来不错(每个 o'chirish(删除)都有删除链接)

1 admin admin admin@gmail.com | admin  
6 author author author@gmail.com | author | o'chirish (delete)  
5 editorxxx editor editor@gmail.com | editor | o'chirish (delete)  
9 home page user1@gmail.com | o'chirish (delete)  
10 taken tekken user22@gmail.com | o'chirish (delete)  
8 tester tester2 tester@gmail.com | o'chirish (delete)  
7 user user user@gmail.com | o'chirish (delete)  

非常感谢您的任何想法!

1 个答案:

答案 0 :(得分:1)

据我记得,我在两种情况下看到了这条消息:链接在那里,但不可见(display:none;)或href不一样。由于您说您可以看到链接,因此应检查href是否设置正确。