spec/lita/rspec_spec.rb in lita-3.3.1 vs spec/lita/rspec_spec.rb in lita-4.0.0.rc1
- old
+ new
@@ -1,22 +1,23 @@
require "spec_helper"
handler_class = Class.new(Lita::Handler) do
- route(/^\w{3}$/, :foo)
- route(/^\w{4}$/, :blah, command: true)
+ route(/^message$/, :message)
+ route(/^command$/, :command, command: true)
route("restricted", :restricted, restrict_to: :some_group)
+ route("admins only", :admins_only, restrict_to: :admins)
http.get "web", :web
on :connected, :greet
- def foo(response)
- response.reply "baz"
+ def message(response)
+ response.reply(response.user.name)
end
- def blah(response)
- response.reply "bongo", "wongo"
+ def command(response)
+ response.reply("a", "command")
end
def restricted(_response)
end
@@ -30,40 +31,79 @@
"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 "routing messages" do
+ 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 "#foo" do
- it "replies with baz" do
- send_message("foo")
- expect(replies).to eq(["baz"])
+ 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) }
+ it { is_expected.not_to route_command("command").to(:not_a_command) }
+ end
+
+ describe "routing to restricted routes" do
+ it { is_expected.not_to route("restricted") }
+ it { is_expected.to route("restricted").with_authorization_for(:some_group) }
+ it { is_expected.not_to route("restricted").with_authorization_for(:wrong_group) }
+ it { is_expected.to route("admins only").with_authorization_for(:admins) }
+ it { is_expected.to route("restricted").with_authorization_for(:some_group).to(:restricted) }
+ it { is_expected.not_to route("restricted").with_authorization_for(:some_group).to(:nothing) }
+ end
+
+ describe "routing HTTP routes" do
+ it { is_expected.to route_http(:get, "web") }
+ it { is_expected.to route_http(:get, "web").to(:web) }
+ it { is_expected.not_to route_http(:get, "web").to(:message) }
+ it { is_expected.not_to route_http(:post, "web") }
+ end
+
+ describe "routing events" do
+ it { is_expected.to route_event(:connected) }
+ it { is_expected.to route_event(:connected).to(:greet) }
+ it { is_expected.not_to route_event(:not_an_event) }
+ it { is_expected.not_to route_event(:connected).to(:message) }
+ end
+
+ describe "deprecated routing syntax" do
+ before { allow(STDERR).to receive(:puts) }
+
+ it { routes("message").to(:message) }
+ it { routes_command("command").to(:command) }
+ it { doesnt_route("command").to(:command) }
+ it { does_not_route("command").to(:command) }
+ it { doesnt_route_command("not a command").to(:message) }
+ it { does_not_route_command("not a command").to(:message) }
+ 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) }
+ end
+
+ describe "#message" do
+ it "replies with a string" do
+ send_message("message")
+ expect(replies).to eq(["Test User"])
end
end
- describe "#blah" do
- it "replies with bongo and wongo" do
- send_command("blah")
- expect(replies).to eq(%w(bongo wongo))
+ describe "#command" do
+ it "replies with two strings" do
+ send_command("command")
+ expect(replies).to eq(%w(a command))
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)
+ send_message("message", as: another_user)
+ expect(replies.last).to eq("Another User")
end
end