Debug gem conflict with rspec mocks

Aperta
#1,154 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
ruby
Ambito
devtools

Direzione di ricerca

Start with lib/debug/source_repository.rb:38 and run the Ruby 3.3.7 reproduction from the issue with debug 1.11.0 and RSpec. Trace how the File.exist? call interacts with the configured mock. Done means the reproduction passes without mock expectation errors while preserving the source repository behavior.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Your environment

  • ruby -v: ruby 3.3.7
  • rdbg -v: 1.11.0

Describe the bug
The debug gem's method in debug/source_repository.rb:38 calls File.exist?, which interferes with RSpec mocks that stub this method for specific file paths. This causes test failures with mock expectation errors when the debug gem is loaded during test execution.

To Reproduce

system('gem install bundler') unless Gem::Specification::find_all_by_name('bundler').any?
require 'bundler/inline'

gemfile(true) do
  source 'https://rubygems.org'
  gem 'rspec'
  gem 'debug', '~> 1.11.0'
end

require 'rspec'
require 'debug'

class MyClass
  def check_if_file_exist?(path)
    File.exist?(path)
  end
end

RSpec.describe "debug gem + File.exist? conflict" do
  let(:target_path) { "config/session_store.yml" }

  let(:my_class) { MyClass.new }

  before do
    allow(File).to receive(:exist?).with(target_path).and_return(true)
  end

  it "stubs File.exist? and avoids debug interference" do
    result = my_class.check_if_file_exist?(target_path)

    expect(result).to be true
  end
end

RSpec::Core::Runner.run([])

Expected behavior
A clear and concise description of what you expected to happen.

  • The test should pass
Lingua principale
Ruby
Stelle
1.3k
Fork
146
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di ruby/debug

Tutte le issue di ruby/debug

Issue simili

Altre issue su Ruby

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.