blob: dd420d4a81e91ad31305a58ac3a8b3153464b6c8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
require 'spec_helper'
require 'mspec/guards'
RSpec.describe Object, "#with_block_device" do
before :each do
ScratchPad.clear
@guard = BlockDeviceGuard.new
allow(BlockDeviceGuard).to receive(:new).and_return(@guard)
end
platform_is_not :freebsd, :windows do
it "yields if block device is available" do
expect(@guard).to receive(:`).and_return("block devices")
with_block_device { ScratchPad.record :yield }
expect(ScratchPad.recorded).to eq(:yield)
end
it "does not yield if block device is not available" do
expect(@guard).to receive(:`).and_return(nil)
with_block_device { ScratchPad.record :yield }
expect(ScratchPad.recorded).not_to eq(:yield)
end
end
platform_is :freebsd, :windows do
it "does not yield, since platform does not support block devices" do
expect(@guard).not_to receive(:`)
with_block_device { ScratchPad.record :yield }
expect(ScratchPad.recorded).not_to eq(:yield)
end
end
it "sets the name of the guard to :with_block_device" do
with_block_device { }
expect(@guard.name).to eq(:with_block_device)
end
it "calls #unregister even when an exception is raised in the guard block" do
expect(@guard).to receive(:match?).and_return(true)
expect(@guard).to receive(:unregister)
expect do
with_block_device { raise Exception }
end.to raise_error(Exception)
end
end
|