Module: ShellMock

Defined in:
lib/shell_mock.rb,
lib/shell_mock/version.rb,
lib/shell_mock/command_stub.rb,
lib/shell_mock/monkey_patch.rb,
lib/shell_mock/run_verifier.rb,
lib/shell_mock/stub_registry.rb,
lib/shell_mock/rspec/matchers.rb,
lib/shell_mock/exec_monkey_patch.rb,
lib/shell_mock/no_stub_specified.rb,
lib/shell_mock/spawn_monkey_patch.rb,
lib/shell_mock/system_monkey_patch.rb,
lib/shell_mock/backtick_monkey_patch.rb

Defined Under Namespace

Modules: Matchers Classes: BacktickMonkeyPatch, CommandStub, ExecMonkeyPatch, MonkeyPatch, NoStubSpecified, RunVerifier, SpawnMonkeyPatch, SystemMonkeyPatch

Constant Summary collapse

VERSION =
"0.7.1"
StubRegistry =
Object.new

Class Method Summary collapse

Class Method Details

.disableObject



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

def self.disable
  ShellMock.monkey_patches.each(&:disable)

  StubRegistry.clear

  @enabled          = false
  @let_commands_run = nil

  true
end

.dont_let_commands_runObject



19
20
21
# File 'lib/shell_mock.rb', line 19

def self.dont_let_commands_run
  @let_commands_run = false
end

.dont_let_commands_run?Boolean

smell; this is a mistake of a method that will only confuse people

Returns:

  • (Boolean)


29
30
31
# File 'lib/shell_mock.rb', line 29

def self.dont_let_commands_run?
  !let_commands_run?
end

.enableObject



33
34
35
36
37
38
39
# File 'lib/shell_mock.rb', line 33

def self.enable
  ShellMock.monkey_patches.each(&:enable)

  @enabled = true

  true
end

.enabled?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/shell_mock.rb', line 52

def self.enabled?
  @enabled
end

.let_commands_runObject



15
16
17
# File 'lib/shell_mock.rb', line 15

def self.let_commands_run
  @let_commands_run = true
end

.let_commands_run?Boolean

Returns:

  • (Boolean)


23
24
25
26
# File 'lib/shell_mock.rb', line 23

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

.monkey_patchesObject



56
57
58
59
60
61
62
63
# File 'lib/shell_mock.rb', line 56

def self.monkey_patches
  @monkey_patches ||= [
    SpawnMonkeyPatch.new,
    SystemMonkeyPatch.new,
    ExecMonkeyPatch.new,
    BacktickMonkeyPatch.new,
  ]
end

.stub_command(command) ⇒ Object



9
10
11
12
13
# File 'lib/shell_mock.rb', line 9

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

  StubRegistry.register_command_stub(command_stub)
end