spec/support/shell_mock.rb in waddup-0.0.2 vs spec/support/shell_mock.rb in waddup-0.1.0
- old
+ new
@@ -1,26 +1,32 @@
-# Raised when shell operations are invoked
-class ShellNotAllowedError < StandardError
+module ShellMock
- def initialize(command)
- msg = "Shell operation is not allowed: #{command}\n\n"
- msg << "You can stub this request with the following snippet:\n\n"
- msg << "stub_shell(\"#{command}\", :output => '', :exitstatus => 0)\n "
- super msg
- end
+ # Raised when shell operations are invoked
+ class ShellNotAllowedError < StandardError
-end
+ def initialize(command)
+ msg = "Shell operation is not allowed: #{command}\n\n"
+ msg << "You can stub this request with the following snippet:\n\n"
+ msg << "stub_shell(\"#{command}\", output: '', exitstatus: 0)\n "
+ super msg
+ end
-# Prevent invoking shell operations
-class Object
-
- def `(command)
- raise ShellNotAllowedError, command
end
- def system(command)
- raise ShellNotAllowedError, command
+ # Applies shell mock functionality
+ def self.apply!
+ Object.any_instance.stub(:`).and_return do |foo|
+ raise ShellNotAllowedError, foo
+ end
+
+ Object.any_instance.stub(:system).and_return do |command|
+ raise ShellNotAllowedError, command
+ end
end
+
+end
+
+class Object
# Stubs shell operations matching given command
#
# Options:
# :output (defaults to '')