Sha256: 509b98fbd3df8d8d314a8ec9ac79582525917144329edfdf2509c359a03ddd2d

Contents?: true

Size: 1.78 KB

Versions: 25

Compression:

Stored size: 1.78 KB

Contents

require "spec_helper"

describe Lita::Handlers::Help, lita_handler: true do
  it { is_expected.to route_command("help").to(:help) }
  it { is_expected.to route_command("help foo").to(:help) }

  describe "#help" do
    let(:secret_handler_class) do
      Class.new(Lita::Handler) do
        route(/secret/, :secret, restrict_to: :the_nobodies, help: {
          "secret" => "no one should ever see this help message"
        })
      end
    end

    it "sends help information for all commands" do
      send_command("help")
      expect(replies.last).to match(
        /#{robot.mention_name}: help.+#{robot.mention_name}: help COMMAND/m
      )
    end

    it "sends help information for commands starting with COMMAND" do
      send_command("help help COMMAND")
      expect(replies.last).to match(/help COMMAND - Lists/)
      expect(replies.last).not_to match(/help - Lists/)
    end

    it "doesn't crash if a handler doesn't have routes" do
      event_handler = Class.new do
        extend Lita::Handler::EventRouter
      end

      registry.register_handler(event_handler)

      expect { send_command("help") }.not_to raise_error
    end

    describe "restricted routes" do
      let(:authorized_user) do
        user = Lita::User.create(2, name: "Authorized User")
        Lita::Authorization.new(robot).add_user_to_group!(user, :the_nobodies)
        user
      end

      before { registry.register_handler(secret_handler_class) }

      it "doesn't show help for commands the user doesn't have access to" do
        send_command("help")
        expect(replies.last).not_to include("secret")
      end

      it "shows help for restricted routes if the user has access" do
        send_command("help", as: authorized_user)
        expect(replies.last).to include("secret")
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 2 rubygems

Version Path
lita-4.8.0 spec/lita/handlers/help_spec.rb
lita-4.8.0.beta1 spec/lita/handlers/help_spec.rb
lita-4.7.1 spec/lita/handlers/help_spec.rb
lita-default-handlers-0.1.0 spec/lita/handlers/help_spec.rb
lita-4.7.0 spec/lita/handlers/help_spec.rb
lita-4.6.1 spec/lita/handlers/help_spec.rb
lita-4.6.0 spec/lita/handlers/help_spec.rb
lita-4.5.0 spec/lita/handlers/help_spec.rb
lita-4.4.3 spec/lita/handlers/help_spec.rb
lita-4.4.2 spec/lita/handlers/help_spec.rb
lita-4.4.1 spec/lita/handlers/help_spec.rb
lita-4.4.0 spec/lita/handlers/help_spec.rb
lita-4.3.2 spec/lita/handlers/help_spec.rb
lita-4.3.1 spec/lita/handlers/help_spec.rb
lita-4.3.0 spec/lita/handlers/help_spec.rb
lita-4.2.1 spec/lita/handlers/help_spec.rb
lita-4.2.0 spec/lita/handlers/help_spec.rb
lita-4.1.0 spec/lita/handlers/help_spec.rb
lita-4.0.4 spec/lita/handlers/help_spec.rb
lita-4.0.3 spec/lita/handlers/help_spec.rb