Sha256: abc2c8a0970e04879e3d5cf2a35a6f9e709a94cd2c5c9e7e03e20494947d4079

Contents?: true

Size: 1.86 KB

Versions: 1

Compression:

Stored size: 1.86 KB

Contents

require_relative "spec_helper"
require "lignite/ev3_tool"

require "fileutils"

describe Lignite::Ev3Tool do
  around(:each) do |example|
    ENV["LIGNITE_REPLAY"] = replay
    example.call
    subject.close
    ENV["LIGNITE_REPLAY"] = nil
  end

  before(:each) { Lignite::Message.reset_msgid }

  describe "#raw_ls" do
    let(:replay) { "#{datadir}/ev3tool_list_files.yml" }

    it "communicates and returns the right thing" do
      expected = [
        "everstorm.rbf",
        "sneeze.rsf",
        "hey.rsf",
        "right.rsf",
        "ok0.rsf",
        "ok1.rsf",
        "left.rsf"
      ]

      expect(subject.raw_ls("everstorm")).to eq(expected)
    end
  end

  describe "#start" do
    let(:replay) { "#{datadir}/ev3tool_start.yml" }

    it "communicates the right thing" do
      expect { subject.start("everstorm") }.not_to raise_error
    end
  end

  describe "#stop" do
    let(:replay) { "#{datadir}/ev3tool_stop.yml" }

    it "communicates the right thing" do
      expect { subject.stop }.not_to raise_error
    end
  end

  describe "#download" do
    let(:replay) { "#{datadir}/ev3tool_download.yml" }

    it "communicates the right thing" do
      expected_file_contents = File.read("#{datadir}/everstorm.rbf", mode: "rb")
      e1 = expected_file_contents[0...1000]
      e2 = expected_file_contents[1000..-1]
      f = double("File")
      expect(File).to receive(:open).with("everstorm.rbf", "w").and_yield(f)
      allow(File).to receive(:open).and_call_original
      expect(f).to receive(:write).with(e1)
      expect(f).to receive(:write).with(e2)

      expect { subject.download("../prjs/everstorm/everstorm.rbf") }.not_to raise_error
    end
  end

  describe "#upload" do
    let(:replay) { "#{datadir}/ev3tool_upload.yml" }

    it "communicates the right thing" do
      expect { subject.upload("#{datadir}/HelloWorld.rbf") }.not_to raise_error
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
lignite-0.6.0 spec/ev3_tool_spec.rb