-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathtest.rb
232 lines (184 loc) · 6.06 KB
/
test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
def test(title, &b)
begin
if b
result = b.call
if result.is_a?(Array)
puts "fail: #{title}"
puts " expected #{result.first} to equal #{result.last}"
elsif result
puts "pass: #{title}"
else
puts "fail: #{title}"
end
else
puts "pending: #{title}"
end
rescue => e
puts "fail: #{title}"
puts e
end
end
def assert(statement)
!!statement
end
def assert_equal(actual, expected)
if expected == actual
true
else
[expected, actual]
end
end
# Part 1: Object Models
# Create a Class for song, artist, and genre. Use an individual file for each class.
# These files should be placed within a lib directory and required on the top of
# any script that utilizes them (including this test script). Once required
# all the tests within this suite should pass.
# Artist Specs
test 'Can initialize an Artist' do
assert Artist.new
end
test 'An artist can have a name' do
artist = Artist.new
artist.name = "Adele"
assert_equal artist.name, "Adele"
end
test "An artist has songs" do
artist = Artist.new
artist.songs = []
assert_equal artist.songs, []
end
test 'The Artist class can reset the artists that have been created' do
assert Artist.reset_artists
assert_equal Artist.count, 0
end
test 'The Artist class can keep track of artists as they are created' do
Artist.reset_artists
artist = Artist.new
assert Artist.all.include?(artist)
end
test 'The Artist class can count how many artists have been created' do
assert Artist.count
end
test 'artists have songs' do
artist = Artist.new
songs = (1..4).collect{|i| Song.new}
artist.songs = songs
assert_equal artist.songs, songs
end
test 'An artist can count how many songs they have' do
artist = Artist.new
songs = [Song.new, Song.new]
artist.songs = songs
assert_equal artist.songs_count, 2
end
test 'a song can be added to an artist' do
artist = Artist.new
song = Song.new
artist.add_song(song)
assert artist.songs.include?(song)
end
test 'artists have genres' do
artist = Artist.new
song = Song.new
song.genre = Genre.new.tap{|g| g.name = "rap"}
artist.add_song(song)
assert artist.genres.include?(song.genre)
end
# Genre Specs
test 'Can initialize a genre' do
assert Genre.new
end
test 'A genre has a name' do
genre = Genre.new
genre.name = 'rap'
assert_equal genre.name, 'rap'
end
test 'A genre has many songs' do
genre = Genre.new.tap{|g| g.name = 'rap'}
[1,2].each do
song = Song.new
song.genre = genre
end
assert_equal genre.songs.count, 2
end
test 'A genre has many artists' do
genre = Genre.new.tap{|g| g.name = 'rap'}
[1,2].each do
artist = Artist.new
song = Song.new
song.genre = genre
artist.add_song(song)
end
assert_equal genre.artists.count, 2
end
test 'A genres Artists are unique' do
genre = Genre.new.tap{|g| g.name = 'rap'}
artist = Artist.new
[1,2].each do
song = Song.new
song.genre = genre
artist.add_song(song)
end
assert_equal genre.artists.count, 1
end
# Same behavior as Artists
test 'The Genre class can keep track of all created genres' do
Genre.reset_genres # You must implement a method like this
genres = [1..5].collect do |i|
Genre.new
end
assert_equal Genre.all, genres
end
# Extra Credit
# Complete any song test that is pending (undefined).
# The functionality described must still be present to complete the assignment
# so even if you do not complete the pending specs, they must pass in my complete
# test suite. There's no way you'd be able to accomplish the site generation
# without your song class having this functionality, so go ahead and try
# to use assert and assert_equal to write some tests.
test 'Can initialize a song'
test 'A song can have a name'
test 'A song can have a genre'
test 'A song has an artist'
# Part 2: Site Generation Using ERB
# write a ruby script that parses the data within the data directory
# and uses the classes defined above to instantiate Song, Artist, and Genres
# for each file. These instances should be correctly associated to each other
# so that artist.genre will return a Genre object, etc.
# This script should additionally Generate a website that has the following sections:
# An index page that links to the two sections of the sites, artists and genres
# site/index.html
# links to artists.html
# links to genres.html
# This index page does not need to be generated by the application, you can just manually
# create it.
# Templates should be generated via ERB files located in lib/views.
# site/artists.html
# The artist index must list all the artists. This list must be sorted alphabetically.
# In addition to the Artists name, the artists total song count should be displayed.
# The artist name should link to the artists individual page within site/artists.
# This page should also say how many Artists there are in total.
# artists/<artist>.html
# The script must generate an artist page for each individual artist that was created
# during import. An artists page should list the name of the artist along with their songs
# and genres. The songs and genres must link to the individual song and genre page.
# M83 - 8 Songs
# 1. Midnight City - Folk
# 2. Kim & Jesse - Pop
# genres.html
# The genre index must list all the genres. This list must be sorted by the amount of songs.
# In addition to the Genres name, the total song and artist count should be listed along side it.
# The genre name should linke to the genres individual page within site/genres.
# Folk: 8 Songs, 3 Artists
# genres/<genre>.html
# The script must generate a genre page for each individual genre that was created
# during import. A genres page should list the name of the songs, linking to the individual
# song and artists. Also include the total unique artists and song counts in the genre.
# Folk
# M83 - Midnight City
# Lady Gaga - Pokerface
# songs/<song>.html
# The song page should list all the available information on the song, it's artist and genre
# with the appropriate links.
# Extra Credit:
# Use a ruby module somewhere to refactor common functionality.