Skip to content

Commit

Permalink
Improve assert_repl_result for CDP
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
st0012 authored and ko1 committed Apr 21, 2023
1 parent ce7e342 commit 8290437
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
3 changes: 2 additions & 1 deletion test/protocol/eval_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ class EvalTest < ProtocolTestCase
6| f = 6
RUBY

def test_eval_evaluates_arithmetic_expressions
def test_eval_evaluates_expressions
run_protocol_scenario PROGRAM do
req_add_breakpoint 5
req_continue
assert_repl_result({value: '2', type: 'Integer'}, 'a')
assert_repl_result({value: '4', type: 'Integer'}, 'd')
assert_repl_result({value: '3', type: 'Integer'}, '1+2')
assert_repl_result({value: 'false', type: 'FalseClass'}, 'a == 1')
req_terminate_debuggee
end
end
Expand Down
10 changes: 5 additions & 5 deletions test/support/protocol_test_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -475,10 +475,10 @@ def close_reader
HOST = '127.0.0.1'

JAVASCRIPT_TYPE_TO_CLASS_MAPS = {
'string' => String,
'number' => Integer,
'boolean' => [TrueClass, FalseClass],
'symbol' => Symbol
'string' => "String",
'number' => "Integer",
'boolean' => ["TrueClass", "FalseClass"],
'symbol' => "Symbol"
}

def assert_eval_result context, expression, expected, frame_idx
Expand Down Expand Up @@ -517,7 +517,7 @@ def assert_eval_result context, expression, expected, frame_idx

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

cl = res.dig(:result, :result, :className) || JAVASCRIPT_TYPE_TO_CLASS_MAPS[res.dig(:result, :result, :type)].inspect
cl = res.dig(:result, :result, :className) || JAVASCRIPT_TYPE_TO_CLASS_MAPS[res.dig(:result, :result, :type)]
result_type = Array cl
assert_include result_type, expected[:type], failure_msg

Expand Down

0 comments on commit 8290437

Please sign in to comment.