Sha256: 0110cba1624694e09f092eedf7615b37bf8fc3d5f5a4b121f8e54a2d03dea797

Contents?: true

Size: 1.83 KB

Versions: 4

Compression:

Stored size: 1.83 KB

Contents

require 'stringio'
require 'test_helper'

class SlaveTest < ActiveSupport::TestCase
  setup do
    PTY.stubs(:spawn).returns([StringIO.new, StringIO.new, Random.rand(20000)])
    @slave = WebConsole::Slave.new
  end

  test '#send_input raises ArgumentError on bad input' do
    assert_raises(ArgumentError) { @slave.send_input(nil) }
    assert_raises(ArgumentError) { @slave.send_input('') }
  end

  test '#pending_output returns nil on no pending output' do
    @slave.stubs(:pending_output?).returns(false)
    assert_nil @slave.pending_output
  end

  test '#pending_output returns a string with the current output' do
    @slave.stubs(:pending_output?).returns(true)
    @slave.instance_variable_get(:@output).stubs(:read_nonblock).returns('foo', nil)
    assert_equal 'foo', @slave.pending_output
  end

  test '#pending_output always encodes output in UTF-8' do
    @slave.stubs(:pending_output?).returns(true)
    @slave.instance_variable_get(:@output).stubs(:read_nonblock).returns('foo', nil)
    assert_equal Encoding::UTF_8, @slave.pending_output.encoding
  end

  test '#configure changes @input dimentions' do
    @slave.instance_variable_get(:@input).expects(:winsize=).with([32, 64])
    @slave.configure(height: 32, width: 64)
  end

  test '#configure only changes the @input dimentions if width is zero' do
    @slave.instance_variable_get(:@input).expects(:winsize=).never
    @slave.configure(height: 32, width: 0)
  end

  test '#configure only changes the @input dimentions if height is zero' do
    @slave.instance_variable_get(:@input).expects(:winsize=).never
    @slave.configure(height: 0, width: 64)
  end

  { dispose: :SIGTERM, dispose!: :SIGKILL }.each do |method, signal|
    test "##{method} sends #{signal} to the process and detaches it" do
      Process.expects(:kill).with(signal, @slave.pid)
      @slave.send(method)
    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
web-console-rails3-0.4.1 test/web_console/slave_test.rb
web-console-0.4.0 test/web_console/slave_test.rb
web-console-rails3-0.3.0 test/web_console/slave_test.rb
web-console-0.3.0 test/web_console/slave_test.rb