Sha256: 04123f6f774d6fbe95d1b5dc4b6050e2d63ffcf3abcfd7f397ff5ee8357bb445

Contents?: true

Size: 1.61 KB

Versions: 6

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

6 entries across 6 versions & 1 rubygems

Version Path
lita-3.1.0 spec/lita/rspec_spec.rb
lita-3.0.4 spec/lita/rspec_spec.rb
lita-3.0.3 spec/lita/rspec_spec.rb
lita-3.0.2 spec/lita/rspec_spec.rb
lita-3.0.1 spec/lita/rspec_spec.rb
lita-3.0.0 spec/lita/rspec_spec.rb