File tree Expand file tree Collapse file tree 2 files changed +34
-8
lines changed
Expand file tree Collapse file tree 2 files changed +34
-8
lines changed Original file line number Diff line number Diff line change @@ -346,7 +346,10 @@ def watch_eval
346346 begin
347347 @prev = @current
348348 @current = result
349- suspend
349+
350+ if @cond . nil? || @object . instance_eval ( @cond )
351+ suspend
352+ end
350353 ensure
351354 remove_instance_variable ( :@prev )
352355 end
@@ -359,7 +362,6 @@ def setup
359362 @tp = TracePoint . new ( :line , :return , :b_return ) { |tp |
360363 next if tp . path . start_with? __dir__
361364 next if tp . path . start_with? '<internal:'
362- next if !safe_eval ( tp . binding , @cond ) if @cond
363365
364366 watch_eval
365367 }
Original file line number Diff line number Diff line change @@ -72,12 +72,36 @@ def test_watch_works_with_command
7272 end
7373 end
7474
75- def test_watch_works_with_condition
76- debug_code ( program ) do
77- type 'continue'
78- type 'watch @name if: 1 == 2'
79- type 'continue'
80- assert_finish
75+ class ConditionTest < TestCase
76+ def program
77+ <<~RUBY
78+ 1| class Student
79+ 2| attr_accessor :name, :age
80+ 3|
81+ 4| def initialize(name, age)
82+ 5| @name = name
83+ 6| @age = age
84+ 7| binding.b(do: "watch @age if: name == 'Sean'")
85+ 8| end
86+ 9| end
87+ 10|
88+ 11| stan = Student.new("Stan", 30)
89+ 12| stan.age += 1
90+ 13| # only stops for Sean's age change
91+ 14| sean = Student.new("Sean", 25)
92+ 15| sean.age += 1
93+ 16|
94+ 17| a = 1 # additional line for line tp
95+ RUBY
96+ end
97+
98+ def test_condition_is_evaluated_in_the_watched_object
99+ debug_code ( program ) do
100+ type 'continue'
101+ assert_line_text ( /Stop by #\d BP - Watch #<Student:.*> @age = 25 -> 26/ )
102+ type 'continue'
103+ assert_finish
104+ end
81105 end
82106 end
83107 end
You can’t perform that action at this time.
0 commit comments