Browse files

Contact#inspect output should be nice even without an email

  • Loading branch information...
1 parent b149eed commit 461962f70684086b28998e09b5158e80575a7f58 @mislav committed Jan 9, 2009
Showing with 11 additions and 3 deletions.
  1. +1 −1 lib/contacts.rb
  2. +10 −2 spec/contact_spec.rb
View
2 lib/contacts.rb
@@ -20,7 +20,7 @@ def email
end
def inspect
- %!#<Contacts::Contact "#{name}" (#{email})>!
+ %!#<Contacts::Contact "#{name}"#{email ? " (#{email})" : ''}>!
end
end
View
12 spec/contact_spec.rb
@@ -24,10 +24,18 @@
it "should have username" do
@contact.username.should == 'maxpower'
end
-
- it "should have nice inspect" do
+ end
+
+ describe '#inspect' do
+ it "should be nice" do
+ @contact = Contacts::Contact.new('max@example.com', 'Max Power', 'maxpower')
@contact.inspect.should == '#<Contacts::Contact "Max Power" (max@example.com)>'
end
+
+ it "should be nice without email" do
+ @contact = Contacts::Contact.new(nil, 'Max Power', 'maxpower')
+ @contact.inspect.should == '#<Contacts::Contact "Max Power">'
+ end
end
end

0 comments on commit 461962f

Please sign in to comment.