Class: TestContacts

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
lib/public/doc/plain-text-files/contacts_y_test.rb

Instance Method Summary collapse

Instance Method Details

#setupObject



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/public/doc/plain-text-files/contacts_y_test.rb', line 6

def setup
  @filename = "contacts.yaml"
  @list = ContactList.new(@filename)
  @contact = Contact.new("Joe Smith")
  
  @contact.email = "[email protected]"
  @contact.home[:street1] = "123 Main Street"
  @contact.home[:city] = "Somewhere"
  @contact.work[:phone] = "(000) 123-4567"
  @contact.extras[:instrument] = "Cello"
  
  @list << @contact
end

#test_delete_contact_from_listObject



25
26
27
28
29
# File 'lib/public/doc/plain-text-files/contacts_y_test.rb', line 25

def test_delete_contact_from_list
  assert(!@list.empty?)
  @list.delete(@contact.name)
  assert(@list.empty?)
end

#test_retrieve_contact_from_listObject



20
21
22
23
# File 'lib/public/doc/plain-text-files/contacts_y_test.rb', line 20

def test_retrieve_contact_from_list
  contact = @list["Joe Smith"]
  assert_equal("Joe Smith", contact.name)
end

#test_save_and_load_listObject



31
32
33
34
35
36
37
# File 'lib/public/doc/plain-text-files/contacts_y_test.rb', line 31

def test_save_and_load_list
  @list.save
  relist = ContactList.load(@filename)
  assert_equal(1, relist.size)
  contact = relist["Joe Smith"]
  assert_equal("Joe Smith", contact.name)
end