Sha256: 77ecf26e666b7eee65253e72ea9396d0d3f1c0f1ffb85bd0a2454244706ad506

Contents?: true

Size: 1.51 KB

Versions: 41

Compression:

Stored size: 1.51 KB

Contents

require 'helper'

module SSHKit
  # Try to maintain backwards compatibility with Custom formatters defined by other people
  class TestCustom < UnitTest

    def setup
      super
      SSHKit.config.output_verbosity = Logger::DEBUG
    end

    def output
      @output ||= String.new
    end

    def custom
      @custom ||= CustomFormatter.new(output)
    end

    {
        log:   'LM 1 Test',
        fatal: 'LM 4 Test',
        error: 'LM 3 Test',
        warn:  'LM 2 Test',
        info:  'LM 1 Test',
        debug: 'LM 0 Test'
    }.each do |level, expected_output|
      define_method("test_#{level}_logging") do
        custom.send(level, 'Test')
        assert_log_output expected_output
      end
    end

    def test_write_logs_commands
      custom.write(Command.new(:ls))

      assert_log_output 'C 1 /usr/bin/env ls'
    end

    def test_double_chevron_logs_commands
      custom << Command.new(:ls)

      assert_log_output 'C 1 /usr/bin/env ls'
    end

    def test_accepts_options_hash
      custom = CustomFormatter.new(output, :foo => 'value')
      assert_equal('value', custom.options[:foo])
    end

    private

    def assert_log_output(expected_output)
      assert_equal expected_output, output
    end

  end

  class CustomFormatter < SSHKit::Formatter::Abstract
    def write(obj)
      original_output << \
        case obj
        when SSHKit::Command    then "C #{obj.verbosity} #{obj}"
        when SSHKit::LogMessage then "LM #{obj.verbosity} #{obj}"
        end
    end
    alias :<< :write

  end

end

Version data entries

41 entries across 41 versions & 2 rubygems

Version Path
sshkit-1.23.2 test/unit/formatters/test_custom.rb
sshkit-1.23.1 test/unit/formatters/test_custom.rb
sshkit-1.23.0 test/unit/formatters/test_custom.rb
sshkit-1.22.2 test/unit/formatters/test_custom.rb
sshkit-1.22.1 test/unit/formatters/test_custom.rb
sshkit-1.22.0 test/unit/formatters/test_custom.rb
sshkit-1.21.7 test/unit/formatters/test_custom.rb
honeybadger-5.4.0 vendor/bundle/ruby/3.2.0/gems/sshkit-1.21.6/test/unit/formatters/test_custom.rb
sshkit-1.21.6 test/unit/formatters/test_custom.rb
honeybadger-5.3.0 vendor/bundle/ruby/3.2.0/gems/sshkit-1.21.5/test/unit/formatters/test_custom.rb
sshkit-1.21.5 test/unit/formatters/test_custom.rb
sshkit-1.21.4 test/unit/formatters/test_custom.rb
sshkit-1.21.3 test/unit/formatters/test_custom.rb
sshkit-1.21.2 test/unit/formatters/test_custom.rb
sshkit-1.21.1 test/unit/formatters/test_custom.rb
sshkit-1.21.0 test/unit/formatters/test_custom.rb
honeybadger-4.5.3 vendor/bundle/ruby/2.6.0/gems/sshkit-1.18.2/test/unit/formatters/test_custom.rb
sshkit-1.20.0 test/unit/formatters/test_custom.rb
sshkit-1.19.1 test/unit/formatters/test_custom.rb
sshkit-1.19.0 test/unit/formatters/test_custom.rb