Sha256: fed61d563672be06baeafcefc940da8a8057a9a7ffe63620565f2735f82a9ef3

Contents?: true

Size: 1.45 KB

Versions: 4

Compression:

Stored size: 1.45 KB

Contents

# frozen_string_literal: true

require "spec_helper"

describe Lita::Handler, lita_handler: true do
  before { registry.handlers.delete(described_class) }

  prepend_before(after_config: true) do
    registry.register_handler(:foo) do
      config :foo_response, required: true, type: String

      after_config do |config|
        route(/foo/) do |response|
          response.reply(config.foo_response)
        end
      end
    end
  end

  it "includes chat routes" do
    registry.register_handler(:foo) do
      route(/foo/) do |response|
        response.reply("bar")
      end
    end

    send_message("foo")

    expect(replies.last).to include("bar")
  end

  it "includes HTTP routes" do
    registry.register_handler(:foo) do
      http.get "foo" do |_request, response|
        response.write("bar")
      end
    end

    http_client = Faraday::Connection.new { |c| c.adapter(:rack, Lita::RackApp.new(robot)) }
    response = http_client.get("/foo")

    expect(response.body).to eq("bar")
  end

  it "includes event routes" do
    registry.register_handler(:foo) do
      on(:some_event) { robot.send_message("payload received") }
    end

    expect(robot).to receive(:send_message).with("payload received")

    robot.trigger(:some_event)
  end

  it "runs the after_config block configuration is finalized", after_config: true do
    registry.config.handlers.foo.foo_response = "baz"

    send_message("foo")

    expect(replies.last).to include("baz")
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

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