Module: ShellMock

Defined in:
lib/shell_mock.rb,
lib/shell_mock/version.rb,
lib/shell_mock/command_stub.rb,
lib/shell_mock/call_verifier.rb,
lib/shell_mock/stub_registry.rb,
lib/shell_mock/rspec/matchers.rb,
lib/shell_mock/no_stub_specified.rb

Defined Under Namespace

Modules: Matchers Classes: CallVerifier, CommandStub, NoStubSpecified

Constant Summary collapse

VERSION =
"0.2.2"
StubRegistry =
Object.new

Class Method Summary collapse

Class Method Details

.disableObject



44
45
46
47
48
49
50
51
# File 'lib/shell_mock.rb', line 44

def self.disable
  Kernel.module_exec do
    define_method(:system, &method(:__un_shell_mocked_system).to_proc) if Kernel.respond_to?(:__un_shell_mocked_system)
    define_method(:`, &method(:__un_shell_mocked_backtick).to_proc)    if Kernel.respond_to?(:__un_shell_mocked_backtick)
  end

  StubRegistry.clear
end

.dont_let_commands_runObject



17
18
19
# File 'lib/shell_mock.rb', line 17

def self.dont_let_commands_run
  @let_commands_run = false
end

.dont_let_commands_run?Boolean

Returns:



26
27
28
# File 'lib/shell_mock.rb', line 26

def self.dont_let_commands_run?
  !let_commands_run?
end

.enableObject



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/shell_mock.rb', line 30

def self.enable
  Kernel.module_exec do
    if Kernel.respond_to?(:__shell_mocked_system)
      define_method(:__un_shell_mocked_system, &method(:system).to_proc)
      define_method(:system, &method(:__shell_mocked_system).to_proc)
    end

    if Kernel.respond_to?(:__shell_mocked_backtick)
      define_method(:__un_shell_mocked_backtick, &method(:`).to_proc)
      define_method(:`, &method(:__shell_mocked_backtick).to_proc)
    end
  end
end

.let_commands_runObject



13
14
15
# File 'lib/shell_mock.rb', line 13

def self.let_commands_run
  @let_commands_run = true
end

.let_commands_run?Boolean

Returns:



21
22
23
24
# File 'lib/shell_mock.rb', line 21

def self.let_commands_run?
  @let_commands_run = true if @let_commands_run.nil?
  @let_commands_run
end

.stub_command(command) ⇒ Object



7
8
9
10
11
# File 'lib/shell_mock.rb', line 7

def self.stub_command(command)
  command_stub = CommandStub.new(command)

  StubRegistry.register_command_stub(command_stub)
end