Skip to content

Commit

Permalink
Fix undefined method error after previous change
Browse files Browse the repository at this point in the history
After the previous change, one would get the error `undefined method
`mode' for Byebug:Module` when running a file with `byebug` calls. A
`require` call needed to be moved up.
  • Loading branch information
deivid-rodriguez committed Mar 11, 2019
1 parent 374d30f commit 9948d64
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/byebug/attacher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ module Byebug
# Starts byebug, and stops at the first line of user's code.
#
def self.attach
require "byebug/core"

unless started?
self.mode = :attached

Expand All @@ -35,6 +33,8 @@ def self.spawn(host = "localhost", port = nil)
#
module Kernel
def byebug
require "byebug/core"

Byebug.attach unless Byebug.mode == :off
end

Expand Down
26 changes: 26 additions & 0 deletions test/runner_against_program_with_byebug_call_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# frozen_string_literal: true

require "test_helper"

module Byebug
#
# Tests standalone byebug when debugging a target program
#
class RunnerAgainstProgramWithByebugCallTest < TestCase
def setup
super

example_file.write("require 'byebug'\nbyebug\nsleep 0")
example_file.close
end

def test_run_with_a_script_to_debug
stdout = run_program(
["ruby", example_path],
'puts "Program: #{$PROGRAM_NAME}"'
)

assert_match(/Program: #{example_path}/, stdout)
end
end
end

0 comments on commit 9948d64

Please sign in to comment.