Skip to content

Commit

Permalink
with_block_device does not yield on windows and freebsd.
Browse files Browse the repository at this point in the history
  • Loading branch information
voxik committed Sep 25, 2012
1 parent 7b31bcd commit a0d2e46
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
8 changes: 6 additions & 2 deletions lib/mspec/guards/block_device.rb
Expand Up @@ -2,8 +2,12 @@

class BlockDeviceGuard < SpecGuard
def match?
block = `find /dev /devices -type b 2> /dev/null`
!(block.nil? || block.empty?)
platform_is_not :freebsd, :windows do
block = `find /dev /devices -type b 2> /dev/null`
return !(block.nil? || block.empty?)
end

false
end
end

Expand Down
26 changes: 18 additions & 8 deletions spec/guards/block_device_spec.rb
Expand Up @@ -9,16 +9,26 @@
BlockDeviceGuard.stub!(:new).and_return(@guard)
end

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
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

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
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
Expand Down

0 comments on commit a0d2e46

Please sign in to comment.