Sha256: cdf301f7ba30b6aecfb2a2589a66a2c7cdaf79e4e32f819776ae83b384471c60

Contents?: true

Size: 945 Bytes

Versions: 3

Compression:

Stored size: 945 Bytes

Contents

require_relative '../test_helper'

class AddressedBus
  include Denko::Behaviors::Component
  include Denko::Behaviors::BusControllerAddressed
end

class AddressedPeripheral
  include Denko::Behaviors::Component
  include Denko::Behaviors::BusPeripheralAddressed
end

class BusPeripheralAddressedTest < Minitest::Test
  def board
    @board ||= BoardMock.new
  end

  def bus
    @bus ||= AddressedBus.new(board: board)
  end
  
  def part
    @part ||= AddressedPeripheral.new(bus: bus, address: 0x22)
  end
  
  def test_initialize
    assert_equal part.board, bus
    assert_equal part.address, 0x22
  end
  
  def test_requires_address
    assert_raises(ArgumentError) { AddressedPeripheral.new(bus: bus) }
  end
  
  def test_can_use_bus_atomically   
    mock = MiniTest::Mock.new
    1.times {mock.expect(:call, nil)}
    
    bus.mutex.stub(:synchronize, mock) do
      part.atomically { true; false; }
    end
    mock.verify
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
denko-0.13.2 test/behaviors/bus_peripheral_addressed.rb
denko-0.13.1 test/behaviors/bus_peripheral_addressed.rb
denko-0.13.0 test/behaviors/bus_peripheral_addressed.rb