├── .autotest ├── History.txt ├── Manifest.txt ├── README.txt ├── Rakefile ├── example.rb └── lib └── minitest └── debugger.rb /.autotest: -------------------------------------------------------------------------------- 1 | # -*- ruby -*- 2 | 3 | require "autotest/restart" 4 | 5 | Autotest.add_hook :initialize do |at| 6 | at.testlib = "minitest/autorun" 7 | at.add_exception "tmp" 8 | 9 | # at.extra_files << "../some/external/dependency.rb" 10 | # 11 | # at.libs << ":../some/external" 12 | # 13 | # at.add_exception "vendor" 14 | # 15 | # at.add_mapping(/dependency.rb/) do |f, _| 16 | # at.files_matching(/test_.*rb$/) 17 | # end 18 | # 19 | # %w(TestA TestB).each do |klass| 20 | # at.extra_class_map[klass] = "test/test_misc.rb" 21 | # end 22 | end 23 | 24 | # Autotest.add_hook :run_command do |at| 25 | # system "rake build" 26 | # end 27 | -------------------------------------------------------------------------------- /History.txt: -------------------------------------------------------------------------------- 1 | === 1.1.0 / 2023-11-07 2 | 3 | * 2 minor enhancements: 4 | 5 | * Declare dependency on debug v1.7+ 6 | * Fix minitest-debug to work with modern debug gem. 7 | 8 | === 1.0.3 / 2015-01-09 9 | 10 | * 1 bug fix: 11 | 12 | * Removed dead rubyforge setting in Rakefile 13 | 14 | === 1.0.2 / 2013-05-29 15 | 16 | * 1 minor enhancement: 17 | 18 | * Switched to minitest 5! 19 | 20 | === 1.0.1 / 2013-04-22 21 | 22 | * 1 bug fix: 23 | 24 | * Fixed minitest dependency to the 4.x family 25 | 26 | === 1.0.0 / 2011-11-07 27 | 28 | * 1 major enhancement 29 | 30 | * Birthday! 31 | -------------------------------------------------------------------------------- /Manifest.txt: -------------------------------------------------------------------------------- 1 | .autotest 2 | History.txt 3 | Manifest.txt 4 | README.txt 5 | Rakefile 6 | example.rb 7 | lib/minitest/debugger.rb 8 | -------------------------------------------------------------------------------- /README.txt: -------------------------------------------------------------------------------- 1 | = minitest-debugger 2 | 3 | home :: https://github.com/seattlerb/minitest-debugger 4 | rdoc :: http://docs.seattlerb.org/minitest-debugger 5 | 6 | == DESCRIPTION: 7 | 8 | This is a stupid simple example of how easy it is to make a minitest 9 | plugin that does something useful. In this case it wraps assert so 10 | that failed assertions will drop into the ruby debugger. 11 | 12 | == FEATURES/PROBLEMS: 13 | 14 | * Failed assertions drop into the debugger. 15 | * Unhandled exceptions already drop into the debugger. 16 | 17 | == SYNOPSIS: 18 | 19 | Add this to the top of your test file or helper: 20 | 21 | require 'minitest/debugger' if ENV['DEBUG'] 22 | 23 | Then run your tests as normal but define DEBUG=1: 24 | 25 | % DEBUG=1 rake test 26 | Debug.rb 27 | Emacs support available. 28 | 29 | Run options: --seed 27343 30 | 31 | # Running tests: 32 | 33 | .Assertion Failed. Dropping into debugger now: 34 | ./lib/minitest/debugger.rb:40: 35 | (rdb:1) up 2 36 | #3 example.rb:18:in `test_assert_failure' 37 | (rdb:1) l 38 | [13, 22] in example.rb 39 | 13 def wrong 40 | 14 24 41 | 15 end 42 | 16 43 | 17 def test_assert_failure 44 | => 18 assert_equal 42, wrong 45 | 19 end 46 | 20 47 | 21 def bad 48 | 22 raise "no" 49 | 50 | == REQUIREMENTS: 51 | 52 | * minitest... you probably already have it 53 | 54 | == INSTALL: 55 | 56 | * sudo gem install minitest-debugger 57 | 58 | == LICENSE: 59 | 60 | (The MIT License) 61 | 62 | Copyright (c) Ryan Davis, seattle.rb 63 | 64 | Permission is hereby granted, free of charge, to any person obtaining 65 | a copy of this software and associated documentation files (the 66 | 'Software'), to deal in the Software without restriction, including 67 | without limitation the rights to use, copy, modify, merge, publish, 68 | distribute, sublicense, and/or sell copies of the Software, and to 69 | permit persons to whom the Software is furnished to do so, subject to 70 | the following conditions: 71 | 72 | The above copyright notice and this permission notice shall be 73 | included in all copies or substantial portions of the Software. 74 | 75 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, 76 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 77 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 78 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 79 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 80 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 81 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 82 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | # -*- ruby -*- 2 | 3 | require "rubygems" 4 | require "hoe" 5 | 6 | Hoe.plugin :isolate 7 | Hoe.plugin :seattlerb 8 | 9 | Hoe.spec "minitest-debugger" do 10 | developer "Ryan Davis", "ryand-ruby@zenspider.com" 11 | 12 | license "MIT" 13 | 14 | dependency "minitest", "~> 5.0" 15 | dependency "debug", "~> 1.7" 16 | end 17 | 18 | # vim: syntax=ruby 19 | -------------------------------------------------------------------------------- /example.rb: -------------------------------------------------------------------------------- 1 | require 'minitest/debugger' if ENV["MTDB"] 2 | require 'minitest/autorun' 3 | 4 | class TestMiniTestUnitTestCase < Minitest::Test 5 | def good 6 | 42 7 | end 8 | 9 | def test_assert 10 | assert_equal 42, good 11 | end 12 | 13 | def wrong 14 | 24 15 | end 16 | 17 | def test_assert_failure 18 | assert_equal 42, wrong 19 | end 20 | 21 | def bad 22 | raise "no" 23 | end 24 | 25 | def test_assert_error 26 | assert_equal 42, bad 27 | end 28 | end 29 | -------------------------------------------------------------------------------- /lib/minitest/debugger.rb: -------------------------------------------------------------------------------- 1 | alias set_trace_funk set_trace_func 2 | 3 | def set_trace_func(*args) 4 | # DEBUGGER__::Context.send :attr_writer, :stop_next 5 | DEBUGGER__::Context.send :attr_writer, :finish_pos 6 | DEBUGGER__.context.finish_pos = -1 7 | DEBUGGER__.context.stop_next(-1) 8 | set_trace_funk(*args) 9 | end 10 | 11 | SCRIPT_LINES__ = {} unless defined? SCRIPT_LINES__ 12 | 13 | # this is unbelievably stupid. 14 | path = caller_locations.find { |s| s.path !~ /require/ }&.absolute_path 15 | SCRIPT_LINES__[path] = File.readlines(path) if path 16 | SCRIPT_LINES__[__FILE__] = File.readlines(__FILE__) 17 | 18 | require 'debug' 19 | require "minitest" 20 | require "minitest/test" 21 | 22 | ## 23 | # This is a stupid simple example of how easy it is to make a minitest 24 | # plugin that does something useful. In this case it wraps assert so 25 | # that failed assertions will drop into the ruby debugger. 26 | 27 | module Minitest::Debugger 28 | VERSION = "1.1.0" 29 | 30 | def assert test, msg = nil 31 | begin 32 | super 33 | rescue Minitest::Assertion => e 34 | warn "Assertion Failed. Dropping into debugger now:" 35 | DEBUGGER__.start 36 | raise e 37 | end 38 | end 39 | end 40 | 41 | class Minitest::Test 42 | include Minitest::Debugger 43 | end 44 | --------------------------------------------------------------------------------