test/activity_spec.rb in friends-0.0.3 vs test/activity_spec.rb in friends-0.0.4
- old
+ new
@@ -72,11 +72,14 @@
describe "#highlight_friends" do
let(:friend1) { Friends::Friend.new(name: "Elizabeth Cady Stanton") }
let(:friend2) { Friends::Friend.new(name: "John Cage") }
let(:friends) { [friend1, friend2] }
let(:description) { "Lunch with #{friend1.name} and #{friend2.name}." }
- subject { activity.highlight_friends(friends: friends) }
+ let(:introvert) { Minitest::Mock.new }
+ subject do
+ activity.highlight_friends(introvert: introvert, friends: friends)
+ end
it "finds all friends" do
subject
activity.description.
must_equal "Lunch with **#{friend1.name}** and **#{friend2.name}**."
@@ -85,74 +88,64 @@
it "matches friends' first names" do
activity = Friends::Activity.new(
date_s: Date.today.to_s,
description: "Lunch with Elizabeth and John."
)
- activity.highlight_friends(friends: friends)
+ activity.highlight_friends(introvert: introvert, friends: friends)
activity.description.
must_equal "Lunch with **#{friend1.name}** and **#{friend2.name}**."
end
it "matches without case sensitivity" do
activity = Friends::Activity.new(
date_s: Date.today.to_s,
description: "Lunch with elizabeth cady stanton."
)
- activity.highlight_friends(friends: friends)
+ activity.highlight_friends(introvert: introvert, friends: friends)
activity.description.
must_equal "Lunch with **Elizabeth Cady Stanton**."
end
- it "ignores when there are multiple matches" do
- friend2.name = "Elizabeth II"
- activity = Friends::Activity.new(
- date_s: Date.today.to_s,
- description: "Dinner with Elizabeth."
- )
- activity.highlight_friends(friends: friends)
- activity.description.must_equal "Dinner with Elizabeth." # No match found.
- end
-
it "ignores when at beginning of word" do
activity = Friends::Activity.new(
date_s: Date.today.to_s,
description: "Field trip to the Johnson Co."
)
- activity.highlight_friends(friends: friends)
+ activity.highlight_friends(introvert: introvert, friends: friends)
# No match found.
activity.description.must_equal "Field trip to the Johnson Co."
end
it "ignores when in middle of word" do
activity = Friends::Activity.new(
date_s: Date.today.to_s,
description: "Field trip to the JimJohnJames Co."
)
- activity.highlight_friends(friends: friends)
+ activity.highlight_friends(introvert: introvert, friends: friends)
# No match found.
activity.description.must_equal "Field trip to the JimJohnJames Co."
end
it "ignores when at end of word" do
activity = Friends::Activity.new(
date_s: Date.today.to_s,
description: "Field trip to the JimJohn Co."
)
- activity.highlight_friends(friends: friends)
+ activity.highlight_friends(introvert: introvert, friends: friends)
# No match found.
activity.description.must_equal "Field trip to the JimJohn Co."
end
it "does not match with leading asterisks" do
activity = Friends::Activity.new(
date_s: Date.today.to_s,
description: "Dinner with **Elizabeth Cady Stanton."
)
- activity.highlight_friends(friends: friends)
+ activity.highlight_friends(introvert: introvert, friends: friends)
# No match found.
activity.description.must_equal "Dinner with **Elizabeth Cady Stanton."
end
@@ -162,13 +155,33 @@
# Note: for now we can't guarantee that "Elizabeth Cady Stanton**" won't
# match, because the Elizabeth isn't surrounded by asterisks.
description: "Dinner with Elizabeth**."
)
- activity.highlight_friends(friends: friends)
+ activity.highlight_friends(introvert: introvert, friends: friends)
# No match found.
activity.description.must_equal "Dinner with Elizabeth**."
+ end
+
+ it "chooses the better friend when there are multiple matches" do
+ friend2.name = "Elizabeth II"
+ activity = Friends::Activity.new(
+ date_s: Date.today.to_s,
+ description: "Dinner with Elizabeth."
+ )
+
+ # Pretend the introvert sets the friends' n_activities values.
+ introvert.expect(:set_n_activities!, nil)
+ friend1.n_activities = 5
+ friend2.n_activities = 7
+
+ activity.highlight_friends(introvert: introvert, friends: friends)
+
+ # Pick the friend with more activities.
+ activity.description.must_equal "Dinner with **Elizabeth II**."
+
+ # introvert.verify
end
end
describe "#friend_names" do
subject { activity.friend_names }