spec/lita/rspec_spec.rb in lita-4.4.3 vs spec/lita/rspec_spec.rb in lita-4.5.0
- old
+ new
@@ -1,9 +1,10 @@
require "spec_helper"
handler_class = Class.new(Lita::Handler) do
route(/^message$/, :message)
+ route(/^channel$/, :channel)
route(/^command$/, :command, command: true)
route("restricted", :restricted, restrict_to: :some_group)
route("admins only", :admins_only, restrict_to: :admins)
http.get "web", :web
@@ -12,10 +13,19 @@
def message(response)
response.reply(response.user.name)
end
+ def channel(response)
+ if (room = response.message.source.room_object)
+ response.reply(room.id)
+ response.reply(room.name)
+ else
+ response.reply("No room")
+ end
+ end
+
def command(response)
response.reply("a", "command")
end
def restricted(_response)
@@ -37,10 +47,16 @@
it { is_expected.to route("message") }
it { is_expected.to route("message").to(:message) }
it { is_expected.not_to route("message").to(:not_a_message) }
end
+ describe "routing channels" do
+ it { is_expected.to route("channel") }
+ it { is_expected.to route("channel").to(:channel) }
+ it { is_expected.not_to route("channel").to(:not_a_channel) }
+ end
+
describe "routing commands" do
it { is_expected.to route_command("command") }
it { is_expected.not_to route("command") }
it { is_expected.not_to route_command("not a command") }
it { is_expected.to route_command("command").to(:command) }
@@ -89,9 +105,21 @@
describe "#message" do
it "replies with a string" do
send_message("message")
expect(replies).to eq(["Test User"])
+ end
+ end
+
+ describe "#channel" do
+ it "replies with channel id if sent from room" do
+ room = Lita::Room.create_or_update(1, name: "Room")
+ send_message("channel", from: room)
+ expect(replies).to eq(%w(1 Room))
+ end
+ it "replies with no channel if not sent from room" do
+ send_message("channel")
+ expect(replies).to eq(["No room"])
end
end
describe "#command" do
it "replies with two strings" do