spec/lita/robot_spec.rb in lita-0.0.1 vs spec/lita/robot_spec.rb in lita-1.0.0

- old
+ new

@@ -1,13 +1,14 @@ require "spec_helper" describe Lita::Robot do - it "raises an exception if the specified adapter can't be found" do + it "logs and quits if the specified adapter can't be found" do adapter_registry = double("adapter_registry") allow(Lita).to receive(:adapters).and_return(adapter_registry) allow(adapter_registry).to receive(:[]).and_return(nil) - expect { subject }.to raise_error(Lita::UnknownAdapterError) + expect(Lita.logger).to receive(:fatal).with(/Unknown adapter/) + expect { subject }.to raise_error(SystemExit) end describe "#receive" do let(:handler1) { double("Handler 1") } let(:handler2) { double("Handler 2") } @@ -23,20 +24,47 @@ describe "#run" do it "starts the adapter" do expect_any_instance_of(Lita::Adapters::Shell).to receive(:run) subject.run end + + it "rescues interrupts and calls #shut_down" do + allow_any_instance_of( + Lita::Adapters::Shell + ).to receive(:run).and_raise(Interrupt) + expect_any_instance_of(Lita::Adapters::Shell).to receive(:shut_down) + subject.run + end end describe "#send_message" do - let(:message) { double("Message") } + let(:source) { double("Source") } it "delegates to the adapter" do expect_any_instance_of( Lita::Adapters::Shell ).to receive(:send_messages).with( - message, ["foo", "bar"] + source, ["foo", "bar"] ) - subject.send_messages(message, "foo", "bar") + subject.send_messages(source, "foo", "bar") + end + end + + describe "#set_topic" do + let(:source) { double("Source") } + + it "delegates to the adapter" do + expect_any_instance_of(Lita::Adapters::Shell).to receive(:set_topic).with( + source, + "New topic" + ) + subject.set_topic(source, "New topic") + end + end + + describe "#shut_down" do + it "gracefully stops the adapter" do + expect_any_instance_of(Lita::Adapters::Shell).to receive(:shut_down) + subject.shut_down end end end