Sha256: 2264b818be342ac6a98fa1b06d13ea658efea5e64991e4cc6f55f6b39dbcaf9f

Contents?: true

Size: 1.85 KB

Versions: 1

Compression:

Stored size: 1.85 KB

Contents

require 'spec_helper'

include Ramdo
describe Ramdisk::DarwinWrapper, if: os?(/darwin/) do
  before(:each) do
    wrapper = Ramdisk::DarwinWrapper.new
    wrapper.list.each do |disk|
      disk.destroy!
    end
  end


  it 'should check if a ramdisk already exists' do
    wrapper = Ramdisk::DarwinWrapper.new
    disks = wrapper.list
    expect(disks).to be_an(Array)
    expect(disks.length).to be_a(Integer)
    expect(disks.length).to be(0)
  end

  it 'should check if enough RAM space is free' do
    wrapper = Ramdisk::DarwinWrapper.new
    expect(wrapper.send(:enough_ram?, '100 MB')).to be_truthy
    expect(wrapper.send(:enough_ram?, '100 GB')).to be_falsey
  end

  it 'should create a new RAM disk and save a file to it' do
    size = '100 MB'

    wrapper = Ramdisk::DarwinWrapper.new
    disk = wrapper.create(size)

    expect(disk).to be_an(Ramdisk::Instance)
    expect { IO.write("#{disk.path}/test.bin", IO.read('/dev/urandom', 100000)) }.not_to raise_error
  end

  it 'should remove a RAM disk' do
    wrapper = Ramdisk::DarwinWrapper.new
    disk = wrapper.create('100 MB')

    count = wrapper.list.length
    expect(disk.destroy!).to be_truthy
    expect(disk.destroy!).to be_falsey # Should not work another time

    expect(wrapper.list.length).to be(count - 1)
  end

  it 'should list all available RAM disks' do
    wrapper = Ramdisk::DarwinWrapper.new
    disk = wrapper.create('100 MB')

    list = wrapper.list
    expect(list.length).to eq(1)
    expect(list.first.device).not_to be_empty
    expect(File.exist?(list.first.device)).to be_truthy
    expect(Dir.exist?(list.first.path)).to be_truthy

    disk = wrapper.create('200 MB')

    list = wrapper.list
    expect(list.length).to eq(2)
    expect(list.last.device).not_to be_empty
    expect(File.exist?(list.last.device)).to be_truthy
    expect(Dir.exist?(list.last.path)).to be_truthy
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ramdo-0.2.1 spec/darwin_wrapper_spec.rb