I use Capybara and Rspec in a Rails application, and I continue to drop some of my tests with this post:
Failure/Error: it { should have_content('error') } Capybara::Ambiguous: Ambiguous match, found 2 elements matching xpath "/html"
And this is logical, because in my test my application should display two messages with the contents of "error".
<% 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 %>
And here is my application layout:
<!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>
Do you know a way (as an option) for it to go through?
EDIT
I used save_and_open_page and I did not find any additional html tag nor error messages outside the page. But when I delete <!DOCTYPE html> , then it works. Should I have a <!DOCTYPE html> and an opening <html> ? Can I delete <!DOCTYPE html> without consequences?
<!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> </head> <body> . . . . . . . . . </body> </html>
source share