Class: GDBMTest

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

Instance Method Summary collapse

Instance Method Details

#setupObject



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

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

#teardownObject



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

def teardown
  @list.delete("Joe Smith") if @list["Joe Smith"]
end

#test_delete_a_contact_from_listObject



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

def test_delete_a_contact_from_list
  assert(!@list.empty?)
  @list.delete("Joe Smith")
  assert(@list.empty?)
  assert(@list.contact_cache.empty?)
end

#test_emailObject



42
43
44
45
# File 'lib/public/doc/plain-text-files/contacts_g_test.rb', line 42

def test_email
  contact = @list["Joe Smith"]
  assert_equal("[email protected]", contact.email)
end

#test_homeObject



37
38
39
40
# File 'lib/public/doc/plain-text-files/contacts_g_test.rb', line 37

def test_home
  contact = @list["Joe Smith"]
  assert_equal("123 Main Street", contact.home["street1"])
end

#test_non_existent_contact_is_nilObject



47
48
49
# File 'lib/public/doc/plain-text-files/contacts_g_test.rb', line 47

def test_non_existent_contact_is_nil
  assert_equal(nil, @list["Some Person"])
end

#test_retrieving_a_contact_from_listObject



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

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