Sha256: 126ea4c14448bb407f86c48d754c218a8e931c8c47dd0a34ca38aa7194c69563

Contents?: true

Size: 641 Bytes

Versions: 9

Compression:

Stored size: 641 Bytes

Contents

module ShellMock
  StubRegistry = Object.new

  StubRegistry.instance_exec do
    def register_command_stub(command_stub)
      command_stubs << command_stub
      command_stub
    end

    def stub_matching(env, command, options)
      matching_stubs = command_stubs.select do |command_stub|
        command_stub.env <= env &&
          command_stub.options <= options &&
          command_stub.command == command
      end

      matching_stubs.max_by do |command_stub|
        [env.size, options.size]
      end
    end

    def command_stubs
      @command_stubs ||= []
    end

    def clear
      @command_stubs = []
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
shell_mock-0.4.0 lib/shell_mock/stub_registry.rb
shell_mock-0.3.3 lib/shell_mock/stub_registry.rb
shell_mock-0.3.2 lib/shell_mock/stub_registry.rb
shell_mock-0.3.1 lib/shell_mock/stub_registry.rb
shell_mock-0.3.0 lib/shell_mock/stub_registry.rb
shell_mock-0.2.2 lib/shell_mock/stub_registry.rb
shell_mock-0.2.1 lib/shell_mock/stub_registry.rb
shell_mock-0.2.0 lib/shell_mock/stub_registry.rb
shell_mock-0.1.0 lib/shell_mock/stub_registry.rb