Sha256: 59e2018eb1c2a835f13f944d3b420112937da92a4548859eca61821ac4c146d4

Contents?: true

Size: 1.01 KB

Versions: 1

Compression:

Stored size: 1.01 KB

Contents

require 'shell_mock/monkey_patch'
require 'shell_mock/stub_registry'
require 'shell_mock/no_stub_specified'

module ShellMock
  class SpawnMonkeyPatch < MonkeyPatch
    def method_name
      :spawn
    end

    def override(env, command = nil, **options)
      env, command = {}, env if command.nil?

      # other arg manipulation can go here if necessary

      stub = StubRegistry.stub_matching(env, command, options)

      if stub
        stub.called_with(env, command, options)

        stub.side_effect.call

        __un_shell_mocked_spawn(stub.to_oneliner, **options)
      else
        if ShellMock.let_commands_run?
          __un_shell_mocked_spawn(env, command, **options)
        else
          raise NoStubSpecified.new(env, command, options)
        end
      end
    end

    def enable
      enable_for(Process.eigenclass) unless Process.respond_to?(method_alias, true)

      super
    end

    def disable
      super

      disable_for(Process.eigenclass) if Process.respond_to?(method_alias, true)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
shell_mock-0.5.0 lib/shell_mock/spawn_monkey_patch.rb