Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add block device guard. #31

Merged
merged 2 commits into from

2 participants

@voxik

This will allow to conditionally exclude tests, which requires block device available on the system.

@voxik voxik referenced this pull request in rubinius/rubinius
Merged

Ignore block device test. #1898

@voxik

Pleas note that I did not test this on Windows. I am not sure if the find command will not throw exception.

@voxik

with_block_device now not yields on windows and freebsd

@brixen brixen merged commit 6cb3705 into rubyspec:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 24, 2012
  1. @voxik

    Add block device guard.

    voxik authored
Commits on Sep 25, 2012
  1. @voxik
This page is out of date. Refresh to see the latest.
View
1  lib/mspec/guards.rb
@@ -1,5 +1,6 @@
require 'mspec/utils/ruby_name'
require 'mspec/guards/background'
+require 'mspec/guards/block_device'
require 'mspec/guards/bug'
require 'mspec/guards/compliance'
require 'mspec/guards/conflict'
View
22 lib/mspec/guards/block_device.rb
@@ -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
View
46 spec/guards/block_device_spec.rb
@@ -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
Something went wrong with that request. Please try again.