Sha256: 5d4aa584184a5c220e10f984aee2145afa5f39a619a58caf3c8156f4138f6043
Contents?: true
Size: 1.45 KB
Versions: 3
Compression:
Stored size: 1.45 KB
Contents
require_relative '../test_helper' class PollerComponent include Denko::Behaviors::Component include Denko::Behaviors::Poller def _read; end end class PollerTest < Minitest::Test def board @board ||= BoardMock.new end def part @part ||= PollerComponent.new(board: board, pin: 1) end def inject(data, wait_for_callbacks = true) Thread.new do if wait_for_callbacks while (!part.callbacks[:read]) do; sleep 0.01; end end loop do sleep 0.01 part.update(data) break unless part.callbacks[:read] end end end def test_include_callbacks_and_threaded assert_includes PollerComponent.ancestors, Denko::Behaviors::Callbacks assert_includes PollerComponent.ancestors, Denko::Behaviors::Threaded end def test_call_stop_before_polling mock = MiniTest::Mock.new.expect :call, nil part.stub(:stop, mock) { part.poll(1) } mock.verify end def test_uses_threaded_loop mock = MiniTest::Mock.new.expect :call, nil part.stub(:threaded_loop, mock) { part.poll(1) } mock.verify end def test_add_and_remove_callback callback = Proc.new{} part.poll(1, &callback) assert_equal part.callbacks[:poll], [callback] part.stop assert_nil part.callbacks[:poll] end def test_stop_kills_thread mock = MiniTest::Mock.new.expect :call, nil part.stub(:stop_thread, mock) { part.stop } mock.verify end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
denko-0.13.2 | test/behaviors/poller_test.rb |
denko-0.13.1 | test/behaviors/poller_test.rb |
denko-0.13.0 | test/behaviors/poller_test.rb |