Sha256: f6dc28d43698c5c49e6efc9a7f4e33bb9f9ddc621c3cfa03bb0533a218f1409e

Contents?: true

Size: 1.53 KB

Versions: 3

Compression:

Stored size: 1.53 KB

Contents

describe Lita::Adapters::Shell do
  let(:robot) do
    double("Lita::Robot", name: "Lita", mention_name: "LitaBot", alias: "/")
  end

  subject { described_class.new(robot) }

  describe "#run" do
    before do
      allow(subject).to receive(:puts)
      allow(subject).to receive(:print)
      allow($stdin).to receive(:gets).and_return("foo", "exit")
      allow(robot).to receive(:trigger)
      allow(robot).to receive(:receive)
    end

    it "passes input to the Robot and breaks on an exit message" do
      expect(subject).to receive(:print).with("#{robot.name} > ").twice
      expect(robot).to receive(:receive).with(an_instance_of(Lita::Message))
      subject.run
    end

    it "marks messages as commands if config.adapter.private_chat is true" do
      Lita.config.adapter.private_chat = true
      expect_any_instance_of(Lita::Message).to receive(:command!)
      subject.run
    end

    it "triggers a connected event" do
      expect(robot).to receive(:trigger).with(:connected)
      subject.run
    end
  end

  describe "#send_message" do
    it "prints its input" do
      expect(subject).to receive(:puts) do |messages|
        expect(messages.first).to include("bar")
      end
      subject.send_messages(double("target"), "bar")
    end

    it "doesn't output empty messages" do
      expect(subject).to receive(:puts).with([])
      subject.send_messages(double("target"), "")
    end
  end

  describe "#shut_down" do
    it "outputs a blank line" do
      expect(subject).to receive(:puts)
      subject.shut_down
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
lita-2.7.2 spec/lita/adapters/shell_spec.rb
lita-2.7.1 spec/lita/adapters/shell_spec.rb
lita-2.7.0 spec/lita/adapters/shell_spec.rb