File: test_dot.rb

package info (click to toggle)
ruby-sshkit 1.9.0-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 604 kB
  • ctags: 619
  • sloc: ruby: 3,045; makefile: 2
file content (58 lines) | stat: -rw-r--r-- 1,328 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
require 'helper'

module SSHKit
  class TestDot < UnitTest

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

    def output
      @output ||= String.new
    end

    def dot
      @dot ||= SSHKit::Formatter::Dot.new(output)
    end

    %w(fatal error warn info debug).each do |level|
      define_method("test_#{level}_output") do
        dot.send(level, 'Test')
        assert_log_output('')
      end
    end

    def test_log_command_start
      dot.log_command_start(SSHKit::Command.new(:ls))
      assert_log_output('')
    end

    def test_log_command_data
      dot.log_command_data(SSHKit::Command.new(:ls), :stdout, 'Some output')
      assert_log_output('')
    end

    def test_command_success
      output.stubs(:tty?).returns(true)
      command = SSHKit::Command.new(:ls)
      command.exit_status = 0
      dot.log_command_exit(command)
      assert_log_output("\e[0;32;49m.\e[0m")
    end

    def test_command_failure
      output.stubs(:tty?).returns(true)
      command = SSHKit::Command.new(:ls, {raise_on_non_zero_exit: false})
      command.exit_status = 1
      dot.log_command_exit(command)
      assert_log_output("\e[0;31;49m.\e[0m")
    end

    private

    def assert_log_output(expected_output)
      assert_equal expected_output, output
    end
  end
end