module ShellMock

Constants

StubRegistry
VERSION

Public Class Methods

disable() click to toggle source
# 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_run() click to toggle source
# File lib/shell_mock.rb, line 19
def self.dont_let_commands_run
  @let_commands_run = false
end
dont_let_commands_run?() click to toggle source

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

# File lib/shell_mock.rb, line 29
def self.dont_let_commands_run?
  !let_commands_run?
end
enable() click to toggle source
# File lib/shell_mock.rb, line 33
def self.enable
  ShellMock.monkey_patches.each(&:enable)

  @enabled = true

  true
end
enabled?() click to toggle source
# File lib/shell_mock.rb, line 52
def self.enabled?
  @enabled
end
let_commands_run() click to toggle source
# File lib/shell_mock.rb, line 15
def self.let_commands_run
  @let_commands_run = true
end
let_commands_run?() click to toggle source
# 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_patches() click to toggle source
# 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) click to toggle source
# File lib/shell_mock.rb, line 9
def self.stub_command(command)
  command_stub = CommandStub.new(command)

  StubRegistry.register_command_stub(command_stub)
end

Public Instance Methods

clear() click to toggle source
# File lib/shell_mock/stub_registry.rb, line 29
def clear
  @command_stubs = []
end
command_stubs() click to toggle source
# File lib/shell_mock/stub_registry.rb, line 25
def command_stubs
  @command_stubs ||= []
end
register_command_stub(command_stub) click to toggle source
# File lib/shell_mock/stub_registry.rb, line 5
def register_command_stub(command_stub)
  command_stubs << command_stub
  command_stub
end
stub_matching(env, command, options) click to toggle source
# File lib/shell_mock/stub_registry.rb, line 10
def stub_matching(env, command, options)
  matching_stubs = command_stubs.select do |command_stub|
    command_stub.command == command &&
      command_stub.env <= env &&
      command_stub.options <= options
  end

  # question: Should we increment all the stubs that match?
  #   What should users expect when they register a stub that
  #   wholly "covers" another already-registered stub?
  matching_stubs.max_by do |command_stub|
    [env.size, options.size]
  end
end