friends 0.35 → 0.36
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/CHANGELOG.md +20 -0
- data/README.md +103 -6
- data/bin/friends +12 -16
- data/lib/friends/commands/add.rb +5 -17
- data/lib/friends/commands/edit.rb +13 -2
- data/lib/friends/commands/list.rb +4 -4
- data/lib/friends/commands/remove.rb +2 -4
- data/lib/friends/commands/rename.rb +2 -4
- data/lib/friends/commands/set.rb +1 -2
- data/lib/friends/commands/stats.rb +1 -7
- data/lib/friends/commands/suggest.rb +1 -8
- data/lib/friends/commands/update.rb +12 -13
- data/lib/friends/event.rb +2 -2
- data/lib/friends/introvert.rb +122 -110
- data/lib/friends/version.rb +1 -1
- data/test/commands/clean_spec.rb +88 -1
- data/test/commands/edit_spec.rb +125 -17
- data/test/commands/rename/friend_spec.rb +7 -0
- data/test/commands/rename/location_spec.rb +8 -0
- data/test/commands/set/location_spec.rb +2 -2
- data/test/editor +15 -0
- data/test/helper.rb +2 -2
- metadata +4 -2
data/lib/friends/version.rb
CHANGED
data/test/commands/clean_spec.rb
CHANGED
@@ -3,7 +3,8 @@
|
|
3
3
|
require "./test/helper"
|
4
4
|
|
5
5
|
clean_describe "clean" do
|
6
|
-
subject { run_cmd("clean") }
|
6
|
+
subject { run_cmd("#{quiet} clean") }
|
7
|
+
let(:quiet) { nil }
|
7
8
|
let(:content) { nil }
|
8
9
|
|
9
10
|
it "outputs a message" do
|
@@ -29,6 +30,32 @@ clean_describe "clean" do
|
|
29
30
|
|
30
31
|
### Friends:
|
31
32
|
|
33
|
+
### Locations:
|
34
|
+
FILE
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "when file is missing some headers and sections are out of order" do
|
39
|
+
let(:content) do
|
40
|
+
<<-CONTENT
|
41
|
+
### Friends:
|
42
|
+
- Marie Curie
|
43
|
+
|
44
|
+
### Activities:
|
45
|
+
- 2016-01-01: Celebrated the new year with **Marie Curie**.
|
46
|
+
CONTENT
|
47
|
+
end
|
48
|
+
|
49
|
+
it "adds the missing file structure and reorders the sections" do
|
50
|
+
file_equals <<-FILE
|
51
|
+
### Activities:
|
52
|
+
- 2016-01-01: Celebrated the new year with **Marie Curie**.
|
53
|
+
|
54
|
+
### Notes:
|
55
|
+
|
56
|
+
### Friends:
|
57
|
+
- Marie Curie
|
58
|
+
|
32
59
|
### Locations:
|
33
60
|
FILE
|
34
61
|
end
|
@@ -41,6 +68,66 @@ clean_describe "clean" do
|
|
41
68
|
it "writes the file with contents sorted" do
|
42
69
|
file_equals CONTENT
|
43
70
|
end
|
71
|
+
|
72
|
+
describe "when the content includes friends and locations that have not yet been added" do
|
73
|
+
let(:content) do
|
74
|
+
<<-CONTENT
|
75
|
+
### Activities:
|
76
|
+
- 2017-01-01: Celebrated the new year in _Paris_ with **Marie Curie** and her husband **Pierre Curie**. **Marie Curie** loves _Paris_!
|
77
|
+
|
78
|
+
### Notes:
|
79
|
+
- 2017-01-01: I just learned that **Jacques Cousteau** is thinking about moving from _Gironde_ to _The Lost City of Atlantis_ (_Gironde_ did seem a bit too terrestrial for him).
|
80
|
+
|
81
|
+
### Friends:
|
82
|
+
- Grace Hopper [NYC]
|
83
|
+
|
84
|
+
### Locations:
|
85
|
+
- NYC
|
86
|
+
CONTENT
|
87
|
+
end
|
88
|
+
|
89
|
+
it "adds those friends and locations" do
|
90
|
+
file_equals <<-CONTENT
|
91
|
+
### Activities:
|
92
|
+
- 2017-01-01: Celebrated the new year in _Paris_ with **Marie Curie** and her husband **Pierre Curie**. **Marie Curie** loves _Paris_!
|
93
|
+
|
94
|
+
### Notes:
|
95
|
+
- 2017-01-01: I just learned that **Jacques Cousteau** is thinking about moving from _Gironde_ to _The Lost City of Atlantis_ (_Gironde_ did seem a bit too terrestrial for him).
|
96
|
+
|
97
|
+
### Friends:
|
98
|
+
- Grace Hopper [NYC]
|
99
|
+
- Jacques Cousteau
|
100
|
+
- Marie Curie
|
101
|
+
- Pierre Curie
|
102
|
+
|
103
|
+
### Locations:
|
104
|
+
- Gironde
|
105
|
+
- NYC
|
106
|
+
- Paris
|
107
|
+
- The Lost City of Atlantis
|
108
|
+
CONTENT
|
109
|
+
end
|
110
|
+
|
111
|
+
it "prints messages for both cleaning and adding friends/locations" do
|
112
|
+
stdout_only <<-OUTPUT
|
113
|
+
Friend added: \"Marie Curie\"
|
114
|
+
Friend added: \"Pierre Curie\"
|
115
|
+
Location added: \"Paris\"
|
116
|
+
Friend added: \"Jacques Cousteau\"
|
117
|
+
Location added: \"Gironde\"
|
118
|
+
Location added: \"The Lost City of Atlantis\"
|
119
|
+
File cleaned: \"#{filename}\"
|
120
|
+
OUTPUT
|
121
|
+
end
|
122
|
+
|
123
|
+
describe "when output is quieted" do
|
124
|
+
let(:quiet) { "--quiet" }
|
125
|
+
|
126
|
+
it "prints no messages" do
|
127
|
+
stdout_only ""
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
44
131
|
end
|
45
132
|
|
46
133
|
describe "when a header is malformed" do
|
data/test/commands/edit_spec.rb
CHANGED
@@ -3,25 +3,133 @@
|
|
3
3
|
require "./test/helper"
|
4
4
|
|
5
5
|
clean_describe "edit" do
|
6
|
-
subject
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
6
|
+
subject { run_cmd("#{quiet} edit", env_vars: "EDITOR=#{editor}") }
|
7
|
+
|
8
|
+
let(:content) { SCRAMBLED_CONTENT }
|
9
|
+
let(:editor) { "cat" }
|
10
|
+
|
11
|
+
# First we test some simple behavior using `cat` as our "editor."
|
12
|
+
describe "when output is quieted" do
|
13
|
+
let(:quiet) { "--quiet" }
|
14
|
+
|
15
|
+
it 'opens the file in the "editor"' do
|
16
|
+
stdout_only content
|
17
|
+
end
|
18
|
+
|
19
|
+
it "cleans the file" do
|
20
|
+
file_equals CONTENT # File is cleaned (no longer scrambled).
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "when output is not quieted" do
|
25
|
+
let(:quiet) { nil }
|
26
|
+
|
27
|
+
# Since our "editor" is just `cat`, our STDOUT output will include both the opening
|
28
|
+
# message and the contents of the file.
|
29
|
+
it 'prints a message and opens the file in the "editor"' do
|
30
|
+
stdout_only "Opening \"#{filename}\" with \"#{editor}\""\
|
31
|
+
"\n#{content}File cleaned: \"#{filename}\""
|
32
|
+
end
|
33
|
+
|
34
|
+
it "cleans the file" do
|
35
|
+
file_equals CONTENT # File is cleaned (no longer scrambled).
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "when editor does not exit successfully" do
|
40
|
+
let(:editor) { "'exit 1 #'" }
|
41
|
+
|
42
|
+
describe "when output is quieted" do
|
43
|
+
let(:quiet) { "--quiet" }
|
44
|
+
|
45
|
+
it "prints nothing to STDOUT" do
|
46
|
+
stdout_only ""
|
47
|
+
end
|
48
|
+
|
49
|
+
it "does not clean the file" do
|
50
|
+
file_equals content
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "when output is not quieted" do
|
55
|
+
let(:quiet) { nil }
|
56
|
+
|
57
|
+
it "prints a status message to STDOUT" do
|
58
|
+
stdout_only <<-OUTPUT
|
59
|
+
Opening "#{filename}" with "exit 1 #"
|
60
|
+
Not cleaning file: "#{filename}" ("exit 1 #" did not exit successfully)
|
61
|
+
OUTPUT
|
62
|
+
end
|
63
|
+
|
64
|
+
it "does not clean the file" do
|
65
|
+
file_equals content
|
66
|
+
end
|
67
|
+
end
|
15
68
|
end
|
16
69
|
|
17
|
-
|
70
|
+
# Now we test a more realistic scenario, in which the editor actually modifies the
|
71
|
+
# file. Instead of human interaction we use the `test/editor` file to serve as our
|
72
|
+
# editor; that script adds a new activity to the file with a friend name and location
|
73
|
+
# name that are not currently in the file. This tests the fact that `friends edit`
|
74
|
+
# should clean the `friends.md` file *after* the editor has closed successfully.
|
75
|
+
describe "when edit operation adds an event that includes a new friend or location" do
|
76
|
+
let(:editor) { "test/editor" }
|
77
|
+
let(:cleaned_edited_content) do
|
78
|
+
<<-EXPECTED_CONTENT
|
79
|
+
### Activities:
|
80
|
+
- 2015-11-01: **Grace Hopper** and I went to _Marie's Diner_. George had to cancel at the last minute. @food
|
81
|
+
- 2015-01-04: Got lunch with **Grace Hopper** and **George Washington Carver**. @food
|
82
|
+
- 2014-12-31: Celebrated the new year in _Paris_ with **Marie Curie**. @partying
|
83
|
+
- 2014-12-15: I just had a possible **Bigfoot** sighting! I think I may have seen **Bigfoot** in the _Mysterious Mountains_.
|
84
|
+
- 2014-11-15: Talked to **George Washington Carver** on the phone for an hour.
|
85
|
+
|
86
|
+
### Notes:
|
87
|
+
- 2017-03-12: **Marie Curie** completed her PhD in record time. @school
|
88
|
+
- 2015-06-15: **Grace Hopper** found out she's getting a big Naval Academy building named after her. @navy
|
89
|
+
- 2015-06-06: **Marie Curie** just got accepted into a PhD program in _Paris_. @school
|
90
|
+
- 2015-01-04: **Grace Hopper** and **George Washington Carver** both won an award.
|
91
|
+
|
92
|
+
### Friends:
|
93
|
+
- Bigfoot
|
94
|
+
- George Washington Carver
|
95
|
+
- Grace Hopper (a.k.a. The Admiral a.k.a. Amazing Grace) [Paris] @navy @science
|
96
|
+
- Marie Curie [Atlantis] @science
|
97
|
+
|
98
|
+
### Locations:
|
99
|
+
- Atlantis
|
100
|
+
- Marie's Diner
|
101
|
+
- Mysterious Mountains
|
102
|
+
- Paris
|
103
|
+
EXPECTED_CONTENT
|
104
|
+
end
|
105
|
+
|
106
|
+
describe "when output is quieted" do
|
107
|
+
let(:quiet) { "--quiet" }
|
108
|
+
|
109
|
+
it "prints nothing to STDOUT" do
|
110
|
+
stdout_only ""
|
111
|
+
end
|
112
|
+
|
113
|
+
it "cleans the file after the editor has quit" do
|
114
|
+
file_equals cleaned_edited_content
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
describe "when output is not quieted" do
|
119
|
+
let(:quiet) { nil }
|
120
|
+
|
121
|
+
it "prints status messages to STDOUT" do
|
122
|
+
stdout_only <<-OUTPUT
|
123
|
+
Opening "#{filename}" with "#{editor}"
|
124
|
+
Friend added: "Bigfoot"
|
125
|
+
Location added: "Mysterious Mountains"
|
126
|
+
File cleaned: "#{filename}"
|
127
|
+
OUTPUT
|
128
|
+
end
|
18
129
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
# our test here can check that STDOUT is equivalent to the `Kernel.exec` command's
|
24
|
-
# output, even though visually that's not what happens.
|
25
|
-
stdout_only content
|
130
|
+
it "cleans the file after the editor has quit" do
|
131
|
+
file_equals cleaned_edited_content
|
132
|
+
end
|
133
|
+
end
|
26
134
|
end
|
27
135
|
end
|
@@ -48,6 +48,13 @@ clean_describe "rename friend" do
|
|
48
48
|
FILE
|
49
49
|
end
|
50
50
|
|
51
|
+
it "updates friend name in notes" do
|
52
|
+
line_changed(
|
53
|
+
"- 2015-01-04: **Grace Hopper** and **George Washington Carver** both won an award.",
|
54
|
+
"- 2015-01-04: **Grace Hopper** and **George Washington** both won an award."
|
55
|
+
)
|
56
|
+
end
|
57
|
+
|
51
58
|
it "prints an output message" do
|
52
59
|
stdout_only 'Name changed: "George Washington"'
|
53
60
|
end
|
@@ -29,6 +29,14 @@ clean_describe "rename location" do
|
|
29
29
|
)
|
30
30
|
end
|
31
31
|
|
32
|
+
it "updates location name in notes" do
|
33
|
+
line_changed(
|
34
|
+
"- 2015-06-06: **Marie Curie** just got accepted into a PhD program in _Paris_. @school",
|
35
|
+
"- 2015-06-06: **Marie Curie** just got accepted into a PhD program in "\
|
36
|
+
"_Ville Lumière_. @school"
|
37
|
+
)
|
38
|
+
end
|
39
|
+
|
32
40
|
it "updates location name for friends" do
|
33
41
|
line_changed(
|
34
42
|
"- Grace Hopper (a.k.a. The Admiral a.k.a. Amazing Grace) [Paris] @navy @science",
|
@@ -31,7 +31,7 @@ clean_describe "set location" do
|
|
31
31
|
let(:friend_name) { "Marie" }
|
32
32
|
|
33
33
|
it "prints correct output" do
|
34
|
-
stdout_only "Marie Curie's location set to: Paris"
|
34
|
+
stdout_only "Marie Curie's location set to: \"Paris\""
|
35
35
|
end
|
36
36
|
|
37
37
|
it "updates existing location" do
|
@@ -43,7 +43,7 @@ clean_describe "set location" do
|
|
43
43
|
let(:friend_name) { "George" }
|
44
44
|
|
45
45
|
it "prints correct output" do
|
46
|
-
stdout_only "George Washington Carver's location set to: Paris"
|
46
|
+
stdout_only "George Washington Carver's location set to: \"Paris\""
|
47
47
|
end
|
48
48
|
|
49
49
|
it "adds a location" do
|
data/test/editor
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# This is an example "editor" used to test the `friends edit` command.
|
4
|
+
# It inserts a new activity into the second line of the file, allowing
|
5
|
+
# us to test that friends and locations added in an `edit` command are
|
6
|
+
# subsequently added during the `clean` stage after the editor closes.
|
7
|
+
|
8
|
+
filename = ARGV[0]
|
9
|
+
current_file_contents = File.read(filename).split("\n")
|
10
|
+
File.open(filename, "w") do |file|
|
11
|
+
file.puts current_file_contents[0]
|
12
|
+
file.puts "- 2014-12-15: I just had a possible **Bigfoot** sighting! "\
|
13
|
+
"I think I may have seen **Bigfoot** in the _Mysterious Mountains_."
|
14
|
+
file.puts current_file_contents.drop(1)
|
15
|
+
end
|
data/test/helper.rb
CHANGED
@@ -79,9 +79,9 @@ def filename; end
|
|
79
79
|
|
80
80
|
def subject; end
|
81
81
|
|
82
|
-
def run_cmd(command, **args)
|
82
|
+
def run_cmd(command, env_vars: "", **args)
|
83
83
|
stdout, stderr, status = Open3.capture3(
|
84
|
-
"bundle exec bin/friends --colorless --filename #{filename} #{command}",
|
84
|
+
"#{env_vars} bundle exec bin/friends --colorless --filename #{filename} #{command}",
|
85
85
|
**args
|
86
86
|
)
|
87
87
|
{
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: friends
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.36'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jacob Evelyn
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-01-
|
11
|
+
date: 2018-01-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: chronic
|
@@ -237,6 +237,7 @@ files:
|
|
237
237
|
- test/commands/stats_spec.rb
|
238
238
|
- test/commands/suggest_spec.rb
|
239
239
|
- test/commands/update_spec.rb
|
240
|
+
- test/editor
|
240
241
|
- test/helper.rb
|
241
242
|
- test/tmp/.keep
|
242
243
|
homepage: https://github.com/JacobEvelyn/friends
|
@@ -290,6 +291,7 @@ test_files:
|
|
290
291
|
- test/commands/stats_spec.rb
|
291
292
|
- test/commands/suggest_spec.rb
|
292
293
|
- test/commands/update_spec.rb
|
294
|
+
- test/editor
|
293
295
|
- test/helper.rb
|
294
296
|
- test/tmp/.keep
|
295
297
|
has_rdoc:
|