ppl 4.0.1 → 4.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/build.yml +1 -0
- data/features/step_definitions/ppl_steps.rb +3 -3
- data/ppl.gemspec +1 -1
- data/spec/ppl/adapter/color/colored_spec.rb +3 -3
- data/spec/ppl/adapter/email_scraper/mail_spec.rb +13 -13
- data/spec/ppl/adapter/output_spec.rb +7 -7
- data/spec/ppl/adapter/storage/disk_spec.rb +18 -18
- data/spec/ppl/adapter/storage/factory_spec.rb +3 -3
- data/spec/ppl/adapter/storage/git_spec.rb +31 -31
- data/spec/ppl/adapter/storage_spec.rb +3 -3
- data/spec/ppl/adapter/vcard/greencard_spec.rb +45 -45
- data/spec/ppl/application/bootstrap_spec.rb +128 -128
- data/spec/ppl/application/command_spec.rb +8 -8
- data/spec/ppl/application/command_suite_spec.rb +7 -7
- data/spec/ppl/application/configuration_spec.rb +16 -16
- data/spec/ppl/application/input_spec.rb +2 -2
- data/spec/ppl/application/router_spec.rb +8 -8
- data/spec/ppl/application/shell_spec.rb +39 -39
- data/spec/ppl/command/add_spec.rb +6 -6
- data/spec/ppl/command/age_spec.rb +7 -7
- data/spec/ppl/command/attribute_spec.rb +22 -22
- data/spec/ppl/command/bday_spec.rb +11 -11
- data/spec/ppl/command/completion_spec.rb +7 -7
- data/spec/ppl/command/email_spec.rb +19 -19
- data/spec/ppl/command/external_spec.rb +7 -7
- data/spec/ppl/command/help_spec.rb +15 -15
- data/spec/ppl/command/init_spec.rb +5 -5
- data/spec/ppl/command/ls_spec.rb +12 -12
- data/spec/ppl/command/mutt_spec.rb +33 -33
- data/spec/ppl/command/mv_spec.rb +11 -11
- data/spec/ppl/command/name_spec.rb +17 -17
- data/spec/ppl/command/nick_spec.rb +1 -1
- data/spec/ppl/command/org_spec.rb +1 -1
- data/spec/ppl/command/phone_spec.rb +15 -15
- data/spec/ppl/command/post_spec.rb +29 -29
- data/spec/ppl/command/rm_spec.rb +3 -3
- data/spec/ppl/command/scrape_spec.rb +24 -24
- data/spec/ppl/command/shell_spec.rb +41 -41
- data/spec/ppl/command/show_spec.rb +4 -4
- data/spec/ppl/command/url_spec.rb +1 -1
- data/spec/ppl/command/version_spec.rb +4 -4
- data/spec/ppl/entity/address_book_spec.rb +1 -1
- data/spec/ppl/entity/contact_spec.rb +16 -16
- data/spec/ppl/entity/email_address_spec.rb +3 -3
- data/spec/ppl/entity/name_spec.rb +1 -1
- data/spec/ppl/entity/phone_number_spec.rb +5 -5
- data/spec/ppl/entity/postal_address_spec.rb +2 -2
- data/spec/ppl/format/address_book/ages_spec.rb +3 -3
- data/spec/ppl/format/address_book/birthdays_spec.rb +3 -3
- data/spec/ppl/format/address_book/email_addresses_spec.rb +3 -3
- data/spec/ppl/format/address_book/mutt_query_spec.rb +3 -3
- data/spec/ppl/format/address_book/names_spec.rb +3 -3
- data/spec/ppl/format/address_book/nicknames_spec.rb +4 -4
- data/spec/ppl/format/address_book/one_line_spec.rb +5 -5
- data/spec/ppl/format/address_book/organizations_spec.rb +3 -3
- data/spec/ppl/format/address_book/phone_numbers_spec.rb +3 -3
- data/spec/ppl/format/address_book/postal_addresses_spec.rb +2 -2
- data/spec/ppl/format/address_book/urls_spec.rb +3 -3
- data/spec/ppl/format/contact/age_spec.rb +8 -8
- data/spec/ppl/format/contact/birthday_spec.rb +4 -4
- data/spec/ppl/format/contact/email_addresses_spec.rb +3 -3
- data/spec/ppl/format/contact/full_spec.rb +11 -11
- data/spec/ppl/format/contact/nicknames_spec.rb +4 -4
- data/spec/ppl/format/contact/organization_spec.rb +4 -4
- data/spec/ppl/format/contact/phone_number_spec.rb +4 -4
- data/spec/ppl/format/contact/postal_address_spec.rb +1 -1
- data/spec/ppl/format/contact/postal_addresses_spec.rb +3 -3
- data/spec/ppl/format/contact/urls_spec.rb +4 -4
- data/spec/ppl/format/custom/contact_spec.rb +13 -13
- data/spec/ppl/format/custom/email_address_spec.rb +3 -3
- data/spec/ppl/format/custom/phone_number_spec.rb +4 -4
- data/spec/ppl/format/custom_spec.rb +6 -6
- data/spec/ppl/format/name/full_only_spec.rb +4 -4
- data/spec/ppl/format/postal_address/multi_line_spec.rb +10 -10
- data/spec/ppl/format/postal_address/one_line_spec.rb +9 -9
- data/spec/ppl/format/table_spec.rb +11 -11
- data/spec/ppl/service/email_address_spec.rb +13 -13
- data/spec/ppl/service/name_spec.rb +9 -9
- data/spec/ppl/service/phone_number_spec.rb +11 -11
- data/spec/ppl/service/postal_address_spec.rb +20 -20
- data/spec/spec_helper.rb +3 -0
- metadata +1 -1
data/spec/ppl/command/mv_spec.rb
CHANGED
@@ -13,7 +13,7 @@ describe Ppl::Command::Mv do
|
|
13
13
|
|
14
14
|
describe "#name" do
|
15
15
|
it "should be 'mv'" do
|
16
|
-
@command.name.
|
16
|
+
expect(@command.name).to eq "mv"
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
@@ -30,24 +30,24 @@ describe Ppl::Command::Mv do
|
|
30
30
|
end
|
31
31
|
|
32
32
|
it "should return false if the new id is taken" do
|
33
|
-
@storage.
|
34
|
-
@storage.
|
35
|
-
@output.
|
33
|
+
expect(@storage).to receive(:require_contact).with("old").and_return(@contact)
|
34
|
+
expect(@storage).to receive(:load_contact).with("new").and_return(@contact)
|
35
|
+
expect(@output).to receive(:error)
|
36
36
|
@input.arguments = ["old", "new"]
|
37
37
|
|
38
|
-
@command.execute(@input, @output).
|
38
|
+
expect(@command.execute(@input, @output)).to eq false
|
39
39
|
end
|
40
40
|
|
41
41
|
it "should rename the given contact" do
|
42
|
-
@storage.
|
43
|
-
@storage.
|
42
|
+
expect(@storage).to receive(:require_contact).with("old").and_return(@contact)
|
43
|
+
expect(@storage).to receive(:load_contact).with("new").and_return(nil)
|
44
44
|
|
45
|
-
@storage.
|
46
|
-
contact.id.
|
45
|
+
expect(@storage).to receive(:delete_contact).with(@contact) do |contact|
|
46
|
+
expect(contact.id).to eq "old"
|
47
47
|
end
|
48
48
|
|
49
|
-
@storage.
|
50
|
-
contact.id.
|
49
|
+
expect(@storage).to receive(:save_contact).with(@contact) do |contact|
|
50
|
+
expect(contact.id).to eq "new"
|
51
51
|
end
|
52
52
|
|
53
53
|
@input.arguments = ["old", "new"]
|
@@ -24,51 +24,51 @@ describe Ppl::Command::Name do
|
|
24
24
|
|
25
25
|
describe "#name" do
|
26
26
|
it "should be 'name'" do
|
27
|
-
@command.name.
|
27
|
+
expect(@command.name).to eq "name"
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
31
|
describe "#execute" do
|
32
32
|
|
33
33
|
it "should list all contact names if no contact ID is given" do
|
34
|
-
@storage.
|
35
|
-
@list_format.
|
36
|
-
@output.
|
34
|
+
expect(@storage).to receive(:load_address_book).and_return(@address_book)
|
35
|
+
expect(@list_format).to receive(:process).and_return("all the names")
|
36
|
+
expect(@output).to receive(:line).with("all the names")
|
37
37
|
@input.arguments = []
|
38
38
|
@command.execute(@input, @output)
|
39
39
|
end
|
40
40
|
|
41
41
|
it "should show the specified contact's name if no name is given" do
|
42
|
-
@storage.
|
43
|
-
@show_format.
|
44
|
-
@output.
|
42
|
+
expect(@storage).to receive(:require_contact).and_return(@contact)
|
43
|
+
expect(@show_format).to receive(:process).and_return("John Doe")
|
44
|
+
expect(@output).to receive(:line).with("John Doe")
|
45
45
|
@input.arguments = ["jim"]
|
46
|
-
@command.execute(@input, @output).
|
46
|
+
expect(@command.execute(@input, @output)).to eq true
|
47
47
|
end
|
48
48
|
|
49
49
|
it "should not output anything if there's nothing to show" do
|
50
|
-
@storage.
|
51
|
-
@show_format.
|
50
|
+
expect(@storage).to receive(:require_contact).and_return(@contact)
|
51
|
+
expect(@show_format).to receive(:process).and_return("")
|
52
52
|
@input.arguments = ["jim"]
|
53
|
-
@command.execute(@input, @output).
|
53
|
+
expect(@command.execute(@input, @output)).to eq false
|
54
54
|
end
|
55
55
|
|
56
56
|
it "should change the contact's name if a name is given" do
|
57
|
-
@storage.
|
58
|
-
@name_service.
|
57
|
+
expect(@storage).to receive(:require_contact).and_return(@contact)
|
58
|
+
expect(@name_service).to receive(:update).with(@contact.name, {
|
59
59
|
:full => "Jim Jamieson"
|
60
60
|
})
|
61
|
-
@storage.
|
61
|
+
expect(@storage).to receive(:save_contact)
|
62
62
|
@input.arguments = ["jim", "Jim Jamieson"]
|
63
63
|
@command.execute(@input, @output)
|
64
64
|
end
|
65
65
|
|
66
66
|
it "should change the contact's name if a name is given" do
|
67
|
-
@storage.
|
68
|
-
@name_service.
|
67
|
+
expect(@storage).to receive(:require_contact).and_return(@contact)
|
68
|
+
expect(@name_service).to receive(:update).with(@contact.name, {
|
69
69
|
:family => "Smith"
|
70
70
|
})
|
71
|
-
@storage.
|
71
|
+
expect(@storage).to receive(:save_contact)
|
72
72
|
@input.arguments = ["jim"]
|
73
73
|
@input.options = { :family => "Smith" }
|
74
74
|
@command.execute(@input, @output)
|
@@ -6,7 +6,7 @@ describe Ppl::Command::Phone do
|
|
6
6
|
|
7
7
|
describe "#name" do
|
8
8
|
it "should be 'phone'" do
|
9
|
-
@command.name.
|
9
|
+
expect(@command.name).to eq "phone"
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
@@ -20,8 +20,8 @@ describe Ppl::Command::Phone do
|
|
20
20
|
@show_format = double(Ppl::Format::Contact)
|
21
21
|
@input = Ppl::Application::Input.new
|
22
22
|
@output = double(Ppl::Application::Output)
|
23
|
-
@storage.
|
24
|
-
@storage.
|
23
|
+
allow(@storage).to receive(:require_contact).and_return(@contact)
|
24
|
+
allow(@storage).to receive(:save_contact)
|
25
25
|
@command.phone_service = @service
|
26
26
|
@command.storage = @storage
|
27
27
|
@command.list_format = @list_format
|
@@ -29,40 +29,40 @@ describe Ppl::Command::Phone do
|
|
29
29
|
end
|
30
30
|
|
31
31
|
it "should list all phone numbers by default" do
|
32
|
-
@storage.
|
33
|
-
@list_format.
|
34
|
-
@output.
|
32
|
+
expect(@storage).to receive(:load_address_book).and_return(@address_book)
|
33
|
+
expect(@list_format).to receive(:process)
|
34
|
+
expect(@output).to receive(:line)
|
35
35
|
@command.execute(@input, @output)
|
36
36
|
end
|
37
37
|
|
38
38
|
it "should show a single contact's numbers if one is specified" do
|
39
39
|
@input.arguments << "jdoe"
|
40
|
-
@storage.
|
41
|
-
@show_format.
|
42
|
-
@output.
|
40
|
+
expect(@storage).to receive(:require_contact).and_return(@contact)
|
41
|
+
expect(@show_format).to receive(:process)
|
42
|
+
expect(@output).to receive(:line)
|
43
43
|
@command.execute(@input, @output)
|
44
44
|
end
|
45
45
|
|
46
46
|
it "should delegate to the service layer to remove a phone number" do
|
47
47
|
@input.arguments = ["jdoe", "01234567890"]
|
48
48
|
@input.options[:delete] = true
|
49
|
-
@storage.
|
50
|
-
@service.
|
49
|
+
expect(@storage).to receive(:require_contact).and_return(@contact)
|
50
|
+
expect(@service).to receive(:remove).with(@contact, "01234567890")
|
51
51
|
@command.execute(@input, @output)
|
52
52
|
end
|
53
53
|
|
54
54
|
it "should delegate to the service layer to add a new phone number" do
|
55
55
|
@input.arguments = ["jdoe", "98776332"]
|
56
|
-
@storage.
|
57
|
-
@service.
|
56
|
+
expect(@storage).to receive(:require_contact).and_return(@contact)
|
57
|
+
expect(@service).to receive(:add).with(@contact, "98776332", @input.options)
|
58
58
|
@command.execute(@input, @output)
|
59
59
|
end
|
60
60
|
|
61
61
|
it "should delegate to the service layer to update an existing number" do
|
62
62
|
@contact.phone_numbers << Ppl::Entity::PhoneNumber.new("012345678")
|
63
63
|
@input.arguments = ["jdoe", "012345678"]
|
64
|
-
@storage.
|
65
|
-
@service.
|
64
|
+
expect(@storage).to receive(:require_contact).and_return(@contact)
|
65
|
+
expect(@service).to receive(:update).with(@contact, "012345678", {})
|
66
66
|
@command.execute(@input, @output)
|
67
67
|
end
|
68
68
|
|
@@ -26,7 +26,7 @@ describe Ppl::Command::Post do
|
|
26
26
|
|
27
27
|
describe "#name" do
|
28
28
|
it "should be 'post'" do
|
29
|
-
@command.name.
|
29
|
+
expect(@command.name).to eq "post"
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
@@ -37,9 +37,9 @@ describe Ppl::Command::Post do
|
|
37
37
|
before { @input.arguments = [] }
|
38
38
|
|
39
39
|
it "displays postal address information for the whole address book" do
|
40
|
-
@storage.
|
41
|
-
@address_book_format.
|
42
|
-
@output.
|
40
|
+
expect(@storage).to receive(:load_address_book).and_return(@address_book)
|
41
|
+
expect(@address_book_format).to receive(:process).and_return("all the postal addresses")
|
42
|
+
expect(@output).to receive(:line).with("all the postal addresses")
|
43
43
|
@input.arguments = []
|
44
44
|
@command.execute(@input, @output)
|
45
45
|
end
|
@@ -50,16 +50,16 @@ describe Ppl::Command::Post do
|
|
50
50
|
before { @input.arguments = ["jim"] }
|
51
51
|
|
52
52
|
it "shows all of a contact's postal addresses" do
|
53
|
-
@storage.
|
54
|
-
@contact_format.
|
55
|
-
@output.
|
56
|
-
@command.execute(@input, @output).
|
53
|
+
expect(@storage).to receive(:require_contact).and_return(@contact)
|
54
|
+
expect(@contact_format).to receive(:process).and_return("1 Test Road")
|
55
|
+
expect(@output).to receive(:line).with("1 Test Road")
|
56
|
+
expect(@command.execute(@input, @output)).to eq true
|
57
57
|
end
|
58
58
|
|
59
59
|
it "outputs nothing if the contact has no addresses" do
|
60
|
-
@storage.
|
61
|
-
@contact_format.
|
62
|
-
@command.execute(@input, @output).
|
60
|
+
expect(@storage).to receive(:require_contact).and_return(@contact)
|
61
|
+
expect(@contact_format).to receive(:process).and_return("")
|
62
|
+
expect(@command.execute(@input, @output)).to eq false
|
63
63
|
end
|
64
64
|
|
65
65
|
end
|
@@ -69,16 +69,16 @@ describe Ppl::Command::Post do
|
|
69
69
|
before { @input.arguments = ["jim", "home"] }
|
70
70
|
|
71
71
|
it "shows a single postal address" do
|
72
|
-
@storage.
|
73
|
-
@postal_address_format.
|
74
|
-
@output.
|
75
|
-
@command.execute(@input, @output).
|
72
|
+
expect(@storage).to receive(:require_contact).and_return(@contact)
|
73
|
+
expect(@postal_address_format).to receive(:process).with(@address).and_return("1 Test Road")
|
74
|
+
expect(@output).to receive(:line).with("1 Test Road")
|
75
|
+
expect(@command.execute(@input, @output)).to eq true
|
76
76
|
end
|
77
77
|
|
78
78
|
it "raises an error if there's no such address" do
|
79
79
|
@input.arguments[1] = "other"
|
80
|
-
@storage.
|
81
|
-
expect{@command.execute(@input, @output).
|
80
|
+
expect(@storage).to receive(:require_contact).and_return(@contact)
|
81
|
+
expect{expect(@command.execute(@input, @output)).to eq true}.to raise_error(Ppl::Error::PostalAddressNotFound)
|
82
82
|
end
|
83
83
|
|
84
84
|
end
|
@@ -89,10 +89,10 @@ describe Ppl::Command::Post do
|
|
89
89
|
before { @input.options = { :delete => true }}
|
90
90
|
|
91
91
|
it "deletes the postal address" do
|
92
|
-
@storage.
|
93
|
-
@service.
|
94
|
-
@storage.
|
95
|
-
@command.execute(@input, @output).
|
92
|
+
expect(@storage).to receive(:require_contact).and_return(@contact)
|
93
|
+
expect(@service).to receive(:remove).with(@contact, "home")
|
94
|
+
expect(@storage).to receive(:save_contact)
|
95
|
+
expect(@command.execute(@input, @output)).to eq true
|
96
96
|
end
|
97
97
|
|
98
98
|
end
|
@@ -103,10 +103,10 @@ describe Ppl::Command::Post do
|
|
103
103
|
before { @input.options = { :country => "New Country" }}
|
104
104
|
|
105
105
|
it "updates the postal address" do
|
106
|
-
@storage.
|
107
|
-
@service.
|
108
|
-
@storage.
|
109
|
-
@command.execute(@input, @output).
|
106
|
+
expect(@storage).to receive(:require_contact).and_return(@contact)
|
107
|
+
expect(@service).to receive(:update).with(@contact, "home", {:country => "New Country"})
|
108
|
+
expect(@storage).to receive(:save_contact)
|
109
|
+
expect(@command.execute(@input, @output)).to eq true
|
110
110
|
end
|
111
111
|
|
112
112
|
end
|
@@ -118,10 +118,10 @@ describe Ppl::Command::Post do
|
|
118
118
|
before { @input.options = { :street => "123 Swim St" }}
|
119
119
|
|
120
120
|
it "adds the postal address" do
|
121
|
-
@storage.
|
122
|
-
@service.
|
123
|
-
@storage.
|
124
|
-
@command.execute(@input, @output).
|
121
|
+
expect(@storage).to receive(:require_contact).and_return(@contact)
|
122
|
+
expect(@service).to receive(:add).with(@contact, "newaddress", {:street => "123 Swim St"})
|
123
|
+
expect(@storage).to receive(:save_contact)
|
124
|
+
expect(@command.execute(@input, @output)).to eq true
|
125
125
|
end
|
126
126
|
|
127
127
|
end
|
data/spec/ppl/command/rm_spec.rb
CHANGED
@@ -13,7 +13,7 @@ describe Ppl::Command::Rm do
|
|
13
13
|
|
14
14
|
describe "#name" do
|
15
15
|
it "should be 'rm'" do
|
16
|
-
@command.name.
|
16
|
+
expect(@command.name).to eq "rm"
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
@@ -25,8 +25,8 @@ describe Ppl::Command::Rm do
|
|
25
25
|
end
|
26
26
|
|
27
27
|
it "should delete the given contact" do
|
28
|
-
@storage.
|
29
|
-
@storage.
|
28
|
+
expect(@storage).to receive(:require_contact).and_return(@contact)
|
29
|
+
expect(@storage).to receive(:delete_contact).with(@contact)
|
30
30
|
@command.execute(@input, @output)
|
31
31
|
end
|
32
32
|
|
@@ -15,68 +15,68 @@ describe Ppl::Command::Scrape do
|
|
15
15
|
|
16
16
|
describe "#name" do
|
17
17
|
it "should be 'scrape'" do
|
18
|
-
@command.name.
|
18
|
+
expect(@command.name).to eq "scrape"
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
22
|
describe "#execute" do
|
23
23
|
|
24
24
|
before(:each) do
|
25
|
-
@input.stdin.
|
26
|
-
@input.stdin.
|
27
|
-
@input.stdin.
|
28
|
-
@email_scraper.
|
29
|
-
Readline.
|
30
|
-
@storage.
|
25
|
+
allow(@input.stdin).to receive(:read)
|
26
|
+
allow(@input.stdin).to receive(:reopen)
|
27
|
+
allow(@input.stdin).to receive(:eof?)
|
28
|
+
allow(@email_scraper).to receive(:scrape_contacts).and_return([])
|
29
|
+
allow(Readline).to receive(:readline).and_return("")
|
30
|
+
allow(@storage).to receive(:save_contact)
|
31
31
|
end
|
32
32
|
|
33
33
|
it "should read input from stdin" do
|
34
34
|
@input.options[:sender] = true
|
35
|
-
@input.stdin.
|
35
|
+
expect(@input.stdin).to receive(:read)
|
36
36
|
@command.execute(@input, @output)
|
37
37
|
end
|
38
38
|
|
39
39
|
it "should pass input to the email scraper" do
|
40
40
|
@input.options[:sender] = true
|
41
|
-
@email_scraper.
|
41
|
+
expect(@email_scraper).to receive(:scrape_contacts)
|
42
42
|
@command.execute(@input, @output)
|
43
43
|
end
|
44
44
|
|
45
45
|
it "shouldn't do any scraping unless told which fields to scrape" do
|
46
|
-
@email_scraper.
|
46
|
+
expect(@email_scraper).not_to receive(:scrape_contacts)
|
47
47
|
@command.execute(@input, @output)
|
48
48
|
end
|
49
49
|
|
50
50
|
it "should always save contacts if in quiet mode" do
|
51
51
|
@input.options[:sender] = true
|
52
52
|
@input.options[:quiet] = true
|
53
|
-
@email_scraper.
|
54
|
-
Readline.
|
55
|
-
@storage.
|
53
|
+
allow(@email_scraper).to receive(:scrape_contacts).and_return([@contact])
|
54
|
+
expect(Readline).not_to receive(:readline)
|
55
|
+
expect(@storage).to receive(:save_contact)
|
56
56
|
@command.execute(@input, @output)
|
57
57
|
end
|
58
58
|
|
59
59
|
it "should reopen stdin to prompt the user" do
|
60
60
|
@input.options[:sender] = true
|
61
|
-
@input.stdin.
|
62
|
-
@input.stdin.
|
63
|
-
@email_scraper.
|
61
|
+
expect(@input.stdin).to receive(:eof?).and_return(true)
|
62
|
+
expect(@input.stdin).to receive(:reopen)
|
63
|
+
allow(@email_scraper).to receive(:scrape_contacts).and_return([@contact])
|
64
64
|
@command.execute(@input, @output)
|
65
65
|
end
|
66
66
|
|
67
67
|
it "should save the contact if the user approves" do
|
68
68
|
@input.options[:sender] = true
|
69
|
-
@email_scraper.
|
70
|
-
Readline.
|
71
|
-
@storage.
|
69
|
+
allow(@email_scraper).to receive(:scrape_contacts).and_return([@contact])
|
70
|
+
expect(Readline).to receive(:readline).and_return("y")
|
71
|
+
expect(@storage).to receive(:save_contact)
|
72
72
|
@command.execute(@input, @output)
|
73
73
|
end
|
74
74
|
|
75
75
|
it "should not save the contact if the user disapproves" do
|
76
76
|
@input.options[:sender] = true
|
77
|
-
@email_scraper.
|
78
|
-
Readline.
|
79
|
-
@storage.
|
77
|
+
allow(@email_scraper).to receive(:scrape_contacts).and_return([@contact])
|
78
|
+
expect(Readline).to receive(:readline).and_return("n")
|
79
|
+
expect(@storage).not_to receive(:save_contact)
|
80
80
|
@command.execute(@input, @output)
|
81
81
|
end
|
82
82
|
|
@@ -85,8 +85,8 @@ describe Ppl::Command::Scrape do
|
|
85
85
|
contact = Ppl::Entity::Contact.new
|
86
86
|
contact.name = "Test Person"
|
87
87
|
contact.email_addresses << "test@example.org"
|
88
|
-
@email_scraper.
|
89
|
-
Readline.
|
88
|
+
allow(@email_scraper).to receive(:scrape_contacts).and_return([contact])
|
89
|
+
expect(Readline).to receive(:readline).with("Add \"Test Person <test@example.org>\" to your address book [Y/n]? ")
|
90
90
|
@command.execute(@input, @output)
|
91
91
|
end
|
92
92
|
|
@@ -8,16 +8,16 @@ describe Ppl::Command::Shell do
|
|
8
8
|
|
9
9
|
describe "#name" do
|
10
10
|
it "should be 'shell'" do
|
11
|
-
@command.name.
|
11
|
+
expect(@command.name).to eq "shell"
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
15
|
describe "#execute" do
|
16
16
|
it "should read a line of input from stdin" do
|
17
|
-
Readline.
|
18
|
-
@command.
|
19
|
-
@command.
|
20
|
-
@command.execute(@input, @output).
|
17
|
+
expect(Readline).to receive(:readline)
|
18
|
+
allow(@command).to receive(:welcome_user)
|
19
|
+
allow(@command).to receive(:terminate_gracefully)
|
20
|
+
expect(@command.execute(@input, @output)).to eq true
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
@@ -25,73 +25,73 @@ describe Ppl::Command::Shell do
|
|
25
25
|
|
26
26
|
before(:each) do
|
27
27
|
@input.stdin = double(IO)
|
28
|
-
@input.stdin.
|
28
|
+
allow(@input.stdin).to receive(:tty?) { true }
|
29
29
|
end
|
30
30
|
|
31
31
|
it "should not show a prompt if stdin isn't a tty" do
|
32
|
-
@input.stdin.
|
33
|
-
Readline.
|
34
|
-
@command.
|
32
|
+
allow(@input.stdin).to receive(:tty?) { false }
|
33
|
+
expect(Readline).to receive(:readline).with("", true)
|
34
|
+
allow(@command).to receive(:welcome_user)
|
35
35
|
@command.execute(@input, @output)
|
36
36
|
end
|
37
37
|
|
38
38
|
it "should show a prompt if stdin is a tty" do
|
39
|
-
@input.stdin.
|
40
|
-
Readline.
|
41
|
-
@command.
|
42
|
-
@command.
|
39
|
+
allow(@input.stdin).to receive(:tty?) { true }
|
40
|
+
expect(Readline).to receive(:readline).with("ppl> ", true)
|
41
|
+
allow(@command).to receive(:welcome_user)
|
42
|
+
allow(@command).to receive(:terminate_gracefully)
|
43
43
|
@command.execute(@input, @output)
|
44
44
|
end
|
45
45
|
|
46
46
|
it "should make a system call with the input from stdin" do
|
47
|
-
Readline.
|
48
|
-
Readline.
|
49
|
-
Kernel.
|
50
|
-
command.
|
47
|
+
expect(Readline).to receive(:readline).and_return("email fred")
|
48
|
+
expect(Readline).to receive(:readline).and_return(false)
|
49
|
+
expect(Kernel).to receive(:system) do |command|
|
50
|
+
expect(command).to include "email fred"
|
51
51
|
end
|
52
|
-
@command.
|
53
|
-
@command.
|
54
|
-
@command.execute(@input, @output).
|
52
|
+
allow(@command).to receive(:welcome_user)
|
53
|
+
allow(@command).to receive(:terminate_gracefully)
|
54
|
+
expect(@command.execute(@input, @output)).to eq true
|
55
55
|
end
|
56
56
|
|
57
57
|
it "should exit on ctrl+c" do
|
58
|
-
Readline.
|
59
|
-
@command.
|
60
|
-
@command.
|
61
|
-
@command.execute(@input, @output).
|
58
|
+
expect(Readline).to receive(:readline).and_raise(Interrupt)
|
59
|
+
allow(@command).to receive(:welcome_user)
|
60
|
+
allow(@command).to receive(:terminate_gracefully)
|
61
|
+
expect(@command.execute(@input, @output)).to eq false
|
62
62
|
end
|
63
63
|
|
64
64
|
it "should print a final newline on EOF so the user's prompt looks nice" do
|
65
|
-
@input.stdin.
|
66
|
-
@output.
|
67
|
-
Readline.
|
68
|
-
@command.
|
65
|
+
allow(@input.stdin).to receive(:tty?) { true }
|
66
|
+
expect(@output).to receive(:line).with("")
|
67
|
+
expect(Readline).to receive(:readline).and_return(false)
|
68
|
+
allow(@command).to receive(:welcome_user)
|
69
69
|
@command.execute(@input, @output)
|
70
70
|
end
|
71
71
|
|
72
72
|
it "should print a final newline on error so the user's prompt looks nice" do
|
73
|
-
@input.stdin.
|
74
|
-
@output.
|
75
|
-
@command.
|
73
|
+
allow(@input.stdin).to receive(:tty?) { true }
|
74
|
+
expect(@output).to receive(:line).with("")
|
75
|
+
allow(@command).to receive(:shell).and_raise(Interrupt)
|
76
76
|
@command.execute(@input, @output)
|
77
77
|
end
|
78
78
|
|
79
79
|
it "should not print a final newline on EOF if stdin isn't a tty" do
|
80
|
-
@input.stdin.
|
81
|
-
@output.
|
82
|
-
Readline.
|
83
|
-
@command.
|
80
|
+
allow(@input.stdin).to receive(:tty?) { false }
|
81
|
+
expect(@output).not_to receive(:line).with("")
|
82
|
+
expect(Readline).to receive(:readline).and_return(false)
|
83
|
+
allow(@command).to receive(:welcome_user)
|
84
84
|
@command.execute(@input, @output)
|
85
85
|
end
|
86
86
|
|
87
87
|
it "should print a welcome message on the tty" do
|
88
|
-
@input.stdin.
|
89
|
-
@output.
|
90
|
-
line.
|
91
|
-
line.
|
88
|
+
allow(@input.stdin).to receive(:tty?) { true }
|
89
|
+
expect(@output).to receive(:line) do |line|
|
90
|
+
expect(line).to include "ppl"
|
91
|
+
expect(line).to include Ppl::Version
|
92
92
|
end
|
93
|
-
Readline.
|
94
|
-
@command.
|
93
|
+
expect(Readline).to receive(:readline).and_return(false)
|
94
|
+
allow(@command).to receive(:terminate_gracefully)
|
95
95
|
@command.execute(@input, @output)
|
96
96
|
end
|
97
97
|
|