vagrant-lxc-ng/spec/unit/support/unit_example_group.rb

39 lines
1.2 KiB
Ruby
Raw Normal View History

2013-03-02 00:20:11 +00:00
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)
}
Object.any_instance.stub(:`) { |*args, &block|
UnitExampleGroup.prevent_system_calls(*args, &block)
}
Object.any_instance.stub(:exec) { |*args, &block|
UnitExampleGroup.prevent_system_calls(*args, &block)
}
Object.any_instance.stub(:fork) { |*args, &block|
UnitExampleGroup.prevent_system_calls(*args, &block)
}
2013-04-23 11:03:29 +00:00
Object.any_instance.stub(:spawn) { |*args, &block|
UnitExampleGroup.prevent_system_calls(*args, &block)
}
require 'vagrant/util/subprocess'
2013-03-02 00:20:11 +00:00
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.
Block: #{block.inspect}
2013-03-02 00:20:11 +00:00
Command: "#{args.join(' ')}"
MSG
end
end