ruby-on-rails – Capybara模棱两可的比赛 – 应该有__内容
发布时间:2020-12-17 03:05:25 所属栏目:百科 来源:网络整理
导读:我在Rails应用程序中使用Capybara和Rspec,并且我一直在使用以下消息测试失败: Failure/Error: it { should have_content('error') }Capybara::Ambiguous: Ambiguous match,found 2 elements matching xpath "/html" 这是合乎逻辑的,因为在我的测试中,我的应
|
我在Rails应用程序中使用Capybara和Rspec,并且我一直在使用以下消息测试失败:
Failure/Error: it { should have_content('error') }
Capybara::Ambiguous:
Ambiguous match,found 2 elements matching xpath "/html"
这是合乎逻辑的,因为在我的测试中,我的应用程序应该呈现带有“错误”内容的两条消息. <% if object.errors.any? %>
<div id="error_explanation">
<div class="alert alert-error">
<%= t('the_form_contains') %>
<%= pluralize(object.errors.count,t('error')) %>.
</div>
<ul>
<% object.errors.full_messages.each do |msg| %>
<li>* <%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
在这里我的应用程序布局: <!DOCTYPE html>
<html>
<head>
<title><%= full_title(yield(:title)) %></title>
<%= stylesheet_link_tag "application",media: "all","data-turbolinks-track" => true %>
<%= javascript_include_tag "application","data-turbolinks-track" => true %>
<%= csrf_meta_tags %>
<%= render 'layouts/shim' %>
</head>
<body>
<%= render 'layouts/header' %>
<div class="container">
<div class="row-fluid">
<div class="offset2 span8 offset2">
<% flash.each do |key,value| %>
<div class="alert alert-<%= key %>"><%= value %></div>
<% end %>
</div>
</div>
<%= yield %>
<%= render 'layouts/footer' %>
<%= debug(params) if Rails.env.development? %>
</div>
</body>
</html>
你知道一种方式(如选项),让它通过吗? 编辑 我使用了save_and_open_page并且没有找到任何额外的html标记,也没有找到页面外的错误消息.但当我删除<!DOCTYPE html>然后它工作.我必须真的有<!DOCTYPE html>和一个开头< html>标签 ?我可以删除<!DOCTYPE html>没有后果? <!DOCTYPE html>
<html>
<head>
<title>Le Troquet</title>
<link data-turbolinks-track="true" href="/assets/application.css" media="all" rel="stylesheet" />
<script data-turbolinks-track="true" src="/assets/application.js"></script>
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body>
.
.
.
.
.
<!-- There is no html tag here -->
.
.
.
.
</body>
</html>
解决方法
看起来问题是你要么:
>有两个< html>您网页中的标签,或者可能是 见这个讨论:Ambiguous match,found 2 elements matching xpath “/html”. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
