spec/lita/robot_spec.rb in lita-3.3.1 vs spec/lita/robot_spec.rb in lita-4.0.0.rc1
- old
+ new
@@ -1,27 +1,24 @@
require "spec_helper"
-describe Lita::Robot 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(Lita.logger).to receive(:fatal).with(/Unknown adapter/)
- expect { subject }.to raise_error(SystemExit)
- end
+describe Lita::Robot, lita: true do
+ subject { described_class.new(registry) }
+ before { registry.register_adapter(:shell, Lita::Adapters::Shell) }
+
it "triggers a loaded event after initialization" do
expect_any_instance_of(described_class).to receive(:trigger).with(:loaded)
subject
end
context "with registered handlers" do
- let(:handler1) { class_double("Lita::Handler", http_routes: [], trigger: nil) }
- let(:handler2) { class_double("Lita::Handler", http_routes: [], trigger: nil) }
+ let(:handler1) { Class.new(Lita::Handler) { namespace :test } }
+ let(:handler2) { Class.new(Lita::Handler) { namespace :test } }
before do
- allow(Lita).to receive(:handlers).and_return([handler1, handler2])
+ registry.register_handler(handler1)
+ registry.register_handler(handler2)
end
describe "#receive" do
it "dispatches messages to every registered handler" do
expect(handler1).to receive(:dispatch).with(subject, "foo")
@@ -68,10 +65,30 @@
Lita::Adapters::Shell
).to receive(:run).and_raise(Interrupt)
expect_any_instance_of(Lita::Adapters::Shell).to receive(:shut_down)
subject.run
end
+
+ it "logs and quits if the specified adapter can't be found" do
+ registry.config.robot.adapter = :does_not_exist
+ expect(Lita.logger).to receive(:fatal).with(/Unknown adapter/)
+ expect { subject.run }.to raise_error(SystemExit)
+ end
+
+ it "logs and aborts if the web server's port is in use" do
+ allow_any_instance_of(Puma::Server).to receive(:add_tcp_listener).and_raise(Errno::EADDRINUSE)
+
+ expect(Lita.logger).to receive(:fatal).with(/web server/)
+ expect { subject.run }.to raise_error(SystemExit)
+ end
+
+ it "logs and aborts if the web server's port is privileged" do
+ allow_any_instance_of(Puma::Server).to receive(:add_tcp_listener).and_raise(Errno::EACCES)
+
+ expect(Lita.logger).to receive(:fatal).with(/web server/)
+ expect { subject.run }.to raise_error(SystemExit)
+ end
end
describe "#join" do
it "delegates to the adapter" do
expect_any_instance_of(Lita::Adapters::Shell).to receive(:join).with("#lita.io")
@@ -149,9 +166,11 @@
subject.set_topic(source, "New topic")
end
end
describe "#shut_down" do
+ before { allow_any_instance_of(Lita::Adapters::Shell).to receive(:puts) }
+
it "gracefully stops the adapter" do
expect_any_instance_of(Lita::Adapters::Shell).to receive(:shut_down)
subject.shut_down
end