ppl 0.3.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. data/.gitignore +1 -0
  2. data/Gemfile +2 -0
  3. data/Gemfile.lock +4 -0
  4. data/README.md +1 -3
  5. data/lib/ppl/adapter/storage/disk.rb +27 -7
  6. data/lib/ppl/adapter/storage/factory.rb +26 -0
  7. data/lib/ppl/adapter/storage/git.rb +101 -0
  8. data/lib/ppl/adapter/storage.rb +4 -0
  9. data/lib/ppl/adapter/vcard/vpim.rb +16 -0
  10. data/lib/ppl/application/bootstrap.rb +23 -10
  11. data/lib/ppl/application/command.rb +3 -0
  12. data/lib/ppl/application/command_suite.rb +8 -0
  13. data/lib/ppl/application/configuration.rb +50 -0
  14. data/lib/ppl/application/output.rb +1 -0
  15. data/lib/ppl/application/shell.rb +21 -0
  16. data/lib/ppl/command/add.rb +34 -0
  17. data/lib/ppl/command/bday.rb +72 -0
  18. data/lib/ppl/command/email.rb +55 -0
  19. data/lib/ppl/command/help.rb +43 -0
  20. data/lib/ppl/command/init.rb +26 -0
  21. data/lib/ppl/command/ls.rb +26 -0
  22. data/lib/ppl/command/mv.rb +42 -0
  23. data/lib/ppl/command/name.rb +54 -0
  24. data/lib/ppl/command/org.rb +55 -0
  25. data/lib/ppl/command/phone.rb +55 -0
  26. data/lib/ppl/command/rm.rb +26 -0
  27. data/lib/ppl/command/show.rb +31 -0
  28. data/lib/ppl/entity/contact.rb +2 -0
  29. data/lib/ppl/format/address_book/birthdays.rb +34 -0
  30. data/lib/ppl/format/address_book/email_addresses.rb +34 -0
  31. data/lib/ppl/format/address_book/names.rb +34 -0
  32. data/lib/ppl/format/address_book/one_line.rb +34 -0
  33. data/lib/ppl/format/address_book/organizations.rb +34 -0
  34. data/lib/ppl/format/address_book/phone_numbers.rb +34 -0
  35. data/lib/ppl/format/address_book.rb +9 -0
  36. data/lib/ppl/format/contact/birthday.rb +13 -0
  37. data/lib/ppl/format/contact/email_address.rb +13 -0
  38. data/lib/ppl/format/contact/full.rb +55 -0
  39. data/lib/ppl/format/contact/name.rb +15 -0
  40. data/lib/ppl/format/contact/organization.rb +13 -0
  41. data/lib/ppl/format/contact/phone_number.rb +13 -0
  42. data/lib/ppl/format/contact.rb +9 -0
  43. data/lib/ppl/format/table.rb +48 -0
  44. data/lib/ppl.rb +33 -11
  45. data/ppl.gemspec +1 -1
  46. data/spec/ppl/adapter/storage/disk_spec.rb +57 -10
  47. data/spec/ppl/adapter/storage/factory_spec.rb +34 -0
  48. data/spec/ppl/adapter/storage/git_spec.rb +114 -0
  49. data/spec/ppl/adapter/storage_spec.rb +6 -0
  50. data/spec/ppl/adapter/vcard/vpim_spec.rb +34 -0
  51. data/spec/ppl/application/bootstrap_spec.rb +42 -4
  52. data/spec/ppl/application/command_suite_spec.rb +8 -0
  53. data/spec/ppl/application/configuration_spec.rb +32 -0
  54. data/spec/ppl/application/shell_spec.rb +4 -0
  55. data/spec/ppl/command/{contact_add_spec.rb → add_spec.rb} +2 -2
  56. data/spec/ppl/command/bday_spec.rb +56 -0
  57. data/spec/ppl/command/email_spec.rb +56 -0
  58. data/spec/ppl/command/help_spec.rb +79 -0
  59. data/spec/ppl/command/init_spec.rb +40 -0
  60. data/spec/ppl/command/ls_spec.rb +32 -0
  61. data/spec/ppl/command/mv_spec.rb +62 -0
  62. data/spec/ppl/command/name_spec.rb +59 -0
  63. data/spec/ppl/command/org_spec.rb +57 -0
  64. data/spec/ppl/command/phone_spec.rb +55 -0
  65. data/spec/ppl/command/{contact_delete_spec.rb → rm_spec.rb} +8 -2
  66. data/spec/ppl/command/{contact_show_spec.rb → show_spec.rb} +12 -6
  67. data/spec/ppl/format/address_book/birthdays_spec.rb +38 -0
  68. data/spec/ppl/format/address_book/email_addresses_spec.rb +38 -0
  69. data/spec/ppl/format/address_book/names_spec.rb +38 -0
  70. data/spec/ppl/format/address_book/one_line_spec.rb +41 -0
  71. data/spec/ppl/format/address_book/organizations_spec.rb +38 -0
  72. data/spec/ppl/format/address_book/phone_numbers_spec.rb +38 -0
  73. data/spec/ppl/format/address_book_spec.rb +18 -0
  74. data/spec/ppl/format/contact/birthday_spec.rb +23 -0
  75. data/spec/ppl/format/contact/email_address_spec.rb +23 -0
  76. data/spec/ppl/format/contact/full_spec.rb +44 -0
  77. data/spec/ppl/format/contact/name_spec.rb +23 -0
  78. data/spec/ppl/format/contact/organization_spec.rb +23 -0
  79. data/spec/ppl/format/contact/phone_number_spec.rb +23 -0
  80. data/spec/ppl/format/contact_spec.rb +17 -0
  81. data/spec/ppl/format/table_spec.rb +72 -0
  82. metadata +61 -19
  83. data/lib/ppl/command/command_list.rb +0 -21
  84. data/lib/ppl/command/contact_add.rb +0 -26
  85. data/lib/ppl/command/contact_delete.rb +0 -16
  86. data/lib/ppl/command/contact_list.rb +0 -24
  87. data/lib/ppl/command/contact_rename.rb +0 -23
  88. data/lib/ppl/command/contact_show.rb +0 -20
  89. data/lib/ppl/command/set_birthday.rb +0 -30
  90. data/lib/ppl/command/set_email.rb +0 -23
  91. data/lib/ppl/command/set_name.rb +0 -28
  92. data/spec/ppl/command/command_list_spec.rb +0 -37
  93. data/spec/ppl/command/contact_list_spec.rb +0 -15
  94. data/spec/ppl/command/contact_rename_spec.rb +0 -42
  95. data/spec/ppl/command/set_birthday_spec.rb +0 -50
  96. data/spec/ppl/command/set_email_spec.rb +0 -38
  97. data/spec/ppl/command/set_name_spec.rb +0 -45
@@ -0,0 +1,56 @@
1
+
2
+ describe Ppl::Command::Email do
3
+
4
+ before(:each) do
5
+ @input = Ppl::Application::Input.new
6
+ @output = Ppl::Application::Output.new(nil, nil)
7
+ @contact = Ppl::Entity::Contact.new
8
+ @command = Ppl::Command::Email.new
9
+ @storage = double(Ppl::Adapter::Storage)
10
+
11
+ @list_format = double(Ppl::Format::Contact)
12
+ @show_format = double(Ppl::Format::Contact)
13
+
14
+ @command.storage = @storage
15
+ @command.show_format = @show_format
16
+ @command.list_format = @list_format
17
+ @contact.id = "jim"
18
+ end
19
+
20
+ describe "#name" do
21
+ it "should be 'email'" do
22
+ @command.name.should eq "email"
23
+ end
24
+ end
25
+
26
+ describe "#execute" do
27
+
28
+ it "should list all email addresses if no contact ID is given" do
29
+ @storage.should_receive(:load_address_book).and_return(@address_book)
30
+ @list_format.should_receive(:process).and_return("all the email addresses")
31
+ @output.should_receive(:line).with("all the email addresses")
32
+ @input.arguments = []
33
+ @command.execute(@input, @output)
34
+ end
35
+
36
+ it "should show the current address if no new address is given" do
37
+ @storage.should_receive(:require_contact).and_return(@contact)
38
+ @show_format.should_receive(:process).and_return("jdoe@example.org")
39
+ @output.should_receive(:line).with("jdoe@example.org")
40
+ @input.arguments = ["jim"]
41
+ @command.execute(@input, @output)
42
+ end
43
+
44
+ it "should change the contact's email address if an address is given" do
45
+ @storage.should_receive(:require_contact).and_return(@contact)
46
+ @storage.should_receive(:save_contact) do |contact|
47
+ contact.email_address.should eq "jim@example.org"
48
+ end
49
+ @input.arguments = ["jim", "jim@example.org"]
50
+ @command.execute(@input, @output)
51
+ end
52
+
53
+ end
54
+
55
+ end
56
+
@@ -0,0 +1,79 @@
1
+
2
+ describe Ppl::Command::Help do
3
+
4
+ before(:each) do
5
+ @command = Ppl::Command::Help.new
6
+ @output = double(Ppl::Application::Output)
7
+
8
+ @command.command_suite = Ppl::Application::CommandSuite.new
9
+ end
10
+
11
+ describe "#command_suite=" do
12
+ it "should accept a value" do
13
+ suite = Object.new
14
+ @command.command_suite = suite
15
+ @command.command_suite.should be suite
16
+ end
17
+ end
18
+
19
+ describe "#name" do
20
+ it "should be 'help'" do
21
+ @command.name.should eq "help"
22
+ end
23
+ end
24
+
25
+ describe "#execute" do
26
+
27
+ it "should not list itself" do
28
+ @command.command_suite.add_command(@command)
29
+
30
+ @output.should_receive(:line).with("usage: ppl <command>")
31
+ @output.should_receive(:line).with(nil)
32
+ @output.should_receive(:line).with(nil)
33
+
34
+ @command.execute(nil, @output)
35
+ end
36
+
37
+ it "should list available commands" do
38
+ command = double(Ppl::Application::Command)
39
+ command.should_receive(:name).twice.and_return("one")
40
+ command.should_receive(:description).and_return("The first command")
41
+ @command.command_suite.add_command(command)
42
+
43
+ @output.should_receive(:line).with("usage: ppl <command>")
44
+ @output.should_receive(:line).with(nil)
45
+ @output.should_receive(:line).with(" one The first command")
46
+ @output.should_receive(:line).with(nil)
47
+
48
+ @command.execute(nil, @output)
49
+ end
50
+
51
+ it "should arrange output into columns" do
52
+ command_foo = Ppl::Application::Command.new
53
+ command_foo.name = "shortname"
54
+ command_foo.description = "This is a command with a short name"
55
+
56
+ command_bar = Ppl::Application::Command.new
57
+ command_bar.name = "veryverylongname"
58
+ command_bar.description = "This is a command with a longer name"
59
+
60
+ @command.command_suite.add_command(command_foo)
61
+ @command.command_suite.add_command(command_bar)
62
+
63
+ @output.should_receive(:line).with("usage: ppl <command>")
64
+ @output.should_receive(:line).with(nil)
65
+ [
66
+ " shortname This is a command with a short name",
67
+ " veryverylongname This is a command with a longer name",
68
+ ].each do |line|
69
+ @output.should_receive(:line).with(line)
70
+ end
71
+ @output.should_receive(:line).with(nil)
72
+
73
+ @command.execute(nil, @output)
74
+ end
75
+
76
+ end
77
+
78
+ end
79
+
@@ -0,0 +1,40 @@
1
+
2
+ describe Ppl::Command::Init do
3
+
4
+ before(:each) do
5
+ @command = Ppl::Command::Init.new
6
+ @input = Ppl::Application::Input.new
7
+ @output = Ppl::Application::Output.new(nil, nil)
8
+ end
9
+
10
+ describe "#name" do
11
+ it "should be 'init'" do
12
+ @command.name.should eq "init"
13
+ end
14
+ end
15
+
16
+ describe "#execute" do
17
+
18
+ it "should pass the given path through to the storage adapter" do
19
+ Ppl::Adapter::Storage::Git.stub(:create_address_book) do |path|
20
+ path.should eq "/contacts"
21
+ end
22
+ @input.arguments.push "/contacts"
23
+ @command.execute(@input, @output)
24
+ end
25
+
26
+ it "should pass the cwd to the storage adapter if no path is given" do
27
+ FakeFS.activate!
28
+ Dir.mkdir "/current"
29
+ Dir.chdir "/current"
30
+ Ppl::Adapter::Storage::Git.stub(:create_address_book) do |path|
31
+ path.should eq "/current"
32
+ end
33
+ @command.execute(@input, @output)
34
+ FakeFS.deactivate!
35
+ end
36
+
37
+ end
38
+
39
+ end
40
+
@@ -0,0 +1,32 @@
1
+
2
+ describe Ppl::Command::Ls do
3
+
4
+ before(:each) do
5
+ @command = Ppl::Command::Ls.new
6
+ @input = Ppl::Application::Input.new
7
+ @output = double(Ppl::Application::Output)
8
+ @storage = double(Ppl::Adapter::Storage)
9
+ @format = double(Ppl::Format::AddressBook)
10
+ @address_book = double(Ppl::Entity::AddressBook)
11
+
12
+ @command.format = @format
13
+ @command.storage = @storage
14
+ end
15
+
16
+ describe "#name" do
17
+ it "should be 'ls'" do
18
+ @command.name.should eq "ls"
19
+ end
20
+ end
21
+
22
+ describe "#execute" do
23
+ it "should show the list of contacts in the address book" do
24
+ @storage.should_receive(:load_address_book).and_return(@address_book)
25
+ @format.should_receive(:process).and_return("list of contacts")
26
+ @output.should_receive(:line).with("list of contacts")
27
+ @command.execute(@input, @output)
28
+ end
29
+ end
30
+
31
+ end
32
+
@@ -0,0 +1,62 @@
1
+
2
+ describe Ppl::Command::Mv do
3
+
4
+ before(:each) do
5
+ @command = Ppl::Command::Mv.new
6
+ @input = Ppl::Application::Input.new
7
+ @output = double(Ppl::Application::Output)
8
+ @contact = Ppl::Entity::Contact.new
9
+ @storage = double(Ppl::Adapter::Storage)
10
+
11
+ @command.storage = @storage
12
+ @contact.id = "old"
13
+ end
14
+
15
+ describe "#name" do
16
+ it "should be 'mv'" do
17
+ @command.name.should eq "mv"
18
+ end
19
+ end
20
+
21
+ describe "#execute" do
22
+
23
+ it "should raise an error if no contact is specified" do
24
+ @input.arguments = []
25
+ expect{@command.execute(@input, @output)}.to raise_error(Ppl::Error::IncorrectUsage)
26
+ end
27
+
28
+ it "should raise an error if no new ID is specified" do
29
+ @input.arguments = ["test", nil]
30
+ expect{@command.execute(@input, @output)}.to raise_error(Ppl::Error::IncorrectUsage)
31
+ end
32
+
33
+ it "should return false if the new id is taken" do
34
+ @storage.should_receive(:require_contact).with("old").and_return(@contact)
35
+ @storage.should_receive(:load_contact).with("new").and_return(@contact)
36
+ @output.should_receive(:error)
37
+ @input.arguments = ["old", "new"]
38
+
39
+ @command.execute(@input, @output).should eq false
40
+ end
41
+
42
+ it "should rename the given contact" do
43
+ @storage.should_receive(:require_contact).with("old").and_return(@contact)
44
+ @storage.should_receive(:load_contact).with("new").and_return(nil)
45
+
46
+ @storage.should_receive(:delete_contact).with(@contact) do |contact|
47
+ contact.id.should eq "old"
48
+ end
49
+
50
+ @storage.should_receive(:save_contact).with(@contact) do |contact|
51
+ contact.id.should eq "new"
52
+ end
53
+
54
+ @input.arguments = ["old", "new"]
55
+
56
+ @command.execute(@input, @output)
57
+ end
58
+
59
+ end
60
+
61
+ end
62
+
@@ -0,0 +1,59 @@
1
+
2
+ describe Ppl::Command::Name do
3
+
4
+ before(:each) do
5
+ @input = Ppl::Application::Input.new
6
+ @output = Ppl::Application::Output.new(nil, nil)
7
+ @contact = Ppl::Entity::Contact.new
8
+ @command = Ppl::Command::Name.new
9
+
10
+ @address_book = Ppl::Entity::AddressBook.new
11
+
12
+ @storage = double(Ppl::Adapter::Storage)
13
+ @show_format = double(Ppl::Format::Contact)
14
+ @list_format = double(Ppl::Format::Contact)
15
+
16
+ @command.storage = @storage
17
+ @command.show_format = @show_format
18
+ @command.list_format = @list_format
19
+
20
+ @contact.id = "jim"
21
+ end
22
+
23
+ describe "#name" do
24
+ it "should be 'name'" do
25
+ @command.name.should eq "name"
26
+ end
27
+ end
28
+
29
+ describe "#execute" do
30
+
31
+ it "should list all contact names if no contact ID is given" do
32
+ @storage.should_receive(:load_address_book).and_return(@address_book)
33
+ @list_format.should_receive(:process).and_return("all the names")
34
+ @output.should_receive(:line).with("all the names")
35
+ @input.arguments = []
36
+ @command.execute(@input, @output)
37
+ end
38
+
39
+ it "should show the specified contact's name if no name is given" do
40
+ @storage.should_receive(:require_contact).and_return(@contact)
41
+ @show_format.should_receive(:process).and_return("John Doe")
42
+ @output.should_receive(:line).with("John Doe")
43
+ @input.arguments = ["jim"]
44
+ @command.execute(@input, @output)
45
+ end
46
+
47
+ it "should change the contact's name if a name is given" do
48
+ @storage.should_receive(:require_contact).and_return(@contact)
49
+ @storage.should_receive(:save_contact) do |contact|
50
+ contact.name.should eq "Jim Jamieson"
51
+ end
52
+ @input.arguments = ["jim", "Jim Jamieson"]
53
+ @command.execute(@input, @output)
54
+ end
55
+
56
+ end
57
+
58
+ end
59
+
@@ -0,0 +1,57 @@
1
+
2
+ describe Ppl::Command::Org do
3
+
4
+ before(:each) do
5
+ @command = Ppl::Command::Org.new
6
+ @input = Ppl::Application::Input.new
7
+ @output = Ppl::Application::Output.new(nil, nil)
8
+ @contact = Ppl::Entity::Contact.new
9
+ @storage = double(Ppl::Adapter::Storage)
10
+
11
+ @show_format = double(Ppl::Format::Contact)
12
+ @list_format = double(Ppl::Format::Contact)
13
+
14
+ @command.storage = @storage
15
+ @command.show_format = @show_format
16
+ @command.list_format = @list_format
17
+
18
+ @contact.id = "tim"
19
+ end
20
+
21
+ describe "#name" do
22
+ it "should be 'org'" do
23
+ @command.name.should eq "org"
24
+ end
25
+ end
26
+
27
+ describe "#execute" do
28
+
29
+ it "should list all organizations if no contact ID is given" do
30
+ @storage.should_receive(:load_address_book).and_return(@address_book)
31
+ @list_format.should_receive(:process).and_return("all the organizations")
32
+ @output.should_receive(:line).with("all the organizations")
33
+ @input.arguments = []
34
+ @command.execute(@input, @output)
35
+ end
36
+
37
+ it "should show the contact's organization if no new organization is given" do
38
+ @storage.should_receive(:require_contact).and_return(@contact)
39
+ @show_format.should_receive(:process).and_return("Example Ltd")
40
+ @output.should_receive(:line).with("Example Ltd")
41
+ @input.arguments = ["jim"]
42
+ @command.execute(@input, @output)
43
+ end
44
+
45
+ it "should change the contact's organization if one is given" do
46
+ @storage.should_receive(:require_contact).and_return(@contact)
47
+ @storage.should_receive(:save_contact) do |contact|
48
+ contact.organization.should eq "Example Ltd"
49
+ end
50
+ @input.arguments = ["jim", "Example Ltd"]
51
+ @command.execute(@input, @output)
52
+ end
53
+
54
+ end
55
+
56
+ end
57
+
@@ -0,0 +1,55 @@
1
+
2
+ describe Ppl::Command::Phone do
3
+
4
+ before(:each) do
5
+ @command = Ppl::Command::Phone.new
6
+ @input = Ppl::Application::Input.new
7
+ @output = Ppl::Application::Output.new(nil, nil)
8
+ @contact = Ppl::Entity::Contact.new
9
+ @storage = double(Ppl::Adapter::Storage)
10
+
11
+ @show_format = double(Ppl::Format::Contact)
12
+ @list_format = double(Ppl::Format::Contact)
13
+
14
+ @command.storage = @storage
15
+ @command.show_format = @show_format
16
+ @command.list_format = @list_format
17
+ end
18
+
19
+ describe "#name" do
20
+ it "should be 'phone'" do
21
+ @command.name.should eq "phone"
22
+ end
23
+ end
24
+
25
+ describe "#execute" do
26
+
27
+ it "should list all phone numbers if no contact ID is given" do
28
+ @storage.should_receive(:load_address_book).and_return(@address_book)
29
+ @list_format.should_receive(:process).and_return("all the numbers")
30
+ @output.should_receive(:line).with("all the numbers")
31
+ @input.arguments = []
32
+ @command.execute(@input, @output)
33
+ end
34
+
35
+ it "should show the contact's phone number if no new number is given" do
36
+ @storage.should_receive(:require_contact).and_return(@contact)
37
+ @show_format.should_receive(:process).and_return("0123456789")
38
+ @output.should_receive(:line).with("0123456789")
39
+ @input.arguments = ["jim"]
40
+ @command.execute(@input, @output)
41
+ end
42
+
43
+ it "should change the contact's phone number if a number is given" do
44
+ @storage.should_receive(:require_contact).and_return(@contact)
45
+ @storage.should_receive(:save_contact) do |contact|
46
+ contact.phone_number.should eq "01234567890"
47
+ end
48
+ @input.arguments = ["jim", "01234567890"]
49
+ @command.execute(@input, @output)
50
+ end
51
+
52
+ end
53
+
54
+ end
55
+
@@ -1,13 +1,14 @@
1
1
 
2
- describe Ppl::Command::ContactDelete do
2
+ describe Ppl::Command::Rm do
3
3
 
4
4
  before(:each) do
5
+ @command = Ppl::Command::Rm.new
5
6
  @input = Ppl::Application::Input.new
6
7
  @output = Ppl::Application::Output.new(nil, nil)
7
8
  @contact = Ppl::Entity::Contact.new
8
- @command = Ppl::Command::ContactDelete.new
9
9
  @storage = double(Ppl::Adapter::Storage)
10
10
 
11
+ @input.arguments = ["test"]
11
12
  @command.storage = @storage
12
13
  end
13
14
 
@@ -19,6 +20,11 @@ describe Ppl::Command::ContactDelete do
19
20
 
20
21
  describe "#execute" do
21
22
 
23
+ it "should raise an error if the contact isn't specified" do
24
+ @input.arguments = [nil]
25
+ expect{@command.execute(@input, @output)}.to raise_error(Ppl::Error::IncorrectUsage)
26
+ end
27
+
22
28
  it "should delete the given contact" do
23
29
  @storage.should_receive(:require_contact).and_return(@contact)
24
30
  @storage.should_receive(:delete_contact).with(@contact)
@@ -1,14 +1,16 @@
1
1
 
2
- describe Ppl::Command::ContactShow do
2
+ describe Ppl::Command::Show do
3
3
 
4
4
  before(:each) do
5
- @command = Ppl::Command::ContactShow.new
5
+ @command = Ppl::Command::Show.new
6
6
  @input = Ppl::Application::Input.new
7
7
  @output = double(Ppl::Application::Output)
8
8
  @contact = Ppl::Entity::Contact.new
9
9
  @storage = double(Ppl::Adapter::Storage)
10
+ @format = double(Ppl::Format::Contact)
10
11
 
11
12
  @command.storage = @storage
13
+ @command.format = @format
12
14
  end
13
15
 
14
16
  describe "#name" do
@@ -18,15 +20,19 @@ describe Ppl::Command::ContactShow do
18
20
  end
19
21
 
20
22
  describe "#execute" do
23
+
24
+ it "should raise an error if no contact is specified" do
25
+ @input.arguments = []
26
+ expect{@command.execute(@input, @output)}.to raise_error(Ppl::Error::IncorrectUsage)
27
+ end
28
+
21
29
  it "should show the contact's name" do
22
30
  @storage.should_receive(:require_contact).and_return(@contact)
31
+ @format.should_receive(:process).and_return("John Doe")
23
32
 
24
- @contact.name = "John Doe"
25
- @contact.email_address = "johndoe@example.org"
33
+ @input.arguments = ["john"]
26
34
 
27
35
  @output.should_receive(:line).with("John Doe")
28
- @output.should_receive(:line).with("johndoe@example.org")
29
-
30
36
  @command.execute(@input, @output)
31
37
  end
32
38
  end
@@ -0,0 +1,38 @@
1
+
2
+ describe Ppl::Format::AddressBook::Birthdays do
3
+
4
+ before(:each) do
5
+ @format = Ppl::Format::AddressBook::Birthdays.new
6
+ @address_book = Ppl::Entity::AddressBook.new
7
+ @contact = Ppl::Entity::Contact.new
8
+ @table = double(Ppl::Format::Table)
9
+
10
+ @contact.id = "test"
11
+ @format.table = @table
12
+
13
+ @address_book.add_contact(@contact)
14
+ end
15
+
16
+ describe "#process" do
17
+
18
+ it "should at least show the contact's id" do
19
+ @table.should_receive(:add_row).with({
20
+ :id => "test:",
21
+ :birthday => nil,
22
+ })
23
+ @format.process(@address_book)
24
+ end
25
+
26
+ it "should show the birthday if it's available" do
27
+ @contact.birthday = Date.parse("2001-02-03")
28
+ @table.should_receive(:add_row).with({
29
+ :id => "test:",
30
+ :birthday => "2001-02-03",
31
+ })
32
+ @format.process(@address_book)
33
+ end
34
+
35
+ end
36
+
37
+ end
38
+
@@ -0,0 +1,38 @@
1
+
2
+ describe Ppl::Format::AddressBook::EmailAddresses do
3
+
4
+ before(:each) do
5
+ @format = Ppl::Format::AddressBook::EmailAddresses.new
6
+ @address_book = Ppl::Entity::AddressBook.new
7
+ @contact = Ppl::Entity::Contact.new
8
+ @table = double(Ppl::Format::Table)
9
+
10
+ @contact.id = "test"
11
+ @format.table = @table
12
+
13
+ @address_book.add_contact(@contact)
14
+ end
15
+
16
+ describe "#process" do
17
+
18
+ it "should at least show the contact's id" do
19
+ @table.should_receive(:add_row).with({
20
+ :id => "test:",
21
+ :email_address => nil,
22
+ })
23
+ @format.process(@address_book)
24
+ end
25
+
26
+ it "should show the email address if it's available" do
27
+ @contact.email_address = "jdoe@example.org"
28
+ @table.should_receive(:add_row).with({
29
+ :id => "test:",
30
+ :email_address => "jdoe@example.org",
31
+ })
32
+ @format.process(@address_book)
33
+ end
34
+
35
+ end
36
+
37
+ end
38
+
@@ -0,0 +1,38 @@
1
+
2
+ describe Ppl::Format::AddressBook::Names do
3
+
4
+ before(:each) do
5
+ @format = Ppl::Format::AddressBook::Names.new
6
+ @address_book = Ppl::Entity::AddressBook.new
7
+ @contact = Ppl::Entity::Contact.new
8
+ @table = double(Ppl::Format::Table)
9
+
10
+ @contact.id = "test"
11
+ @format.table = @table
12
+
13
+ @address_book.add_contact(@contact)
14
+ end
15
+
16
+ describe "#process" do
17
+
18
+ it "should at least show the contact's id" do
19
+ @table.should_receive(:add_row).with({
20
+ :id => "test:",
21
+ :name => nil,
22
+ })
23
+ @format.process(@address_book)
24
+ end
25
+
26
+ it "should show the name if it's available" do
27
+ @contact.name = "John Doe"
28
+ @table.should_receive(:add_row).with({
29
+ :id => "test:",
30
+ :name => "John Doe",
31
+ })
32
+ @format.process(@address_book)
33
+ end
34
+
35
+ end
36
+
37
+ end
38
+
@@ -0,0 +1,41 @@
1
+
2
+ describe Ppl::Format::AddressBook::OneLine do
3
+
4
+ before(:each) do
5
+ @format = Ppl::Format::AddressBook::OneLine.new
6
+ @address_book = Ppl::Entity::AddressBook.new
7
+ @contact = Ppl::Entity::Contact.new
8
+ @table = double(Ppl::Format::Table)
9
+
10
+ @contact.id = "test"
11
+ @format.table = @table
12
+
13
+ @address_book.add_contact(@contact)
14
+ end
15
+
16
+ describe "#process" do
17
+
18
+ it "should at least show the contact's id" do
19
+ @table.should_receive(:add_row).with({
20
+ :id => "test:",
21
+ :name => nil,
22
+ :email => nil,
23
+ })
24
+ @format.process(@address_book)
25
+ end
26
+
27
+ it "should show all the info if it's available" do
28
+ @contact.name = "John Doe"
29
+ @contact.email_address = "jdoe@example.org"
30
+ @table.should_receive(:add_row).with({
31
+ :id => "test:",
32
+ :name => "John Doe",
33
+ :email => "<jdoe@example.org>",
34
+ })
35
+ @format.process(@address_book)
36
+ end
37
+
38
+ end
39
+
40
+ end
41
+