summaryrefslogtreecommitdiff
path: root/test/functional/bin_test.rb
blob: 4d9f90440d3424d332cada8d187a69ddc2e8e8db (plain)
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
require 'minitest/autorun'
require 'minitest/pride'

class BinTest < Minitest::Test
  def teardown
    run_command 'stop'
  end

  def test_bin_loading
    assert_command_runs('version')
  end

  def test_not_running_by_default
    assert_stopped
  end

  def test_start
    run_command 'start'
    assert_running
  end

  protected

  def assert_running
    status = run_command 'status'
    assert_includes status, 'Nickserver running'
  end

  def assert_stopped
    status = run_command 'status'
    assert_includes status, 'No nickserver processes are running.'
  end

  def assert_command_runs(command)
    out = run_command command
    assert $CHILD_STATUS.exitstatus.zero?,
           "failed to run 'nickserver #{command}':\n #{out}"
  end

  def run_command(command)
    `#{path_to_executable} #{command} 2>&1`
  end

  def path_to_executable
    File.expand_path(File.dirname(__FILE__) + '/../../bin/nickserver')
  end
end