Skip to content

Commit

Permalink
Merge pull request #715 from freerange/use-built-in-ruby-debug-option…
Browse files Browse the repository at this point in the history
…-vs-custom-debug-module

Use built-in Ruby debug option vs custom module
  • Loading branch information
floehopper authored Jan 1, 2025
2 parents 69ef41c + 78a5d80 commit 1207992
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 23 deletions.
2 changes: 0 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ jobs:
type: string
docker:
- image: << parameters.docker-image >>
environment:
MOCHA_OPTIONS=debug
steps:
- checkout
- run: ruby --version
Expand Down
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,9 @@ If you want, Mocha can generate a warning or raise an exception when:

See the [documentation](https://mocha.jamesmead.org/Mocha/Configuration.html) for `Mocha::Configuration` for further details.

##### MOCHA_OPTIONS
`MOCHA_OPTIONS` is an environment variable whose value can be set to a comma-separated list, so that we can specify multiple options e.g. `MOCHA_OPTIONS=debug`.
Only the following values are currently recognized and have an effect:
* `debug`: Enables a debug mode which provides extra output to assist with debugging.
### Debugging

Mocha provides some extra output to help with debugging when the standard Ruby debug option (`-d`) is set.

### Semantic versioning

Expand Down
9 changes: 0 additions & 9 deletions lib/mocha/debug.rb

This file was deleted.

5 changes: 2 additions & 3 deletions lib/mocha/integration/minitest.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
require 'mocha/debug'
require 'mocha/detection/minitest'
require 'mocha/integration/minitest/adapter'

Expand All @@ -10,14 +9,14 @@ def self.activate
return false unless target

minitest_version = Gem::Version.new(Detection::Minitest.version)
Debug.puts "Detected Minitest version: #{minitest_version}"
warn "Detected Minitest version: #{minitest_version}" if $DEBUG

unless Minitest::Adapter.applicable_to?(minitest_version)
raise 'Versions of minitest earlier than v3.3.0 are not supported.'
end

unless target < Minitest::Adapter
Debug.puts "Applying #{Minitest::Adapter.description}"
warn "Applying #{Minitest::Adapter.description}" if $DEBUG
target.send(:include, Minitest::Adapter)
end

Expand Down
4 changes: 2 additions & 2 deletions lib/mocha/integration/monkey_patcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ module Integration
module MonkeyPatcher
def self.apply(mod, run_method_patch)
if mod < Mocha::API
Debug.puts "Mocha::API already included in #{mod}"
warn "Mocha::API already included in #{mod}" if $DEBUG
else
mod.send(:include, Mocha::API)
end
if mod.method_defined?(:run_before_mocha)
Debug.puts "#{mod}#run_before_mocha method already defined"
warn "#{mod}#run_before_mocha method already defined" if $DEBUG
elsif mod.method_defined?(:run)
mod.send(:alias_method, :run_before_mocha, :run)
mod.send(:remove_method, :run)
Expand Down
5 changes: 2 additions & 3 deletions lib/mocha/integration/test_unit.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
require 'mocha/debug'
require 'mocha/detection/test_unit'
require 'mocha/integration/test_unit/adapter'

Expand All @@ -10,14 +9,14 @@ def self.activate
return false unless target

test_unit_version = Gem::Version.new(Detection::TestUnit.version)
Debug.puts "Detected Test::Unit version: #{test_unit_version}"
warn "Detected Test::Unit version: #{test_unit_version}" if $DEBUG

unless TestUnit::Adapter.applicable_to?(test_unit_version)
raise 'Versions of test-unit earlier than v2.5.1 are not supported.'
end

unless target < TestUnit::Adapter
Debug.puts "Applying #{TestUnit::Adapter.description}"
warn "Applying #{TestUnit::Adapter.description}" if $DEBUG
target.send(:include, TestUnit::Adapter)
end

Expand Down

0 comments on commit 1207992

Please sign in to comment.