How to resolve errors that occur in the "Ruby on Rails" integration test

Introduction

In integration testing, previously working code was throwing an error. The cause was unexpected, so I decided to leave it as an article (although it is not a memorandum)

error contents

Terminal


Failures:

  1)user Before user registration Can you enter member information?
     Failure/Error: expect(page).to have_content("Enter delivery address information")

     Capybara::Ambiguous:
       Ambiguous match, found 2 elements matching visible xpath "/html"
     # ./spec/features/user_spec.rb:20:in `block (3 levels) in <top (required)>'

  2)user Cannot log in before user registration
     Failure/Error: expect(page).to have_content("Click here if you do not have an account")

     Capybara::Ambiguous:
       Ambiguous match, found 2 elements matching visible xpath "/html"
     # ./spec/features/user_spec.rb:29:in `block (3 levels) in <top (required)>'

  3)user Before user registration Press the product listing button to move to the login page.
     Failure/Error: expect(page).to have_content("Click here if you do not have an account")

     Capybara::Ambiguous:
       Ambiguous match, found 2 elements matching visible xpath "/html"
     # ./spec/features/user_spec.rb:35:in `block (3 levels) in <top (required)>'

  4)user My page is displayed in the header if you can log in after registering as a user
     Failure/Error: expect(page).to have_content "My page"

     Capybara::Ambiguous:
       Ambiguous match, found 2 elements matching visible xpath "/html"
     # ./spec/features/user_spec.rb:50:in `block (3 levels) in <top (required)>'

  5)user You can log out after registering as a user
     Failure/Error: expect(page).to have_content "New member registration"

     Capybara::Ambiguous:
       Ambiguous match, found 2 elements matching visible xpath "/html"
     # ./spec/features/user_spec.rb:56:in `block (3 levels) in <top (required)>'

  6)user If you press the product listing button after user registration, you will be taken to the listing page.
     Failure/Error: expect(page).to have_content("Exhibition image")

     Capybara::Ambiguous:
       Ambiguous match, found 2 elements matching visible xpath "/html"
     # ./spec/features/user_spec.rb:61:in `block (3 levels) in <top (required)>'

  7) Item#create can not save image(image)If you do not have, you cannot register
     Failure/Error: expect(item.errors[:images]).to include("Please enter")
       expected [] to include "Please enter"
     # ./spec/models/item_spec.rb:33:in `block (4 levels) in <top (required)>'

solution

before

haml:application.html.haml


!!!
%html
%head
%meta{content: "text/html; charset=UTF-8", "http-equiv": "Content-Type"}/
%title FreemarketSample68d
%script{src: "https://js.pay.jp/", type: "text/javascript"}
%meta{:content => "summary_large_image", :name => "twitter:card"}/
%meta{:content => "@yGZqMc5IqNbVsw0", :name => "twitter:site"}/
%meta{:content => "http://52.198.247.0/", :property => "og:url"}/
%meta{:content => "freemarket_sample", :property => "og:title"}/
%meta{:content => "This is a sample for team development! Please take a look!", :property => "og:description"}/
%meta{:content => "logo-white.png ", :property => "og:image"}/
= favicon_link_tag 'favicon.ico'
= csrf_meta_tags
= csp_meta_tag
= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track': 'reload'
= javascript_include_tag 'application', 'data-turbolinks-track': 'reload'
  %body
  = yield

after

haml:application.html.haml


!!!
%html
  %head
    %meta{content: "text/html; charset=UTF-8", "http-equiv": "Content-Type"}/
    %title FreemarketSample68d
    %script{src: "https://js.pay.jp/", type: "text/javascript"}
    %meta{:content => "summary_large_image", :name => "twitter:card"}/
    %meta{:content => "@yGZqMc5IqNbVsw0", :name => "twitter:site"}/
    %meta{:content => "http://52.198.247.0/", :property => "og:url"}/
    %meta{:content => "freemarket_sample", :property => "og:title"}/
    %meta{:content => "This is a sample for team development! Please take a look!", :property => "og:description"}/
    %meta{:content => "logo-white.png ", :property => "og:image"}/
    = favicon_link_tag 'favicon.ico'
    = csrf_meta_tags
    = csp_meta_tag
    = stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track': 'reload'
    = javascript_include_tag 'application', 'data-turbolinks-track': 'reload'
  %body
    = yield

Summary

Even in the before state, an error did not occur as an application, but an error occurred in the integration test.

The reason seems to be that there is no default nesting in application.html.haml. If you don't nest meta tags or favicon, you will get an error in other places, so be careful!

Recommended Posts

How to resolve errors that occur in the "Ruby on Rails" integration test
[Ruby on Rails] How to install Bootstrap in Rails
How to debug the processing in the Ruby on Rails model only on the console
[Ruby on Rails] How to write enum in Japanese
[Ruby on Rails Tutorial] Error in the test in Chapter 3
[Ruby On Rails] How to reset DB in Heroku
How to use Ruby on Rails
How to display a graph in Ruby on Rails (LazyHighChart)
[Ruby on Rails] How to use CarrierWave
How to resolve errors when installing Rails 5.1.3
[Ruby on Rails] How to use redirect_to
[Ruby on Rails] How to use kaminari
Things to remember and concepts in the Ruby on Rails tutorial
How to create a query using variables in GraphQL [Using Ruby on Rails]
How to implement gem "summer note" in wysiwyg editor in Ruby on Rails
How to solve the local environment construction of Ruby on Rails (MAC)!
[Ruby On Rails] How to search the contents of params using include?
[Ruby] How to prevent errors when nil is included in the operation
[Ruby on Rails] How to display error messages
How to add / remove Ruby on Rails columns
How to use "sign_in" in integration test (RSpec)
How to build the simplest blockchain in Ruby
[Ruby on Rails] How to use session method
How to check Rails commands in the terminal
[Ruby on Rails] How to log in with only your name and password using the gem devise
[Ruby on Rails] When logging in for the first time ・ How to split the screen in half using jQuery
[Ruby on Rails] How to make the link destination part of the specified id
[Ruby on Rails] Rails tutorial Chapter 14 Summary of how to implement the status feed
How to implement image posting function using Active Storage in Ruby on Rails
[Ruby on Rails] How to Japaneseize the error message of Form object (ActiveModel)
How to set the display time to Japan time in Rails
(Ruby on Rails6) How to create models and tables
[Rails] How to display an image in the view
How to resolve SSL_connect error in PayPal Ruby SDK
[Ruby On Rails] Description that allows only specific users to transition to the edit page
[Ruby On Rails] How to use simple_format to display the entered text with line breaks
[Ruby] 5 errors that tend to occur when scraping with Selenium and how to deal with them
[Ruby on Rails] Quickly display the page title in the browser
Solution for errors that occur when upgrading to Rails 5.2 series
(Ruby on Rails6) Display of the database that got the id of the database
How to retrieve the hash value in an array in Ruby
[Note] About the Fizz_Buzz problem (How Ruby on Rails works)
How to switch Java in the OpenJDK era on Mac
How to run React and Rails on the same server
Apply CSS to a specific View in Ruby on Rails
[Rails] How to display information stored in the database in view
Ruby on Rails 5 quick learning practice guide that can be used in the field Summary
[Ruby On Rails] How to search and save the data of the parent table from the child table
[Ruby on Rails] I want to get the URL of the image saved in Active Storage
[Ruby On Rails] How to update the calculated result to an integer type column using update_column
How to deploy jQuery on Rails
How to iterate infinitely in Ruby
How to deploy Bootstrap on Rails
Ruby on Rails Japanese-English support i18n
How to install Bootstrap in Ruby
Rails on Tiles (how to write)
How to resolve Mixed Content errors
[Technical memo] How to resolve errors
How to introduce jQuery in Rails 6
How to install Swiper in Rails
[Rails / Routing] How to refer to the controller in the directory you created