Skip to content

Commit

Permalink
Rename assertion retrying method
Browse files Browse the repository at this point in the history
  • Loading branch information
tompng committed Sep 16, 2024
1 parent cc5b578 commit 7a74aee
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions lib/yamatanooroti/vterm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def result
result
end

private def assert_screen_with_proc(check_proc, assert_block, convert_proc = :itself.to_proc)
private def retryable_screen_assertion_with_proc(check_proc, assert_proc, convert_proc = :itself.to_proc)
retry_until = Time.now + @timeout
while Time.now < retry_until
break unless try_sync
Expand All @@ -137,27 +137,27 @@ def result
break if check_proc.call(convert_proc.call(@result))
end
@result ||= retrieve_screen
assert_block.call(convert_proc.call(@result))
assert_proc.call(convert_proc.call(@result))
end

def assert_screen(expected_lines, message = nil)
lines_to_string = ->(lines) { lines.join("\n").sub(/\n*\z/, "\n") }
case expected_lines
when Array
assert_screen_with_proc(
->(a) { expected_lines == a },
->(a) { assert_equal(expected_lines, a, message) }
retryable_screen_assertion_with_proc(
->(actual) { expected_lines == actual },
->(actual) { assert_equal(expected_lines, actual, message) }
)
when String
assert_screen_with_proc(
->(a) { expected_lines == a },
->(a) { assert_equal(expected_lines, a, message) },
retryable_screen_assertion_with_proc(
->(actual) { expected_lines == actual },
->(actual) { assert_equal(expected_lines, actual, message) },
lines_to_string
)
when Regexp
assert_screen_with_proc(
->(a) { expected_lines.match?(a) },
->(a) { assert_match(expected_lines, a, message) },
retryable_screen_assertion_with_proc(
->(actual) { expected_lines.match?(actual) },
->(actual) { assert_match(expected_lines, actual, message) },
lines_to_string
)
end
Expand Down

0 comments on commit 7a74aee

Please sign in to comment.