[Ruby On Rails] Error in test using RSpec MySQL client is not connected

It is a memorandum.

error contents

OrderForm
Product purchase
When the product purchase goes well
You can purchase if the following 7 items exist → zicide, prefecture_id, city, address, phone_number, user_id, item_id
Can be purchased even if the building name is empty
When product purchase does not go well
Cannot be purchased if the zip code is empty
Cannot be purchased without a hyphen in the zip code
Cannot be purchased if the phone number has a hyphen(FAILED - 1)
You can only purchase if your phone number is within 11 digits(FAILED - 2)

Failures:

  1)OrderForm Product purchase When product purchase is not successful You cannot purchase if there is a hyphen in the phone number
     Failure/Error: _query(sql, @query_options.merge(options))
     
     ActiveRecord::StatementInvalid:
       Mysql2::Error::ConnectionError: Lost connection to MySQL server during query

There is an error in Mysql. Probably, it's possible that you've loaded something later than the data that should be loaded first, causing an error.

approach

require 'rails_helper'
describe OrderForm do
  before do
    @order = FactoryBot.build(:order_form)
    sleep(1)
  end

I decided to do a test process every second so that nothing would be read first. I was able to avoid the error by adding sleep (1) to the test description.

Recommended Posts

[Ruby On Rails] Error in test using RSpec MySQL client is not connected
MySQL client is not connected while testing RSpec
"" Application.js "is not present in the asset pipeline" error in Ruby on Rails
[Ruby on Rails Tutorial] Error in the test in Chapter 3
[Ruby on Rails] View test with RSpec
[Ruby on Rails] Model test with RSpec
[Ruby On Rails] When a model unit test is performed with RSpec using FactoryBot, an error occurs because the foreign key is not entered.
Introducing Rspec, a Ruby on Rails test framework
Rails5 Rspec test error ArgumentError: Factory not registered: user
[Rails] Test code using Rspec
Ruby on Rails Japanese-English support i18n
[Ruby on Rails] What is Bcrypt?
Data is not registered in Rails.
When using Slim in Ruby on Rails, "undefined local variable or method` f'for "is displayed in form_with
[Ruby on Rails] Search function (not selected)
[Ruby on Rails] Code check using Rubocop-airbnb
How to create a query using variables in GraphQL [Using Ruby on Rails]
Ruby on Rails in Visual Studio Codespaces
Notes on using FCM with Ruby on Rails
[Rails] About the error that the image is not displayed in the production environment
[Ruby on Rails] Image slideshow using Skippr
MySQL is not running stably ... Rails app is not running.
[Cloud9] Yay! You ’re on Rails! Is not displayed in the rails tutorial
Beginners create portfolio in Ruby on Rails
[Ruby on Rails] Solving the addiction when setting crontab using whenever in EC2
How to implement image posting function using Active Storage in Ruby on Rails
[Ruby on Rails] How to display error messages
[Ruby on Rails] Until the introduction of RSpec
Introducing Rspec with Ruby on Rails x Docker
Recommendation of Service class in Ruby on Rails
Rails new in Ruby on Rails ~ Memorandum until deployment 1
(Ruby on Rails6) Creating data in a table
[Ruby on Rails] How to install Bootstrap in Rails
[Ruby on Rails] Individual display of error messages
Ruby on Rails Incorrect string value error resolution when posting a form in Japanese
[Ruby on rails] When executing the heroku command, bash: heroku: command not found is displayed. [Rails tutorial]
[Ruby on Rails] I get a warning when running RSpec because gem'chromedriver-helper' is deprecated.
[Ruby on Rails] How to write enum in Japanese
[Rails] Test of star evaluation function using Raty [Rspec]
Rails must be exist error (@save is not executed)
Run Ruby on Rails RSpec tests with GitHub Actions
[Rails / RSpec] Write Model test (using Shoulda Matchers / FactoryBot)
[Ruby On Rails] How to reset DB in Heroku
[Ruby on Rails] Common processing between controllers (using concaves)
[Ruby on Rails] Post image preview function in refile
Ruby on Rails environment construction using VirtualBox, Vagrant, cyberduck
[Error] The app is not displayed in the production environment
[Ruby on Rails] From MySQL construction to database change
Try using the query attribute of Ruby on Rails
What I was interested in in Progate's Ruby on Rails course [Each statement of error message]
[Ruby on Rails] Carousel of bootstrap4 is implemented as a slide show using each method.
Test run on rails
Ruby on Rails Elementary
Ruby on Rails basics
[Rails] Test with RSpec
Ruby On Rails Association
The story when the test folder was not created in Rails
Difficulties in building a Ruby on Rails environment (Windows 10) (SQLite3)
Definitely useful! Debug code for development in Ruby on Rails
Ruby on Rails Email automatic sending function setting (using gmail)
[Ruby on Rails] When parameter id acquisition does not work