Sha256: 8d688d7b5c5f04d66d48373f0a0bc49bab4ff0e6e4e2d6197804dc869efa2b55

Contents?: true

Size: 1.55 KB

Versions: 4

Compression:

Stored size: 1.55 KB

Contents

# frozen_string_literal: true

require "spec_helper"

describe Lita::Source do
  subject { described_class.new(user: user, room: room, private_message: pm) }

  let(:pm) { false }
  let(:room) { Lita::Room.new(1) }
  let(:user) { Lita::User.new(1) }

  describe "#room" do
    it "returns the room as a string" do
      expect(subject.room).to eq("1")
    end
  end

  describe "#room_object" do
    it "returns the room as a Lita::Room" do
      expect(subject.room_object).to eq(room)
    end
  end

  describe "#user" do
    it "returns the user object" do
      expect(subject.user).to eq(user)
    end
  end

  context "when the private_message argument is true" do
    let(:pm) { true }

    it "is marked as a private message" do
      expect(subject).to be_a_private_message
    end
  end

  it "can be manually marked as private" do
    subject.private_message!

    expect(subject).to be_a_private_message
  end

  context "with a string for the room argument" do
    let(:room) { "#channel" }

    it "sets #room to the string" do
      expect(subject.room).to eq(room)
    end

    it "sets #room_object to a Lita::Room with the string as its ID" do
      expect(subject.room_object).to eq(Lita::Room.new(room))
    end

    context "room exists in database" do
      let(:name) { "example" }

      it "finds room by its ID" do
        Lita::Room.create_or_update(room, name: name)
        expect(subject.room_object.name).to eq(name)
      end
    end
  end

  it "requires either a user or a room" do
    expect { described_class.new }.to raise_error(ArgumentError)
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rita-5.0.0.alpha.4 spec/lita/source_spec.rb
rita-5.0.0.alpha.3 spec/lita/source_spec.rb
rita-5.0.0.alpha.2 spec/lita/source_spec.rb
rita-5.0.0.alpha.1 spec/lita/source_spec.rb