test/friend_spec.rb in friends-0.0.1 vs test/friend_spec.rb in friends-0.0.2
- old
+ new
@@ -1,11 +1,46 @@
require_relative "helper"
describe Friends::Friend do
- describe "#name" do
- subject { Friends::Friend.new(name: "Jacob") }
+ let(:name) { "Jacob Evelyn" }
+ let(:friend) { Friends::Friend.new(name: name) }
- it "returns name" do
- subject.name.must_equal "Jacob"
+ describe ".deserialize" do
+ subject { Friends::Friend.deserialize(serialized_str) }
+
+ describe "when string is well-formed" do
+ let(:serialized_str) do
+ "#{Friends::Friend::SERIALIZATION_PREFIX}#{name}"
+ end
+
+ it "creates a friend with the correct name" do
+ subject.name.must_equal name
+ end
+ end
+
+ describe "when string is malformed" do
+ let(:serialized_str) { "" }
+
+ it { proc { subject }.must_raise Serializable::SerializationError }
+ end
+ end
+
+ describe "#new" do
+ subject { friend }
+
+ it { subject.name.must_equal name }
+ end
+
+ describe "#serialize" do
+ subject { friend.serialize }
+
+ it { subject.must_equal "#{Friends::Friend::SERIALIZATION_PREFIX}#{name}" }
+ end
+
+ describe "#<=>" do
+ it "sorts alphabetically" do
+ aaron = Friends::Friend.new(name: "Aaron")
+ zeke = Friends::Friend.new(name: "Zeke")
+ [zeke, aaron].sort.must_equal [aaron, zeke]
end
end
end