File: sys_top_spec.rb

package info (click to toggle)
ruby-sys-proctable 1.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 396 kB
  • sloc: ruby: 3,656; makefile: 3
file content (50 lines) | stat: -rw-r--r-- 1,528 bytes parent folder | download
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
##############################################################################
# sys_top_spec.rb
#
# Test suite for the sys-top library that is included with this distribution.
##############################################################################
require 'spec_helper'

RSpec.describe Sys::Top do
  context 'constants' do
    it 'sets the version to the expected value' do
      expect(Sys::Top::VERSION).to eql('1.0.5')
    end
  end

  context 'top' do
    it 'defines a top method' do
      expect(described_class).to respond_to(:top)
    end

    it 'returns an array' do
      expect(described_class.top).to be_kind_of(Array)
    end

    it 'works with no arguments' do
      expect{ described_class.top }.not_to raise_error
    end

    it 'accepts a maximum of two arguments' do
      expect{ described_class.top(1, 'foo', 2) }.to raise_error(ArgumentError)
    end

    it 'accepts optional arguments' do
      expect{ described_class.top(5) }.not_to raise_error
      expect{ described_class.top(5, 'cmdline') }.not_to raise_error
    end

    it 'returns the expected results with no arguments' do
      expect(described_class.top.size).to be(10)
      expect(described_class.top.first).to be_kind_of(Struct::ProcTableStruct)
    end

    it 'returns the expected result with a size argument' do
      expect(described_class.top(5).size).to be(5)
    end

    it 'returns the expected result with a size and sort_by argument' do
      expect(described_class.top(5, :cmdline).size).to be(5)
    end
  end
end