Sha256: c3615e2240758df12cbaedefd79331faff6913b3bc974ba18e21f3e75f4de693

Contents?: true

Size: 1.34 KB

Versions: 7

Compression:

Stored size: 1.34 KB

Contents

require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
require 'artoo/drivers/led'

describe Artoo::Drivers::Led do
  before do
    @device = mock('device')
    @pin = 13
    @device.stubs(:pin).returns(@pin)
    @led = Artoo::Drivers::Led.new(:parent => @device)
    @connection = mock('connection')
    @device.stubs(:connection).returns(@connection)
  end

  it 'Led#is_on? default' do
    @led.is_on?.must_equal false
  end

  it 'Led#is_off? default' do
    @led.is_off?.must_equal true
  end

  it 'Led#on' do
    @connection.expects(:set_pin_mode).with(@pin, Firmata::Board::OUTPUT)
    @connection.expects(:digital_write).with(@pin, Firmata::Board::HIGH)
    @led.on
    @led.is_on?.must_equal true
  end

  it 'Led#off' do
    @connection.expects(:set_pin_mode).with(@pin, Firmata::Board::OUTPUT)
    @connection.expects(:digital_write).with(@pin, Firmata::Board::LOW)
    @led.off
    @led.is_off?.must_equal true
  end

  it 'Led#toggle' do
    @connection.stubs(:set_pin_mode)
    @connection.stubs(:digital_write)
    @led.is_off?.must_equal true
    @led.toggle
    @led.is_on?.must_equal true
    @led.toggle
    @led.is_off?.must_equal true
  end

  it 'Led#brightness' do
    val = 100
    @connection.expects(:set_pin_mode).with(@pin, Firmata::Board::PWM)
    @connection.expects(:analog_write).with(@pin, val)
    @led.brightness(val)
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
artoo-0.4.0 test/drivers/led_test.rb
artoo-0.3.0 test/drivers/led_test.rb
artoo-0.2.0 test/drivers/led_test.rb
artoo-0.1.3 test/drivers/led_test.rb
artoo-0.1.2 test/drivers/led_test.rb
artoo-0.1.1 test/drivers/led_test.rb
artoo-0.1.0 test/drivers/led_test.rb