skip to Main Content

When running the test suite for my Rails application, whenever I hit a binding.pry or byebug, my terminal gets corrupted– what gets echoed to the terminal isn’t what I’m typing and the only way to get things back to normal is to interrupt the process and run reset

Any ideas what the issue could be? I’m not sure where to start.

Here’s my 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]

2

Answers


  1. I’m experiencing a very similar problem; my terminal output is inconsistent, repeated, and I can’t type when I hit a breakpoint.

    TLDR: Rails 6 added (by default) parallelized tests. These seem to trigger byebug breakpoints simultaneously in different worker processes. To fix, disable parallel tests.

    This seems to be a known issue.
    To fix, I simply commented out the indicated line in test_helper.rb that enables running tests in parallel:

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

    Notes

    • I noticed that the issue was connected to parallel testing since when the breakpoint triggered I saw my breakpoint and the surrounding code repeated 4 times (with the prompt (byebug) repeated three times, too:
      enter image description here

    • This didn’t start until I updated to Rails 6.1. I wasn’t having this issue with Rails 6.0 for some reason.

    Login or Signup to reply.
  2. I encountered the same issue using pry on github.com/rails/rails which does not have a test/test_helper.rb as referenced in Matt’s response.

    The issue was resolved by:

    • Run tests in serial by setting PARALLEL_WORKERS=1. Example
    • Run a single test with -n test_long_test_name. Example
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search