Safety net for running unit specs

This commit is contained in:
Fabio Rehm 2013-03-01 21:20:11 -03:00
parent 7e48b572d7
commit 927c56c024
3 changed files with 29 additions and 1 deletions

View file

@ -13,7 +13,7 @@ Bundler.require
require 'rspec-spies' require 'rspec-spies'
Dir[File.dirname(__FILE__) + "/spec/support/**/*.rb"].each { |f| require f } Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each { |f| require f }
RSpec.configure do |config| RSpec.configure do |config|
config.treat_symbols_as_metadata_keys_with_true_values = true config.treat_symbols_as_metadata_keys_with_true_values = true

View file

@ -0,0 +1,24 @@
module UnitExampleGroup
def self.included(base)
base.metadata[:type] = :unit
base.before do
Object.any_instance.stub(:system) { |*args, &block|
UnitExampleGroup.prevent_system_calls(*args, &block)
}
Vagrant::Util::Subprocess.stub(:execute) { |*args, &block|
UnitExampleGroup.prevent_system_calls(*args, &block)
}
end
end
def self.prevent_system_calls(*args, &block)
args.pop if args.last.is_a?(Hash)
raise <<-MSG
Somehow your code under test is trying to execute a command on your system,
please stub it out or move your spec code to an acceptance spec.
Command: "#{args.join(' ')}"
MSG
end
end

View file

@ -2,4 +2,8 @@ require 'spec_helper'
RSpec.configure do |config| RSpec.configure do |config|
config.include RSpec::Fire config.include RSpec::Fire
config.include UnitExampleGroup, :type => :unit, :example_group => {
:file_path => /\bspec\/unit\//
}
end end