Sha256: 1fa9714562ed4fb0060fc8a3bef47802d077b8c14dc4df5ba5d6de28c827a34c

Contents?: true

Size: 1.34 KB

Versions: 6

Compression:

Stored size: 1.34 KB

Contents

require 'spec_helper'
require 'mspec/guards'

describe Object, "#with_block_device" do
  before :each do
    ScratchPad.clear

    @guard = BlockDeviceGuard.new
    BlockDeviceGuard.stub!(:new).and_return(@guard)
  end

  platform_is_not :freebsd, :windows do
    it "yields if block device is available" do
      @guard.should_receive(:`).and_return("block devices")
      with_block_device { ScratchPad.record :yield }
      ScratchPad.recorded.should == :yield
    end

    it "does not yield if block device is not available" do
      @guard.should_receive(:`).and_return(nil)
      with_block_device { ScratchPad.record :yield }
      ScratchPad.recorded.should_not == :yield
    end
  end

  platform_is :freebsd, :windows do
    it "does not yield, since platform does not support block devices" do
      @guard.should_not_receive(:`)
      with_block_device { ScratchPad.record :yield }
      ScratchPad.recorded.should_not == :yield
    end
  end

  it "sets the name of the guard to :with_block_device" do
    with_block_device { }
    @guard.name.should == :with_block_device
  end

  it "calls #unregister even when an exception is raised in the guard block" do
    @guard.should_receive(:match?).and_return(true)
    @guard.should_receive(:unregister)
    lambda do
      with_block_device { raise Exception }
    end.should raise_error(Exception)
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
mspec-1.7.0 spec/guards/block_device_spec.rb
mspec-1.6.0 spec/guards/block_device_spec.rb
mspec-1.5.21 spec/guards/block_device_spec.rb
mspec-1.5.20 spec/guards/block_device_spec.rb
mspec-1.5.19 spec/guards/block_device_spec.rb
mspec-1.5.18 spec/guards/block_device_spec.rb