forked from rubinius/rubinius
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
143 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
require 'mspec/guards/guard' | ||
|
||
class BlockDeviceGuard < SpecGuard | ||
def match? | ||
platform_is_not :freebsd, :windows do | ||
block = `find /dev /devices -type b 2> /dev/null` | ||
return !(block.nil? || block.empty?) | ||
end | ||
|
||
false | ||
end | ||
end | ||
|
||
class Object | ||
def with_block_device | ||
g = BlockDeviceGuard.new | ||
g.name = :with_block_device | ||
yield if g.yield? | ||
ensure | ||
g.unregister | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters