1002d12439bbbe3304083a8e06c7a00e621b2e66
[packages/precise/mcollective.git] / spec / unit / runnerstats_spec.rb
1 #!/usr/bin/env rspec
2
3 require 'spec_helper'
4
5 module MCollective
6   describe RunnerStats do
7     before do
8       Agents.stubs(:agentlist).returns("agents")
9       Time.stubs(:now).returns(Time.at(0))
10
11       @stats = RunnerStats.new
12
13       logger = mock
14       logger.stubs(:log)
15       logger.stubs(:start)
16       Log.configure(logger)
17     end
18
19     describe "#to_hash" do
20       it "should return the correct data" do
21         @stats.to_hash.keys.sort.should == [:stats, :threads, :pid, :times, :agents].sort
22
23         @stats.to_hash[:stats].should == {:validated => 0, :unvalidated => 0, :passed => 0, :filtered => 0,
24           :starttime => 0, :total => 0, :ttlexpired => 0, :replies => 0}
25
26         @stats.to_hash[:agents].should == "agents"
27       end
28     end
29
30     [[:ttlexpired, :ttlexpired], [:passed, :passed], [:filtered, :filtered],
31      [:validated, :validated], [:received, :total], [:sent, :replies]].each do |tst|
32       describe "##{tst.first}" do
33         it "should increment #{tst.first}" do
34           @stats.send(tst.first)
35           @stats.to_hash[:stats][tst.last].should == 1
36         end
37       end
38     end
39   end
40 end