File: stats_test.rb

package info (click to toggle)
ruby-beaneater 1.1.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 296 kB
  • sloc: ruby: 1,628; sh: 4; makefile: 2
file content (43 lines) | stat: -rw-r--r-- 1,188 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
# test/stats_test.rb

require File.expand_path('../test_helper', __FILE__)

describe Beaneater::Stats do
  before do
    connection = stub(:transmit => { :body => { 'uptime' => 1, 'cmd-use' => 2 }, :status => "OK"})
    @beanstalk = stub(:connection => connection)
    @stats = Beaneater::Stats.new(@beanstalk)
  end

  describe 'for #[]' do
    it "should return stats by key" do
      assert_equal 1, @stats[:uptime]
    end

    it "should return stats by underscore key" do
      assert_equal 2, @stats[:'cmd_use']
    end
  end # []

  describe 'for #keys' do
    it "should return list of keys" do
      assert_equal 2, @stats.keys.size
      assert @stats.keys.include?('uptime'), "Expected keys to include 'uptime'"
      assert @stats.keys.include?('cmd_use'), "Expected keys to include 'cmd-use'"
    end
  end # keys

  describe 'for #method_missing' do
    it "should return stats by key" do
      assert_equal 1, @stats.uptime
    end

    it "should return stats by underscore key" do
      assert_equal 2, @stats.cmd_use
    end

    it "should raise NoMethodError" do
      assert_raises(NoMethodError) { @stats.cmd }
    end
  end # method_missing
end # Beaneater::Stats