繁体   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