Permalink
Browse files

ERP-121 Finish up specs for CLI

  • Loading branch information...
1 parent 9f908d2 commit 247eff5fb72814aa4042b7fb5d1d09badaa9abb3 @tusharr tusharr committed Jun 25, 2014
Showing with 49 additions and 2 deletions.
  1. +0 −2 lib/honest_pubsub/cli.rb
  2. +30 −0 spec/honest_pubsub/cli_spec.rb
  3. +19 −0 spec/spec_helper.rb
View
@@ -84,8 +84,6 @@ def write_pidfile
def load_subscribers
HonestPubsub::Server::SubscriberServer.new(subscriber_classes).start
end
-
-
end
end
@@ -112,4 +112,34 @@
end
end
+ describe '#load_subscribers' do
+ let(:subscribers) { nil }
+ let(:subscriber_server) { double('subscriber_server')}
+ before {
+ cli.subscribers = subscribers
+ allow(subscriber_server).to receive(:start)
+ allow(HonestPubsub::Server::SubscriberServer).to receive(:new).and_return(subscriber_server)
+ cli.send(:load_subscribers)
+ }
+
+ context "No subscribers passed through CLI" do
+ let(:all_subscribers) { HonestPubsub::Server::ClientWorker.class_variable_get(:@@registered_subscribers) }
+ it "loads all subscribers" do
+ expect(all_subscribers).to include(MyTestSubscriber1)
@ricaurte

ricaurte Jun 26, 2014

separate its again por favor

+ expect(all_subscribers).to include(MyTestSubscriber2)
+ expect(all_subscribers).to include(MyTestSubscriber3)
+ expect(HonestPubsub::Server::SubscriberServer).to have_received(:new).with(all_subscribers)
+ expect(subscriber_server).to have_received(:start)
+ end
+ end
+
+ context "Subscribers passed through CLI" do
+ let(:subscribers) { ['MyTestSubscriber1', 'MyTestSubscriber2'] }
+ it "loads all subscribers" do
+ expect(HonestPubsub::Server::SubscriberServer).to have_received(:new).with([MyTestSubscriber1, MyTestSubscriber2])
+ expect(subscriber_server).to have_received(:start)
+ end
+ end
+ end
+
end
View
@@ -27,3 +27,22 @@
end
HonestPubsub::Configuration.configure_with("test", File.join(HonestPubsub.root,"spec/config.yml") )
+
+# Some test subscriber classes to make testing easier
+class MyTestSubscriber1 < HonestPubsub::Server::ClientWorker
+ def perform(payload)
+
+ end
+end
+
+class MyTestSubscriber2 < HonestPubsub::Server::ClientWorker
+ def perform(payload)
+
+ end
+end
+
+class MyTestSubscriber3 < MyTestSubscriber1
+ def perform(payload)
+
+ end
+end

0 comments on commit 247eff5

Please sign in to comment.