Sha256: 9c21b3a18d89e566ed8182a69ee1319b2a7c577bd5ec21560f58e5401da4495d

Contents?: true

Size: 1.29 KB

Versions: 4

Compression:

Stored size: 1.29 KB

Contents

require_relative "spec_helper"
require "lignite"

describe Lignite::Connection::Usb do
  let(:device) do
    instance_double("FakeDevice", interfaces: [interface])
  end
  let(:interface) { double("FakeInterface", endpoints: [in_ep, out_ep]) }
  let(:in_ep) { double("InEndpoint", direction: :in) }
  let(:out_ep) { double("OutEndpoint", direction: :out) }
  let(:dev_handle) { double("FakeDevHandle") }

  before(:each) do
    usb = instance_double("FakeContext", devices: [device])
    allow(LIBUSB::Context).to receive(:new).and_return(usb)
    allow(dev_handle).to receive(:"auto_detach_kernel_driver=")
    allow(dev_handle).to receive(:claim_interface).and_yield
  end

  describe "#write" do
    it "does not crash" do
      data = "hello"
      allow(device).to receive(:open).and_yield(dev_handle)
      allow(dev_handle).to receive(:interrupt_transfer).and_return(data.bytesize)
      expect { subject.write(data) }.to_not raise_error
    end
  end

  describe "#read" do
    it "does not crash" do
      allow(device).to receive(:open).and_yield(dev_handle)
      allow(dev_handle).to receive(:interrupt_transfer).and_return("hello")
      expect(subject.read(1000)).to eq("hello")
    end
  end

  describe "#write" do
    it "does not crash" do
      expect { subject.close }.to_not raise_error
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
lignite-0.6.0 spec/connection_usb_spec.rb
lignite-0.5.0 spec/connection_usb_spec.rb
lignite-0.4.0 spec/connection_usb_spec.rb
lignite-0.3.0 spec/connection_usb_spec.rb