pry-byebug 1.2.1 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: eba2846fe4080bb11d92caad167546fad2f72fad
4
- data.tar.gz: bbb99275dfe2289e74258051053715e065173810
3
+ metadata.gz: aaed52b59d6393f7ec0b0c0364c4ab345d4d9fbe
4
+ data.tar.gz: d6d0fb953ff4a59b4b2a5fb93a5c117c295a39ed
5
5
  SHA512:
6
- metadata.gz: 96e581e92822c411c12219ae9b19db5d423ef262abe2aad86e3ef5bd6428bf080718ba7f4dd833c2e64fd86a0bc6d8adb758a44e166ed33196145bd99134899e
7
- data.tar.gz: 6013dee785c7affd6006e905e6a46d9849e54b3f1f80d586d5908134235541d7030420ef3abc520b075f9dc7b8efe619726f7d1848d7a4b57f0eecbaa0da1ea8
6
+ metadata.gz: 2dd86e047aa5d2e7ebd5a502825c98adbebfe6b26824a87bfdee6c8cc109ccea2d575554e85194024c062c489f7e7297be7b31e8217b12bad7b29ea02275d9fe
7
+ data.tar.gz: 4987952759065ed3dd4d3891b8cafce89be3c58246a16678a2a04a70365412006f60d7d5ce1ef3dba766a09a8286ffd5d397e06f37bf22c15e05a27337223d04
data/.travis.yml CHANGED
@@ -1,5 +1,6 @@
1
1
  rvm:
2
2
  - 2.0.0
3
+ - 2.1.0
3
4
  - ruby-head
4
5
  matrix:
5
6
  allow_failures:
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 1.3.0 (2014-05-02)
2
+
3
+ * Add breakpoints on method names (thanks @andreychernih & @palkan)
4
+ * Fix "undefined method `interface`" error (huge thanks to @andreychernih)
5
+
6
+
1
7
  ## 1.2.1 (2013-30-12)
2
8
 
3
9
  * Fix for "uncaught throw :breakout_nav" (thanks @lukebergen)
@@ -7,8 +7,48 @@ module PryByebug
7
7
  extend Enumerable
8
8
  extend self
9
9
 
10
- # Add a new breakpoint.
11
- def add(file, line, expression = nil)
10
+ class FileBreakpoint < SimpleDelegator
11
+ def source_code
12
+ Pry::Code.from_file(source).around(pos, 3).with_marker(pos)
13
+ end
14
+
15
+ def to_s
16
+ "#{source} @ #{pos}"
17
+ end
18
+ end
19
+
20
+ class MethodBreakpoint < SimpleDelegator
21
+ def initialize(byebug_bp, method)
22
+ __setobj__ byebug_bp
23
+ @method = method
24
+ end
25
+
26
+ def source_code
27
+ Pry::Code.from_method(Pry::Method.from_str(@method))
28
+ end
29
+
30
+ def to_s
31
+ @method
32
+ end
33
+ end
34
+
35
+ def breakpoints
36
+ @breakpoints ||= []
37
+ end
38
+
39
+ # Add method breakpoint.
40
+ def add_method(method, expression = nil)
41
+ validate_expression expression
42
+ Pry.processor.debugging = true
43
+ owner, name = method.split /[\.#]/
44
+ byebug_bp = Byebug.add_breakpoint(owner, name.to_sym, expression)
45
+ bp = MethodBreakpoint.new byebug_bp, method
46
+ breakpoints << bp
47
+ bp
48
+ end
49
+
50
+ # Add file breakpoint.
51
+ def add_file(file, line, expression = nil)
12
52
  real_file = (file != Pry.eval_path)
13
53
  raise ArgumentError, 'Invalid file!' if real_file && !File.exist?(file)
14
54
  validate_expression expression
@@ -16,7 +56,9 @@ module PryByebug
16
56
  Pry.processor.debugging = true
17
57
 
18
58
  path = (real_file ? File.expand_path(file) : file)
19
- Byebug.add_breakpoint(path, line, expression)
59
+ bp = FileBreakpoint.new Byebug.add_breakpoint(path, line, expression)
60
+ breakpoints << bp
61
+ bp
20
62
  end
21
63
 
22
64
  # Change the conditional expression for a breakpoint.
@@ -30,14 +72,16 @@ module PryByebug
30
72
 
31
73
  # Delete an existing breakpoint with the given ID.
32
74
  def delete(id)
33
- unless Byebug.started? && Byebug.remove_breakpoint(id)
34
- raise ArgumentError, "No breakpoint ##{id}"
35
- end
75
+ deleted = Byebug.started? &&
76
+ Byebug.remove_breakpoint(id) &&
77
+ breakpoints.delete(find_by_id(id))
78
+ raise ArgumentError, "No breakpoint ##{id}" if not deleted
36
79
  Pry.processor.debugging = false if to_a.empty?
37
80
  end
38
81
 
39
82
  # Delete all breakpoints.
40
83
  def clear
84
+ @breakpoints = []
41
85
  Byebug.breakpoints.clear if Byebug.started?
42
86
  Pry.processor.debugging = false
43
87
  end
@@ -60,7 +104,7 @@ module PryByebug
60
104
  end
61
105
 
62
106
  def to_a
63
- Byebug.started? ? Byebug.breakpoints : []
107
+ breakpoints
64
108
  end
65
109
 
66
110
  def size
@@ -152,22 +152,29 @@ module PryByebug
152
152
  place = args.shift
153
153
  condition = args.join(' ') if 'if' == args.shift
154
154
 
155
- file, line =
155
+ bp =
156
156
  case place
157
157
  when /^(\d+)$/ # Line number only
158
158
  line = $1
159
159
  unless PryByebug.check_file_context(target)
160
160
  raise ArgumentError, 'Line number declaration valid only in a file context.'
161
161
  end
162
- [target.eval('__FILE__'), line]
162
+ Breakpoints.add_file(target.eval('__FILE__'), line.to_i, condition)
163
163
  when /^(.+):(\d+)$/ # File and line number
164
- [$1, $2]
165
- else # Method or class name
166
- self.args = [place]
167
- method_object.source_location
164
+ Breakpoints.add_file($1, $2.to_i, condition)
165
+ when /^(.*)[.#].+$/ # Method or class name
166
+ if $1.strip.empty?
167
+ unless PryByebug.check_file_context(target)
168
+ raise ArgumentError, 'Method name declaration valid only in a file context.'
169
+ end
170
+ place = target.eval('self.class.to_s') + place
171
+ end
172
+ Breakpoints.add_method(place,condition)
173
+ else
174
+ raise ArgumentError, 'Cannot identify arguments as breakpoint'
168
175
  end
169
176
 
170
- print_full_breakpoint Breakpoints.add(file, line.to_i, condition)
177
+ print_full_breakpoint bp
171
178
  end
172
179
  end
173
180
  alias_command 'breakpoint', 'break'
@@ -201,7 +208,7 @@ module PryByebug
201
208
  Breakpoints.each do |breakpoint|
202
209
  output.printf "%#{max_width}d ", breakpoint.id
203
210
  output.print breakpoint.enabled? ? 'Yes ' : 'No '
204
- output.print "#{breakpoint.source}:#{breakpoint.pos}"
211
+ output.print breakpoint.to_s
205
212
  output.print " (if #{breakpoint.expr})" if breakpoint.expr
206
213
  output.puts
207
214
  end
@@ -236,17 +243,14 @@ module PryByebug
236
243
  def print_full_breakpoint(breakpoint)
237
244
  line = breakpoint.pos
238
245
  output.print text.bold("Breakpoint #{breakpoint.id}: ")
239
- output.print "#{breakpoint.source} @ line #{line} "
246
+ output.print "#{breakpoint.to_s} "
240
247
  output.print breakpoint.enabled? ? '(Enabled)' : '(Disabled)'
241
248
  output.puts ' :'
242
249
  if (expr = breakpoint.expr)
243
250
  output.puts "#{text.bold('Condition:')} #{expr}"
244
251
  end
245
252
  output.puts
246
- output.puts Pry::Code.from_file(breakpoint.source).
247
- around(line, 3).
248
- with_line_numbers.
249
- with_marker(line).to_s
253
+ output.puts breakpoint.source_code.with_line_numbers.to_s
250
254
  output.puts
251
255
  end
252
256
  end
@@ -2,10 +2,12 @@ require 'pry'
2
2
  require 'byebug'
3
3
 
4
4
  module PryByebug
5
- class Processor
5
+ class Processor < Byebug::Processor
6
6
  attr_accessor :pry
7
7
 
8
- def initialize
8
+ def initialize(interface = Byebug::LocalInterface.new)
9
+ super(interface)
10
+
9
11
  Byebug.handler = self
10
12
  @always_enabled = true
11
13
  @delayed = Hash.new(0)
@@ -1,3 +1,3 @@
1
1
  module PryByebug
2
- VERSION = '1.2.1'
2
+ VERSION = '1.3.0'
3
3
  end
data/pry-byebug.gemspec CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |gem|
21
21
  gem.add_runtime_dependency 'pry', '~> 0.9.12'
22
22
  gem.add_runtime_dependency 'byebug', '~> 2.2'
23
23
 
24
- gem.add_development_dependency 'bundler', '~> 1.3.5'
25
- gem.add_development_dependency 'rake', '~> 10.1.0'
26
- gem.add_development_dependency 'mocha', '~> 0.14.0'
24
+ gem.add_development_dependency 'bundler', '~> 1.5'
25
+ gem.add_development_dependency 'rake', '~> 10.1'
26
+ gem.add_development_dependency 'mocha', '~> 1.0'
27
27
  end
@@ -1,14 +1,34 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class BreakpointsTest < MiniTest::Spec
4
-
5
- def test_add_raises_argument_error
4
+ def test_add_file_raises_argument_error
6
5
  Pry.stubs eval_path: "something"
7
6
  File.stubs :exist?
8
7
  assert_raises(ArgumentError) do
9
- PryByebug::Breakpoints.add("file", 1)
8
+ PryByebug::Breakpoints.add_file("file", 1)
10
9
  end
11
10
  end
12
11
 
13
- end
12
+ class Tester
13
+ def self.class_method; end
14
+ def instance_method; end
15
+ end
14
16
 
17
+ def test_add_method_adds_instance_method_breakpoint
18
+ Pry.stub :processor, PryByebug::Processor.new do
19
+ PryByebug::Breakpoints.add_method 'BreakpointsTest::Tester#instance_method'
20
+ bp = Byebug.breakpoints.last
21
+ assert_equal 'BreakpointsTest::Tester', bp.source
22
+ assert_equal 'instance_method', bp.pos
23
+ end
24
+ end
25
+
26
+ def test_add_method_adds_class_method_breakpoint
27
+ Pry.stub :processor, PryByebug::Processor.new do
28
+ PryByebug::Breakpoints.add_method 'BreakpointsTest::Tester.class_method'
29
+ bp = Byebug.breakpoints.last
30
+ assert_equal 'BreakpointsTest::Tester', bp.source
31
+ assert_equal 'class_method', bp.pos
32
+ end
33
+ end
34
+ end
@@ -5,6 +5,14 @@ class CommandsTest < MiniTest::Spec
5
5
  (Pathname.new(__FILE__) + "../examples/stepping.rb").cleanpath.to_s
6
6
  end
7
7
 
8
+ let(:break_first_file) do
9
+ (Pathname.new(__FILE__) + "../examples/break1.rb").cleanpath.to_s
10
+ end
11
+
12
+ let(:break_second_file) do
13
+ (Pathname.new(__FILE__) + "../examples/break2.rb").cleanpath.to_s
14
+ end
15
+
8
16
  before do
9
17
  Pry.color = false
10
18
  Pry.pager = false
@@ -15,7 +23,7 @@ class CommandsTest < MiniTest::Spec
15
23
  describe 'Step Command' do
16
24
  describe 'single step' do
17
25
  before do
18
- @input = InputTester.new('step')
26
+ @input = InputTester.new 'step'
19
27
  redirect_pry_io(@input, @output) do
20
28
  load step_file
21
29
  end
@@ -28,7 +36,7 @@ class CommandsTest < MiniTest::Spec
28
36
 
29
37
  describe 'multiple step' do
30
38
  before do
31
- @input = InputTester.new('step 2')
39
+ @input = InputTester.new 'step 2'
32
40
  redirect_pry_io(@input, @output) do
33
41
  load step_file
34
42
  end
@@ -43,7 +51,7 @@ class CommandsTest < MiniTest::Spec
43
51
  describe 'Next Command' do
44
52
  describe 'single step' do
45
53
  before do
46
- @input = InputTester.new('next')
54
+ @input = InputTester.new 'next'
47
55
  redirect_pry_io(@input, @output) do
48
56
  load step_file
49
57
  end
@@ -56,7 +64,7 @@ class CommandsTest < MiniTest::Spec
56
64
 
57
65
  describe 'multiple step' do
58
66
  before do
59
- @input = InputTester.new('next 2')
67
+ @input = InputTester.new 'next 2'
60
68
  redirect_pry_io(@input, @output) do
61
69
  load step_file
62
70
  end
@@ -68,5 +76,103 @@ class CommandsTest < MiniTest::Spec
68
76
  end
69
77
  end
70
78
 
79
+ describe 'Set Breakpoints' do
80
+ before do
81
+ @input = InputTester.new 'break --delete-all'
82
+ redirect_pry_io(@input, @output) do
83
+ load break_first_file
84
+ end
85
+ @output = StringIO.new
86
+ end
87
+
88
+ describe 'set by line number' do
89
+ before do
90
+ @input = InputTester.new 'break 3'
91
+ redirect_pry_io(@input, @output) do
92
+ load break_first_file
93
+ end
94
+ end
95
+
96
+ it 'shows breakpoint enabled' do
97
+ @output.string.must_match /^Breakpoint [\d]+: #{break_first_file} @ 3 \(Enabled\)/
98
+ end
99
+
100
+ it 'shows breakpoint hit' do
101
+ @output.string =~ /^Breakpoint ([\d]+): #{break_first_file} @ 3 \(Enabled\)/
102
+ @output.string.must_match Regexp.new("^Breakpoint #{$1}\. First hit")
103
+ end
104
+
105
+ it 'shows breakpoint line' do
106
+ @output.string.must_match /\=> 3:/
107
+ end
108
+ end
109
+
110
+ describe 'set by method_id' do
111
+ before do
112
+ @input = InputTester.new 'break BreakExample#a'
113
+ redirect_pry_io(@input, @output) do
114
+ load break_first_file
115
+ end
116
+ end
117
+
118
+ it 'shows breakpoint enabled' do
119
+ @output.string.must_match /^Breakpoint [\d]+: BreakExample#a \(Enabled\)/
120
+ end
121
+
122
+ it 'shows breakpoint hit' do
123
+ @output.string =~ /^Breakpoint ([\d]+): BreakExample#a \(Enabled\)/
124
+ @output.string.must_match Regexp.new("^Breakpoint #{$1}\. First hit")
125
+ end
126
+
127
+ it 'shows breakpoint line' do
128
+ @output.string.must_match /\=> 4:/
129
+ end
130
+
131
+ describe 'when its a bang method' do
132
+ before do
133
+ @input = InputTester.new 'break BreakExample#c!'
134
+ redirect_pry_io(@input, @output) do
135
+ load break_first_file
136
+ end
137
+ end
138
+
139
+ it 'shows breakpoint enabled' do
140
+ @output.string.must_match /^Breakpoint [\d]+: BreakExample#c! \(Enabled\)/
141
+ end
142
+
143
+ it 'shows breakpoint hit' do
144
+ @output.string =~ /^Breakpoint ([\d]+): BreakExample#c! \(Enabled\)/
145
+ @output.string.must_match Regexp.new("^Breakpoint #{$1}\. First hit")
146
+ end
147
+
148
+ it 'shows breakpoint line' do
149
+ @output.string.must_match /\=> 14:/
150
+ end
151
+ end
152
+ end
153
+
154
+ describe 'set by method_id within context' do
155
+ before do
156
+ @input = InputTester.new 'break #b'
157
+ redirect_pry_io(@input, @output) do
158
+ load break_second_file
159
+ end
160
+ end
161
+
162
+ it 'shows breakpoint enabled' do
163
+ @output.string.must_match /^Breakpoint [\d]+: BreakExample#b \(Enabled\)/
164
+ end
165
+
166
+ it 'shows breakpoint hit' do
167
+ @output.string =~ /^Breakpoint ([\d]+): BreakExample#b \(Enabled\)/
168
+ @output.string.must_match Regexp.new("^Breakpoint #{$1}\. First hit")
169
+ end
170
+
171
+ it 'shows breakpoint line' do
172
+ @output.string.must_match /\=> 8:/
173
+ end
174
+ end
175
+
176
+ end
71
177
  end
72
178
 
@@ -0,0 +1,20 @@
1
+ binding.pry
2
+
3
+ class BreakExample
4
+ def a
5
+ z = 2
6
+ b
7
+ end
8
+
9
+ def b
10
+ v2 = 5 if 1 == 2 ; [1,2,3].map { |a| a.to_f }
11
+ c!
12
+ end
13
+
14
+ def c!
15
+ z = 4
16
+ 5
17
+ end
18
+ end
19
+
20
+ BreakExample.new.a
@@ -0,0 +1,18 @@
1
+ class BreakExample
2
+ def a
3
+ binding.pry
4
+ z = 2
5
+ b
6
+ end
7
+
8
+ def b
9
+ c
10
+ end
11
+
12
+ def c
13
+ z = 4
14
+ 5
15
+ end
16
+ end
17
+
18
+ BreakExample.new.a
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pry-byebug
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Rodríguez
@@ -9,78 +9,78 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-12-30 00:00:00.000000000 Z
12
+ date: 2014-02-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: pry
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - ~>
18
+ - - "~>"
19
19
  - !ruby/object:Gem::Version
20
20
  version: 0.9.12
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - ~>
25
+ - - "~>"
26
26
  - !ruby/object:Gem::Version
27
27
  version: 0.9.12
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: byebug
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - ~>
32
+ - - "~>"
33
33
  - !ruby/object:Gem::Version
34
34
  version: '2.2'
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - ~>
39
+ - - "~>"
40
40
  - !ruby/object:Gem::Version
41
41
  version: '2.2'
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: bundler
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - ~>
46
+ - - "~>"
47
47
  - !ruby/object:Gem::Version
48
- version: 1.3.5
48
+ version: '1.5'
49
49
  type: :development
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
- - - ~>
53
+ - - "~>"
54
54
  - !ruby/object:Gem::Version
55
- version: 1.3.5
55
+ version: '1.5'
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: rake
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
- - - ~>
60
+ - - "~>"
61
61
  - !ruby/object:Gem::Version
62
- version: 10.1.0
62
+ version: '10.1'
63
63
  type: :development
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
- - - ~>
67
+ - - "~>"
68
68
  - !ruby/object:Gem::Version
69
- version: 10.1.0
69
+ version: '10.1'
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: mocha
72
72
  requirement: !ruby/object:Gem::Requirement
73
73
  requirements:
74
- - - ~>
74
+ - - "~>"
75
75
  - !ruby/object:Gem::Version
76
- version: 0.14.0
76
+ version: '1.0'
77
77
  type: :development
78
78
  prerelease: false
79
79
  version_requirements: !ruby/object:Gem::Requirement
80
80
  requirements:
81
- - - ~>
81
+ - - "~>"
82
82
  - !ruby/object:Gem::Version
83
- version: 0.14.0
83
+ version: '1.0'
84
84
  description: |-
85
85
  Combine 'pry' with 'byebug'. Adds 'step', 'next', and
86
86
  'continue' commands to control execution.
@@ -89,8 +89,8 @@ executables: []
89
89
  extensions: []
90
90
  extra_rdoc_files: []
91
91
  files:
92
- - .gitignore
93
- - .travis.yml
92
+ - ".gitignore"
93
+ - ".travis.yml"
94
94
  - CHANGELOG.md
95
95
  - Gemfile
96
96
  - LICENSE
@@ -109,6 +109,8 @@ files:
109
109
  - test/base_test.rb
110
110
  - test/breakpoints_test.rb
111
111
  - test/commands_test.rb
112
+ - test/examples/break1.rb
113
+ - test/examples/break2.rb
112
114
  - test/examples/stepping.rb
113
115
  - test/processor_test.rb
114
116
  - test/pry_ext_test.rb
@@ -124,17 +126,17 @@ require_paths:
124
126
  - lib
125
127
  required_ruby_version: !ruby/object:Gem::Requirement
126
128
  requirements:
127
- - - '>='
129
+ - - ">="
128
130
  - !ruby/object:Gem::Version
129
131
  version: 2.0.0
130
132
  required_rubygems_version: !ruby/object:Gem::Requirement
131
133
  requirements:
132
- - - '>='
134
+ - - ">="
133
135
  - !ruby/object:Gem::Version
134
136
  version: '0'
135
137
  requirements: []
136
138
  rubyforge_project:
137
- rubygems_version: 2.1.11
139
+ rubygems_version: 2.2.1
138
140
  signing_key:
139
141
  specification_version: 4
140
142
  summary: Fast debugging with Pry.
@@ -142,9 +144,10 @@ test_files:
142
144
  - test/base_test.rb
143
145
  - test/breakpoints_test.rb
144
146
  - test/commands_test.rb
147
+ - test/examples/break1.rb
148
+ - test/examples/break2.rb
145
149
  - test/examples/stepping.rb
146
150
  - test/processor_test.rb
147
151
  - test/pry_ext_test.rb
148
152
  - test/pry_remote_ext_test.rb
149
153
  - test/test_helper.rb
150
- has_rdoc: