friends 0.0.1 → 0.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/.gitignore +1 -0
- data/.overcommit.yml +3 -0
- data/.rubocop.yml +6 -5
- data/README.md +146 -5
- data/bin/friends +126 -2
- data/friends.gemspec +4 -3
- data/friends.md +8 -2
- data/lib/friends.rb +2 -1
- data/lib/friends/activity.rb +127 -0
- data/lib/friends/friend.rb +29 -0
- data/lib/friends/friends_error.rb +4 -0
- data/lib/friends/introvert.rb +185 -31
- data/lib/friends/serializable.rb +32 -0
- data/lib/friends/version.rb +1 -1
- data/test/activity_spec.rb +172 -0
- data/test/friend_spec.rb +39 -4
- data/test/helper.rb +2 -2
- data/test/introvert_spec.rb +213 -0
- data/test/tmp/.keep +0 -0
- metadata +35 -13
- data/lib/friends/extrovert.rb +0 -29
data/test/friend_spec.rb
CHANGED
@@ -1,11 +1,46 @@
|
|
1
1
|
require_relative "helper"
|
2
2
|
|
3
3
|
describe Friends::Friend do
|
4
|
-
|
5
|
-
|
4
|
+
let(:name) { "Jacob Evelyn" }
|
5
|
+
let(:friend) { Friends::Friend.new(name: name) }
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
describe ".deserialize" do
|
8
|
+
subject { Friends::Friend.deserialize(serialized_str) }
|
9
|
+
|
10
|
+
describe "when string is well-formed" do
|
11
|
+
let(:serialized_str) do
|
12
|
+
"#{Friends::Friend::SERIALIZATION_PREFIX}#{name}"
|
13
|
+
end
|
14
|
+
|
15
|
+
it "creates a friend with the correct name" do
|
16
|
+
subject.name.must_equal name
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "when string is malformed" do
|
21
|
+
let(:serialized_str) { "" }
|
22
|
+
|
23
|
+
it { proc { subject }.must_raise Serializable::SerializationError }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "#new" do
|
28
|
+
subject { friend }
|
29
|
+
|
30
|
+
it { subject.name.must_equal name }
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "#serialize" do
|
34
|
+
subject { friend.serialize }
|
35
|
+
|
36
|
+
it { subject.must_equal "#{Friends::Friend::SERIALIZATION_PREFIX}#{name}" }
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "#<=>" do
|
40
|
+
it "sorts alphabetically" do
|
41
|
+
aaron = Friends::Friend.new(name: "Aaron")
|
42
|
+
zeke = Friends::Friend.new(name: "Zeke")
|
43
|
+
[zeke, aaron].sort.must_equal [aaron, zeke]
|
9
44
|
end
|
10
45
|
end
|
11
46
|
end
|
data/test/helper.rb
CHANGED
@@ -0,0 +1,213 @@
|
|
1
|
+
require_relative "helper"
|
2
|
+
|
3
|
+
describe Friends::Introvert do
|
4
|
+
let(:filename) { "test/tmp/friends.md" }
|
5
|
+
let(:args) { { filename: filename } }
|
6
|
+
let(:introvert) { Friends::Introvert.new(args) }
|
7
|
+
let(:friend_names) { ["George Washington Carver", "Betsy Ross"] }
|
8
|
+
let(:friends) { friend_names.map { |name| Friends::Friend.new(name: name) } }
|
9
|
+
let(:activities) do
|
10
|
+
[
|
11
|
+
Friends::Activity.new(
|
12
|
+
date_s: Date.today.to_s,
|
13
|
+
description: "Lunch with **#{friend_names.first}** and "\
|
14
|
+
"**#{friend_names.last}**."
|
15
|
+
),
|
16
|
+
Friends::Activity.new(
|
17
|
+
date_s: (Date.today + 1).to_s,
|
18
|
+
description: "Called **#{friend_names.last}**."
|
19
|
+
)
|
20
|
+
]
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "#new" do
|
24
|
+
it "accepts all arguments" do
|
25
|
+
introvert # Build a new introvert.
|
26
|
+
|
27
|
+
# Check passed values.
|
28
|
+
introvert.filename.must_equal filename
|
29
|
+
end
|
30
|
+
|
31
|
+
it "has sane defaults" do
|
32
|
+
args.clear # Pass no arguments to the initializer.
|
33
|
+
introvert # Build a new introvert.
|
34
|
+
|
35
|
+
# Check default values.
|
36
|
+
introvert.filename.must_equal Friends::Introvert::DEFAULT_FILENAME
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "#clean" do
|
41
|
+
subject { introvert.clean }
|
42
|
+
|
43
|
+
# Delete the file that is created each time.
|
44
|
+
after { File.delete(filename) }
|
45
|
+
|
46
|
+
it "writes cleaned file" do
|
47
|
+
sorted_friends = friends.sort
|
48
|
+
unsorted_friends = sorted_friends.reverse
|
49
|
+
sorted_activities = activities.sort
|
50
|
+
unsorted_activities = sorted_activities.reverse
|
51
|
+
|
52
|
+
serialized_names = sorted_friends.map(&:serialize)
|
53
|
+
name_output = serialized_names.join("\n")
|
54
|
+
|
55
|
+
serialized_descriptions = sorted_activities.map(&:serialize)
|
56
|
+
descriptions_output = serialized_descriptions.join("\n")
|
57
|
+
|
58
|
+
expected_output =
|
59
|
+
"#{Friends::Introvert::ACTIVITIES_HEADER}\n#{descriptions_output}\n\n"\
|
60
|
+
"#{Friends::Introvert::FRIENDS_HEADER}\n#{name_output}\n"
|
61
|
+
|
62
|
+
# Read the input as unsorted, and make sure we get sorted output.
|
63
|
+
introvert.stub(:friends, unsorted_friends) do
|
64
|
+
introvert.stub(:activities, unsorted_activities) do
|
65
|
+
subject
|
66
|
+
File.read(filename).must_equal expected_output
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
it { subject.must_equal filename }
|
72
|
+
end
|
73
|
+
|
74
|
+
describe "#list_friends" do
|
75
|
+
subject { introvert.list_friends }
|
76
|
+
|
77
|
+
it "lists the names of friends" do
|
78
|
+
introvert.stub(:friends, friends) do
|
79
|
+
subject.must_equal friend_names
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe "#add_friend" do
|
85
|
+
let(:new_friend_name) { "Jacob Evelyn" }
|
86
|
+
subject { introvert.add_friend(name: new_friend_name) }
|
87
|
+
|
88
|
+
describe "when there is no existing friend with that name" do
|
89
|
+
it "adds the given friend" do
|
90
|
+
introvert.stub(:friends, friends) do
|
91
|
+
subject
|
92
|
+
introvert.list_friends.must_include new_friend_name
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
it "returns the friend added" do
|
97
|
+
introvert.stub(:friends, friends) do
|
98
|
+
subject.name.must_equal new_friend_name
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
describe "when there is an existing friend with that name" do
|
104
|
+
let(:new_friend_name) { friend_names.first }
|
105
|
+
|
106
|
+
it "raises an error" do
|
107
|
+
introvert.stub(:friends, friends) do
|
108
|
+
proc { subject }.must_raise Friends::FriendsError
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
describe "#list_activities" do
|
115
|
+
subject { introvert.list_activities(with: with) }
|
116
|
+
|
117
|
+
describe "when not filtering by a friend" do
|
118
|
+
let(:with) { nil }
|
119
|
+
|
120
|
+
it "lists the activities" do
|
121
|
+
introvert.stub(:activities, activities) do
|
122
|
+
subject.must_equal activities.map(&:display_text)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
describe "when filtering by part of a friend's name" do
|
128
|
+
let(:with) { "george" }
|
129
|
+
|
130
|
+
describe "when there is more than one friend match" do
|
131
|
+
let(:friend_names) { ["George Washington Carver", "Boy George"] }
|
132
|
+
|
133
|
+
it "raises an error" do
|
134
|
+
introvert.stub(:friends, friends) do
|
135
|
+
introvert.stub(:activities, activities) do
|
136
|
+
proc { subject }.must_raise Friends::FriendsError
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
describe "when there are no friend matches" do
|
143
|
+
let(:friend_names) { ["Joe"] }
|
144
|
+
|
145
|
+
it "raises an error" do
|
146
|
+
introvert.stub(:friends, friends) do
|
147
|
+
introvert.stub(:activities, activities) do
|
148
|
+
proc { subject }.must_raise Friends::FriendsError
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
describe "when there is exactly one friend match" do
|
155
|
+
it "filters the activities by that friend" do
|
156
|
+
introvert.stub(:friends, friends) do
|
157
|
+
introvert.stub(:activities, activities) do
|
158
|
+
# Only one activity has that friend.
|
159
|
+
subject.must_equal activities[0..0].map(&:display_text)
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
describe "#add_activity" do
|
168
|
+
let(:activity_serialization) { "2014-01-01: Snorkeling with Betsy." }
|
169
|
+
let(:activity_description) { "Snorkeling with **Betsy Ross**." }
|
170
|
+
subject { introvert.add_activity(serialization: activity_serialization) }
|
171
|
+
|
172
|
+
it "adds the given activity" do
|
173
|
+
introvert.stub(:friends, friends) do
|
174
|
+
subject
|
175
|
+
introvert.activities.last.description.must_equal activity_description
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
it "returns the activity added" do
|
180
|
+
introvert.stub(:friends, friends) do
|
181
|
+
subject.description.must_equal activity_description
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
describe "#list_favorites" do
|
187
|
+
subject { introvert.list_favorites(limit: limit) }
|
188
|
+
|
189
|
+
describe "when limit is nil" do
|
190
|
+
let(:limit) { nil }
|
191
|
+
|
192
|
+
it "returns all friends in order of favoritism" do
|
193
|
+
introvert.stub(:friends, friends) do
|
194
|
+
introvert.stub(:activities, activities) do
|
195
|
+
subject.must_equal ["Betsy Ross", "George Washington Carver"]
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
describe "when there are more friends than favorites requested" do
|
202
|
+
let(:limit) { 1 }
|
203
|
+
|
204
|
+
it "returns the number of favorites requested" do
|
205
|
+
introvert.stub(:friends, friends) do
|
206
|
+
introvert.stub(:activities, activities) do
|
207
|
+
subject.must_equal ["Betsy Ross"]
|
208
|
+
end
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
data/test/tmp/.keep
ADDED
File without changes
|
metadata
CHANGED
@@ -1,29 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: friends
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jacob Evelyn
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: gli
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '2.12'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '2.12'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: memoist
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.11'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.11'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rake
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -56,16 +70,16 @@ dependencies:
|
|
56
70
|
name: codeclimate-test-reporter
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
58
72
|
requirements:
|
59
|
-
- - "
|
73
|
+
- - "~>"
|
60
74
|
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
75
|
+
version: '0.4'
|
62
76
|
type: :development
|
63
77
|
prerelease: false
|
64
78
|
version_requirements: !ruby/object:Gem::Requirement
|
65
79
|
requirements:
|
66
|
-
- - "
|
80
|
+
- - "~>"
|
67
81
|
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
82
|
+
version: '0.4'
|
69
83
|
description: Spend time with the people you care about. Introvert-tested. Extrovert-approved.
|
70
84
|
email:
|
71
85
|
- jacobevelyn@gmail.com
|
@@ -87,13 +101,18 @@ files:
|
|
87
101
|
- friends.gemspec
|
88
102
|
- friends.md
|
89
103
|
- lib/friends.rb
|
90
|
-
- lib/friends/
|
104
|
+
- lib/friends/activity.rb
|
91
105
|
- lib/friends/friend.rb
|
106
|
+
- lib/friends/friends_error.rb
|
92
107
|
- lib/friends/introvert.rb
|
108
|
+
- lib/friends/serializable.rb
|
93
109
|
- lib/friends/version.rb
|
110
|
+
- test/activity_spec.rb
|
94
111
|
- test/friend_spec.rb
|
95
112
|
- test/helper.rb
|
96
|
-
|
113
|
+
- test/introvert_spec.rb
|
114
|
+
- test/tmp/.keep
|
115
|
+
homepage: https://github.com/JacobEvelyn/friends
|
97
116
|
licenses:
|
98
117
|
- MIT
|
99
118
|
metadata: {}
|
@@ -118,5 +137,8 @@ signing_key:
|
|
118
137
|
specification_version: 4
|
119
138
|
summary: Spend time with the people you care about.
|
120
139
|
test_files:
|
140
|
+
- test/activity_spec.rb
|
121
141
|
- test/friend_spec.rb
|
122
142
|
- test/helper.rb
|
143
|
+
- test/introvert_spec.rb
|
144
|
+
- test/tmp/.keep
|
data/lib/friends/extrovert.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
# Extrovert is the public interface for the friends script. It interacts with
|
2
|
-
# an Introvert for backend computations.
|
3
|
-
|
4
|
-
require "friends/introvert"
|
5
|
-
|
6
|
-
require "thor"
|
7
|
-
|
8
|
-
module Friends
|
9
|
-
class Extrovert < Thor
|
10
|
-
def initialize(*args)
|
11
|
-
super
|
12
|
-
@introvert = Introvert.new
|
13
|
-
end
|
14
|
-
|
15
|
-
attr_reader :introvert
|
16
|
-
|
17
|
-
class_option :verbose, type: :boolean
|
18
|
-
|
19
|
-
desc "clean", "Cleans your friends.md file"
|
20
|
-
def clean
|
21
|
-
introvert.clean
|
22
|
-
end
|
23
|
-
|
24
|
-
desc "list", "List all friends"
|
25
|
-
def list
|
26
|
-
puts introvert.friends.map(&:name)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|