Skip to content

Commit 461962f

Browse files
committed
Contact#inspect output should be nice even without an email
1 parent b149eed commit 461962f

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

lib/contacts.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def email
2020
end
2121

2222
def inspect
23-
%!#<Contacts::Contact "#{name}" (#{email})>!
23+
%!#<Contacts::Contact "#{name}"#{email ? " (#{email})" : ''}>!
2424
end
2525
end
2626

spec/contact_spec.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,18 @@
2424
it "should have username" do
2525
@contact.username.should == 'maxpower'
2626
end
27-
28-
it "should have nice inspect" do
27+
end
28+
29+
describe '#inspect' do
30+
it "should be nice" do
31+
@contact = Contacts::Contact.new('[email protected]', 'Max Power', 'maxpower')
2932
@contact.inspect.should == '#<Contacts::Contact "Max Power" ([email protected])>'
3033
end
34+
35+
it "should be nice without email" do
36+
@contact = Contacts::Contact.new(nil, 'Max Power', 'maxpower')
37+
@contact.inspect.should == '#<Contacts::Contact "Max Power">'
38+
end
3139
end
3240

3341
end

0 commit comments

Comments
 (0)