簡體   English   中英

為什么我在運行 rails 測試時點擊 binding.pry 或 byebug 后無法輸入終端?

[英]Why can't I type in terminal after hitting binding.pry or byebug when running rails test?

在為我的 Rails 應用程序運行測試套件時,每當我點擊binding.prybyebug時,我的終端就會損壞——回顯到終端的不是我輸入的內容,也是讓事情恢復正常的唯一方法就是中斷進程並運行reset

任何想法可能是什么問題? 我不知道從哪里開始。

這是我的 Gemfile:

 source 'https://rubygems.org' git_source(:github) { |repo| "https://github.com/#{repo}.git" } gem 'rails', '6.0.2.1' gem 'puma', '3.12.2' gem 'sass-rails', '5.1.0' gem 'webpacker', '4.0.7' gem 'turbolinks', '5.2.0' gem 'jbuilder', '2.9.1' gem 'bootsnap', '1.4.5', require: false gem 'bootstrap-sass', '3.4.1' gem 'pry' gem 'pry-rails' gem 'bcrypt', '3.1.13' group:development, :test do gem 'sqlite3', '1.4.1' gem 'byebug', '11.0.1', platforms: [:mri, :mingw, :x64_mingw] end group:development do gem 'web-console', '4.0.1' gem 'listen', '3.1.5' gem 'spring', '2.1.0' gem 'spring-watcher-listen', '2.0.1' end group:test do gem 'capybara', '3.28.0' gem 'selenium-webdriver', '3.142.4' gem 'webdrivers', '4.1.2' gem 'rails-controller-testing', '1.0.4' gem 'minitest', '5.11.3' gem 'minitest-reporters', '1.3.8' gem 'guard', '2.15.0' gem 'guard-minitest', '2.4.6' end group:production do gem 'pg', '1.1.4' end # Windows does not include zoneinfo files, so bundle the tzinfo-data gem gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] # source 'https://rubygems.org' # git_source(:github) { |repo| "https://github.com/#{repo}.git" } # ruby '2.7.1' # # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' # gem 'rails', '~> 6.0.3', '>= 6.0.3.2' # # Use sqlite3 as the database for Active Record # gem 'sqlite3', '~> 1.4' # # Use Puma as the app server # gem 'puma', '~> 4.1' # # Use SCSS for stylesheets # gem 'sass-rails', '>= 6' # # Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker # gem 'webpacker', '~> 4.0' # # Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks # gem 'turbolinks', '~> 5' # # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder # gem 'jbuilder', '~> 2.7' # # Use Redis adapter to run Action Cable in production # # gem 'redis', '~> 4.0' # # Use Active Model has_secure_password # # gem 'bcrypt', '~> 3.1.7' # # Use Active Storage variant # # gem 'image_processing', '~> 1.2' # # Reduces boot times through caching; required in config/boot.rb # gem 'bootsnap', '>= 1.4.2', require: false # group:development, :test do # # Call 'byebug' anywhere in the code to stop execution and get a debugger console # gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] # end # group:development do # # Access an interactive console on exception pages or by calling 'console' anywhere in the code. # gem 'web-console', '>= 3.3.0' # gem 'listen', '~> 3.2' # # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring # gem 'spring' # gem 'spring-watcher-listen', '~> 2.0.0' # end # group:test do # # Adds support for Capybara system testing and selenium driver # gem 'capybara', '>= 2.15' # gem 'selenium-webdriver' # # Easy installation and use of web drivers to run system tests with browsers # gem 'webdrivers' # end # # Windows does not include zoneinfo files, so bundle the tzinfo-data gem # gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

我遇到了一個非常相似的問題; 我的終端 output 不一致,重復,遇到斷點時無法輸入。

TLDR:Rails 6 添加(默認)並行測試。 這些似乎在不同的工作進程中同時觸發 byebug 斷點。 要修復,請禁用並行測試。

這似乎是一個已知問題 為了解決這個問題,我只是在test_helper.rb中注釋掉了啟用並行運行測試的指示行:

# test/test_helper.rb
class ActiveSupport::TestCase
  # ...
  # comment out this line: 
  # parallelize(workers: :number_of_processors)

  # ...
end

筆記

  • 我注意到這個問題與並行測試有關,因為當斷點觸發時,我看到我的斷點和周圍的代碼重復了 4 次(提示(byebug)也重復了 3 次: 在此處輸入圖像描述

  • 這直到我更新到 Rails 6.1 才開始。 由於某種原因,我在 Rails 6.0 中沒有遇到這個問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM