Skip to content

Commit

Permalink
Merge pull request ruby#5 from hasumikin/add_message_to_assert_screen
Browse files Browse the repository at this point in the history
Add "message" to assert_screen
  • Loading branch information
st0012 authored Oct 27, 2023
2 parents 9eb1577 + f268f44 commit 8539bee
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
6 changes: 3 additions & 3 deletions lib/yamatanooroti/vterm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,13 @@ def result
@result
end

def assert_screen(expected_lines)
def assert_screen(expected_lines, message = nil)
actual_lines = result
case expected_lines
when Array
assert_equal(expected_lines, actual_lines)
assert_equal(expected_lines, actual_lines, message)
when String
assert_equal(expected_lines, actual_lines.join("\n").sub(/\n*\z/, "\n"))
assert_equal(expected_lines, actual_lines.join("\n").sub(/\n*\z/, "\n"), message)
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions lib/yamatanooroti/windows.rb
Original file line number Diff line number Diff line change
Expand Up @@ -519,12 +519,12 @@ def result
@result
end

def assert_screen(expected_lines)
def assert_screen(expected_lines, message = nil)
case expected_lines
when Array
assert_equal(expected_lines, @result)
assert_equal(expected_lines, @result, message)
when String
assert_equal(expected_lines, @result.join("\n").sub(/\n*\z/, "\n"))
assert_equal(expected_lines, @result.join("\n").sub(/\n*\z/, "\n"), message)
end
end

Expand Down
10 changes: 10 additions & 0 deletions test/yamatanooroti/test_run_ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ def test_meta_key
get_out_from_tmpdir
end

def test_assert_screen_takes_a_message_when_failed
start_terminal(5, 30, ['ruby', '-e', 'puts "aaa"'])
close
assert_raise_with_message Test::Unit::AssertionFailedError, /\Amessage when failed/ do
assert_screen(<<~EOC, 'message when failed')
bbb
EOC
end
end

private

def get_into_tmpdir
Expand Down

0 comments on commit 8539bee

Please sign in to comment.