Update mcollective.init according to OSCI-855
[packages/precise/mcollective.git] / spec / unit / plugins / mcollective / discovery / mc_spec.rb
1 #!/usr/bin/env rspec
2
3 require 'spec_helper'
4
5 require File.dirname(__FILE__) + '/../../../../../plugins/mcollective/discovery/mc.rb'
6
7 module MCollective
8   class Discovery
9     describe Mc do
10       describe "#discover" do
11         before do
12           @reply = mock
13           @reply.stubs(:payload).returns({:senderid => "rspec"})
14
15           @client = mock
16           @client.stubs(:sendreq)
17           @client.stubs(:unsubscribe)
18           @client.stubs(:receive).returns(@reply)
19
20           Log.stubs(:debug)
21         end
22
23         it "should send the ping request via the supplied client" do
24           @client.expects(:sendreq).with("ping", "discovery", Util.empty_filter).returns("123456")
25           Mc.discover(Util.empty_filter, 1, 1, @client)
26         end
27
28         it "should stop early if a limit is supplied" do
29           @client.stubs(:receive).returns(@reply).times(10)
30           Mc.discover(Util.empty_filter, 1, 10, @client).should == ("rspec," * 10).split(",")
31         end
32
33         it "should unsubscribe from the discovery reply source" do
34           @client.expects(:unsubscribe).with("discovery", :reply)
35           Mc.discover(Util.empty_filter, 1, 10, @client).should == ("rspec," * 10).split(",")
36         end
37       end
38     end
39   end
40 end