Skip to content

Commit

Permalink
Fix dots test the same way as spinner test
Browse files Browse the repository at this point in the history
  • Loading branch information
abinoam committed Jul 28, 2013
1 parent 79453f9 commit 6e09e49
Showing 1 changed file with 26 additions and 23 deletions.
49 changes: 26 additions & 23 deletions test/test_cursors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,34 +51,37 @@ class TestSpinningCursorCursor < Test::Unit::TestCase
end

context "dots" do
parsed = Parser.new { type :dots; delay 0.2; banner ""}
delay = parsed.delay
should "change 'frames' with correct delay" do
setup do
parsed = Parser.new { type :dots; delay 0.2; banner ""}
@delay = parsed.delay
$cycle_steps = []
$cycle_times = []
capture_stdout do |out|
dots = Thread.new do
SpinningCursor::Cursor.new(parsed).spin
spinner = Thread.new do
test_cursor = SpinningCursor::Cursor.new(parsed)
class << test_cursor
def reset_line(str)
$cycle_steps.push str
$cycle_times.push Time.now
Thread.current.kill if $cycle_times.size == 5
end
end
test_cursor.spin
end
# slight delay to get things started
sleep (delay/4.0)
buffer = "#{ESC_R_AND_CLR}" << "."
assert_equal buffer, out.string

sleep delay
buffer << "#{ESC_R_AND_CLR}" << ".."
assert_equal buffer, out.string

sleep delay
buffer << "#{ESC_R_AND_CLR}" << "..."
assert_equal buffer, out.string
spinner.join
end
end

sleep delay
buffer << "#{ESC_R_AND_CLR}"
assert_equal buffer, out.string
# don't need to go through the whole thing, otherwise test will take
# too long
dots.kill
should "change 'frames' with correct delay" do
$cycle_times.each_cons(2) do |t1, t2|
interval = t2-t1
assert (interval > @delay and interval < (1.5 * @delay))
end
end

should "cycle through correctly" do
assert_equal [".", "..", "...", "", "."], $cycle_steps
end
end

context "spinner" do
Expand Down

0 comments on commit 6e09e49

Please sign in to comment.