Sha256: 5f4004ce2e2a36c9038aca31805e876e78254aa5a553be74d595a16ffcab1292

Contents?: true

Size: 1.61 KB

Versions: 3

Compression:

Stored size: 1.61 KB

Contents

require "spec_helper"

handler_class = Class.new(Lita::Handler) do
  route(/^\w{3}$/, :foo)
  route(/^\w{4}$/, :blah, command: true)
  route("restricted", :restricted, restrict_to: :some_group)

  http.get "web", :web

  on :connected, :greet

  def foo(response)
    response.reply "baz"
  end

  def blah(response)
    response.reply "bongo", "wongo"
  end

  def restricted(_response)
  end

  def web(_request, _response)
  end

  def greet(_payload)
  end

  def self.name
    "Lita::Handlers::Test"
  end
end

describe handler_class, lita_handler: true do
  it { routes("foo").to(:foo) }
  it { routes_command("blah").to(:blah) }
  it { doesnt_route("blah").to(:blah) }
  it { does_not_route("blah").to(:blah) }
  it { doesnt_route_command("yo").to(:foo) }
  it { does_not_route_command("yo").to(:foo) }
  it { routes("restricted").to(:restricted) }
  it { routes_http(:get, "web").to(:web) }
  it { doesnt_route_http(:post, "web").to(:web) }
  it { routes_event(:connected).to(:greet) }
  it { doesnt_route_event(:connected).to(:web) }
  it { does_not_route_event(:connected).to(:web) }

  describe "#foo" do
    it "replies with baz" do
      send_message("foo")
      expect(replies).to eq(["baz"])
    end
  end

  describe "#blah" do
    it "replies with bongo and wongo" do
      send_command("blah")
      expect(replies).to eq(%w(bongo wongo))
    end
  end

  it "allows the sending user to be specified" do
    another_user = Lita::User.create(2, name: "Another User")
    expect(robot).to receive(:receive) do |message|
      expect(message.source.user).to eq(another_user)
    end
    send_message("foo", as: another_user)
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
lita-3.3.1 spec/lita/rspec_spec.rb
lita-3.3.0 spec/lita/rspec_spec.rb
lita-3.2.0 spec/lita/rspec_spec.rb