spec/lita/handlers/totems_spec.rb in lita-totems-0.2.0 vs spec/lita/handlers/totems_spec.rb in lita-totems-0.3.0

- old
+ new

@@ -1,19 +1,21 @@ require "spec_helper" describe Lita::Handlers::Totems, lita_handler: true do - it { routes("totems add foo").to(:add) } - it { routes("totem add foo").to(:add) } - it { routes("totem join foo").to(:add) } - it { doesnt_route("totems add ").to(:add) } - it { doesnt_route("tote add foo").to(:add) } - it { routes("totems kick foo").to(:kick) } - it { routes("totems kick foo bob").to(:kick) } - it { routes("totems").to(:info) } - it { routes("totems info").to(:info) } - it { routes("totems info chicken").to(:info) } + it { is_expected.to route("totems add foo").to(:add) } + it { is_expected.to route("totem add foo").to(:add) } + it { is_expected.to route("totem join foo").to(:add) } + it { is_expected.to route("totems add foo message").to(:add) } + it { is_expected.not_to route("totems add ").to(:add) } + it { is_expected.not_to route("tote add foo").to(:add) } + it { is_expected.to route("totems kick foo").to(:kick) } + it { is_expected.to route("totems kick foo bob").to(:kick) } + it { is_expected.to route("totems").to(:info) } + it { is_expected.to route("totems info").to(:info) } + it { is_expected.to route("totems info chicken").to(:info) } + let(:totem_creator) { Class.new do def initialize @id = 0 end @@ -119,10 +121,29 @@ send_message("totems add chicken", as: carl) expect(replies.last).to eq('Error: you are already in the queue for "chicken".') end end + context "with a message" do + before do + Timecop.freeze("2014-03-01 12:00:00") do + send_message("totems add chicken message", as: carl) + send_message("totems add chicken other message", as: another_user) + end + end + it "includes the message in the totems' info" do + Timecop.freeze("2014-03-01 13:00:00") do + send_message("totems info chicken") + expect(replies.last).to eq <<-END +1. Carl (held for 1h) + message +2. person_1 (waiting for 1h) + other message + END + end + end + end end context "when the totem doesn't exist" do it "lets user know" do send_message("totems add chicken", as: carl) @@ -150,30 +171,32 @@ send_message("totems add chicken", as: another_user) send_message("totems add chicken", as: yet_another_user) end end it "yields that totem, gives to the next person in line" do - expect(robot).to receive(:send_messages) do |target, message| - expect(target.user.id).to eq(another_user.id) - expect(message).to eq(%{You are now in possession of totem "chicken."}) + expect(robot).to receive(:send_messages).twice do |target, message| + expect([another_user.id, carl.id]).to include(target.user.id) + if target.user.id == another_user.id + expect(message).to eq(%{You are now in possession of totem "chicken."}) + elsif target.user.id == carl.id + expect(message).to eq("You have yielded the totem to #{another_user.name}.") + end end send_message("totems yield", as: carl) - # todo: check for message to other user - expect(replies.last).to eq("You have yielded the totem to #{another_user.name}.") end it "updates the waiting since value for the new holder" do Timecop.freeze("2014-03-01 13:00:00") do send_message("totems info chicken") expect(replies.last).to eq <<-END 1. Carl (held for 2h) -2. Test User (waiting for 1h) +2. person_1 (waiting for 1h) 3. person_2 (waiting for 1h) END send_message("totems yield", as: carl) send_message("totems info chicken") expect(replies.last).to eq <<-END -1. Test User (held for 0s) +1. person_1 (held for 0s) 2. person_2 (waiting for 1h) END end end end @@ -238,22 +261,22 @@ it "yields totem and does not update holder" do Timecop.freeze("2014-03-02 14:00:00") do send_message("totems yield chicken", as: carl) expect(replies.last).to eq(%{You are no longer in line for the "chicken" totem.}) send_message("totems info chicken") - expect(replies.last).to eq("1. Test User (held for 1h)\n") + expect(replies.last).to eq("1. person_1 (held for 1h)\n") end end end end context "when not specifying a totem" do it "yields totem and does not update holder" do Timecop.freeze("2014-03-02 14:00:00") do send_message("totems yield", as: carl) expect(replies.last).to eq(%{You are no longer in line for the "chicken" totem.}) send_message("totems info chicken") - expect(replies.last).to eq("1. Test User (held for 1h)\n") + expect(replies.last).to eq("1. person_1 (held for 1h)\n") end end end end @@ -272,11 +295,11 @@ it "yields totem and does not update holder" do Timecop.freeze("2014-03-02 14:00:00") do send_message("totems yield chicken", as: carl) expect(replies.last).to eq(%{You are no longer in line for the "chicken" totem.}) send_message("totems info chicken") - expect(replies.last).to eq("1. Test User (held for 1h)\n2. person_2 (waiting for 1h)\n") + expect(replies.last).to eq("1. person_1 (held for 1h)\n2. person_2 (waiting for 1h)\n") end end end end context "when not specifying a totem" do @@ -304,11 +327,11 @@ it "yields totem and does not update holder" do Timecop.freeze("2014-03-02 14:00:00") do send_message("totems yield chicken", as: carl) expect(replies.last).to eq(%{You are no longer in line for the "chicken" totem.}) send_message("totems info chicken") - expect(replies.last).to eq("1. Test User (held for 1h)\n2. person_2 (waiting for 1h)\n") + expect(replies.last).to eq("1. person_1 (held for 1h)\n2. person_2 (waiting for 1h)\n") end end end end context "when not specifying a totem" do @@ -331,35 +354,38 @@ context "there is a user owning the totem and somebody else waiting for it" do before do send_message("totems add chicken", as: another_user) send_message("totems add chicken", as: carl) end - it "should notify that user that she has been kicked" do - expect(robot).to receive(:send_messages) do |target, message| - expect(target.user.id).to eq(another_user.id) - expect(message).to eq(%{You have been kicked from totem "chicken".}) - end - send_message("totems kick chicken") + it "should notify that user that she has been kicked, and notify the next user she now has the totem" do + expect(robot).to receive(:send_messages).twice do |target, message| + expect([another_user.id, carl.id]).to include(target.user.id) + if target.user.id == carl.id + expect(message).to eq(%{You are now in possession of totem "chicken".}) + elsif target.user.id == another_user.id + expect(message).to eq(%{You have been kicked from totem "chicken".}) + end + end + send_message("totems kick chicken", as: carl) end - it "should notify next user in line that she now has the totem" do - send_message("totems kick chicken") - expect(replies.last).to eq(%{You are now in possession of totem "chicken".}) - end end context "there is a user owning the totem" do before do send_message("totems add chicken", as: carl) end it "should notify that user that she has been kicked and clear the owning_user_id" do - expect(robot).to receive(:send_messages) do |target, message| - expect(target.user.id).to eq(carl.id) - expect(message).to eq(%{You have been kicked from totem "chicken".}) + expect(robot).to receive(:send_messages).twice do |target, message| + expect([another_user.id, carl.id]).to include(target.user.id) + if target.user.id == carl.id + expect(message).to eq(%{You have been kicked from totem "chicken".}) + elsif target.user.id == another_user.id + expect(message).to eq("") + end end send_message("totems kick chicken") send_message("totems info chicken") - expect(replies.last).to eq "" end end context "nobody owns that totem" do it "sends an error" do @@ -386,11 +412,11 @@ it "shows info for just that totem" do Timecop.freeze("2014-03-01 13:00:00") do send_message("totems info chicken") expect(replies.last).to eq <<-END 1. Carl (held for 1h) -2. Test User (waiting for 1h) +2. person_1 (waiting for 1h) 3. person_2 (waiting for 1h) END end end end @@ -400,10 +426,10 @@ Timecop.freeze("2014-03-02 13:00:00") do send_message("totems info") expect(replies.last).to include <<-END - chicken 1. Carl (held for 1d 1h) - 2. Test User (waiting for 1d 1h) + 2. person_1 (waiting for 1d 1h) 3. person_2 (waiting for 1d 1h) END expect(replies.last).to include <<-END - duck 1. person_2 (held for 1d 1h)