spec/lita/message_spec.rb in lita-3.0.4 vs spec/lita/message_spec.rb in lita-3.1.0
- old
+ new
@@ -3,30 +3,32 @@
describe Lita::Message do
let(:robot) do
instance_double("Lita::Robot", name: "Lita", mention_name: "LitaBot", alias: ".")
end
+ let(:source) { instance_double("Lita::Source") }
+
subject do
- described_class.new(robot, "Hello", "Carl")
+ described_class.new(robot, "Hello", source)
end
it "has a body" do
expect(subject.body).to eq("Hello")
end
it "has a source" do
- expect(subject.source).to eq("Carl")
+ expect(subject.source).to eq(source)
end
describe "#args" do
it "returns an array of the 2nd through nth word in the message" do
- subject = described_class.new(robot, "args foo bar", "Carl")
+ subject = described_class.new(robot, "args foo bar", source)
expect(subject.args).to eq(%w(foo bar))
end
it "escapes messages that have mismatched quotes" do
- subject = described_class.new(robot, "args it's working", "Carl")
+ subject = described_class.new(robot, "args it's working", source)
expect(subject.args).to eq(%w(it's working))
end
end
describe "#command!" do
@@ -39,29 +41,29 @@
describe "#command?" do
it "is true when the message is addressed to the Robot" do
subject = described_class.new(
robot,
"#{robot.mention_name}: hello",
- "Carl"
+ source
)
expect(subject).to be_a_command
end
it "is true when the Robot's name is capitalized differently" do
subject = described_class.new(
robot,
"#{robot.mention_name.upcase}: hello",
- "Carl"
+ source
)
expect(subject).to be_a_command
end
it "is true when the Robot's alias is used" do
subject = described_class.new(
robot,
"#{robot.alias}hello",
- "Carl"
+ source
)
expect(subject).to be_a_command
end
it "is false when the message is not addressed to the Robot" do
@@ -76,11 +78,11 @@
end
end
describe "#reply" do
it "sends strings back to the source through the robot" do
- expect(robot).to receive(:send_messages).with("Carl", "foo", "bar")
+ expect(robot).to receive(:send_messages).with(source, "foo", "bar")
subject.reply("foo", "bar")
end
end
describe "#reply_privately" do
@@ -93,8 +95,15 @@
expect(robot).to receive(:send_messages) do |source, *strings|
expect(source).to be_a_private_message
expect(strings).to eq(%w(foo bar))
end
subject.reply_privately("foo", "bar")
+ end
+ end
+
+ describe "#reply_with_mention" do
+ it "prefixes strings with a user mention and sends them back to the source" do
+ expect(robot).to receive(:send_messages_with_mention).with(source, "foo", "bar")
+ subject.reply_with_mention("foo", "bar")
end
end
end