Sha256: a0af19e22403a7b74d3f467b687d82b38d8ec4f51f923bf441a0153e009a58c3

Contents?: true

Size: 1.76 KB

Versions: 2

Compression:

Stored size: 1.76 KB

Contents

require File.dirname(__FILE__)+'/../spec_helper'

include RfidUsbGomSensor

describe RfidUsbGomSensor::Node do
  it "should find the class at least" do
    Node.should_not == nil
  end

  it "should fail on a wronk checksum" do
    ref_rec = [2, 1, 12616128551217792992, 0, 77, 3]
    blk = ref_rec.pack "ccQccc"
    lambda { rec = (Node.decode blk) }.should raise_error
  end

  it "should decode a record" do
    ref_rec = [2, 1, 12616128551217792992, 0, 49, 3]
    blk = ref_rec.pack "ccQccc"
    rec = (Node.decode blk)
    rec.should == ref_rec
  end

  it "should calc a xor checksum" do
    buf = [0x01, 0x02, 0x04, 0x08].pack "c*"
    lambda { Node.checksum buf, 0x0f }.should_not raise_error
  end

  describe "with a node it" do

    RFID_NODE = <<-JSON
{
  "node": {
    "uri": "/sensors/rfid-usb-reader",
    "mtime": "2010-01-06T15:14:57+01:00",
    "ctime": "2010-01-06T15:14:57+01:00",
    "entries": [
      {
  "node": "/sensors/rfid-usb-reader/tags",
  "mtime": "2009-12-31T13:00:39+01:00",
  "ctime": "2009-12-31T13:00:39+01:00"
}
,
{ "attribute": {
  "name": "daemon_ip",
  "node": "/sensors/rfid-usb-reader",
  "value": "127.0.0.1",
  "type": "string",
  "mtime": "2010-01-07T19:30:36+01:00",
  "ctime": "2010-01-07T19:30:36+01:00"
} }
,
{ "attribute": {
  "name": "device",
  "node": "/sensors/rfid-usb-reader",
  "value": "/dev/tty.SLAB_USBtoUART",
  "type": "string",
  "mtime": "2010-01-06T15:15:29+01:00",
  "ctime": "2010-01-06T15:15:29+01:00"
} }    ]
  }
}
    JSON

    before :each do
      node_path = "/sensor/rfid/usb-reader"
      $c.should_receive(:read).with("#{node_path}.json").and_return(RFID_NODE)
      @sensor = (Node.new node_path)
    end

    it "should pull its config from GOM" do 
      @sensor.device.should == "/dev/tty.SLAB_USBtoUART"
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rfid-usb-gom-sensor-0.1.3 spec/rfid-usb-gom-sensor/node_spec.rb
rfid-usb-gom-sensor-0.1.2 spec/rfid-usb-gom-sensor/node_spec.rb