Safety net for running unit specs
This commit is contained in:
parent
7e48b572d7
commit
927c56c024
3 changed files with 29 additions and 1 deletions
|
@ -13,7 +13,7 @@ Bundler.require
|
|||
|
||||
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|
|
||||
config.treat_symbols_as_metadata_keys_with_true_values = true
|
||||
|
|
24
spec/support/unit_example_group.rb
Normal file
24
spec/support/unit_example_group.rb
Normal 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
|
|
@ -2,4 +2,8 @@ require 'spec_helper'
|
|||
|
||||
RSpec.configure do |config|
|
||||
config.include RSpec::Fire
|
||||
|
||||
config.include UnitExampleGroup, :type => :unit, :example_group => {
|
||||
:file_path => /\bspec\/unit\//
|
||||
}
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue