Skip to content

Commit 8290437

Browse files
st0012ko1
authored andcommitted
Improve assert_repl_result for CDP
The current implementation doesn't work when the result is a boolean type because the helper calls `#inspect` on the values of `JAVASCRIPT_TYPE_TO_CLASS_MAPS`, which is an array for boolean types. Example failure: ``` <["[TrueClass, FalseClass]"]> was expected to include <"FalseClass">. ``` Since `JAVASCRIPT_TYPE_TO_CLASS_MAPS` is never used in other places, we can just store the String representation of the class name in the hash and thus avoid calling `#inspect` on the values.
1 parent ce7e342 commit 8290437

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

test/protocol/eval_test.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@ class EvalTest < ProtocolTestCase
1313
6| f = 6
1414
RUBY
1515

16-
def test_eval_evaluates_arithmetic_expressions
16+
def test_eval_evaluates_expressions
1717
run_protocol_scenario PROGRAM do
1818
req_add_breakpoint 5
1919
req_continue
2020
assert_repl_result({value: '2', type: 'Integer'}, 'a')
2121
assert_repl_result({value: '4', type: 'Integer'}, 'd')
2222
assert_repl_result({value: '3', type: 'Integer'}, '1+2')
23+
assert_repl_result({value: 'false', type: 'FalseClass'}, 'a == 1')
2324
req_terminate_debuggee
2425
end
2526
end

test/support/protocol_test_case.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -475,10 +475,10 @@ def close_reader
475475
HOST = '127.0.0.1'
476476

477477
JAVASCRIPT_TYPE_TO_CLASS_MAPS = {
478-
'string' => String,
479-
'number' => Integer,
480-
'boolean' => [TrueClass, FalseClass],
481-
'symbol' => Symbol
478+
'string' => "String",
479+
'number' => "Integer",
480+
'boolean' => ["TrueClass", "FalseClass"],
481+
'symbol' => "Symbol"
482482
}
483483

484484
def assert_eval_result context, expression, expected, frame_idx
@@ -517,7 +517,7 @@ def assert_eval_result context, expression, expected, frame_idx
517517

518518
failure_msg = FailureMessage.new{create_protocol_message "result:\n#{JSON.pretty_generate res}"}
519519

520-
cl = res.dig(:result, :result, :className) || JAVASCRIPT_TYPE_TO_CLASS_MAPS[res.dig(:result, :result, :type)].inspect
520+
cl = res.dig(:result, :result, :className) || JAVASCRIPT_TYPE_TO_CLASS_MAPS[res.dig(:result, :result, :type)]
521521
result_type = Array cl
522522
assert_include result_type, expected[:type], failure_msg
523523

0 commit comments

Comments
 (0)