debug icon indicating copy to clipboard operation
debug copied to clipboard

Debug gem conflict with rspec mocks

Open imamrb opened this issue 4 months ago • 2 comments

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

imamrb avatar Aug 15 '25 16:08 imamrb

What should I do...?

ko1 avatar Aug 16 '25 03:08 ko1

What should I do...?

Hello, I can not ask you to do something. Just something I was facing and thought of reporting.

imamrb avatar Aug 16 '25 12:08 imamrb