-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsong_spec.rb
49 lines (42 loc) · 1.46 KB
/
song_spec.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
require 'rspec'
require_relative 'song'
describe Song do
describe "Song::new" do
let(:song_name) {'Blue Song'}
let(:genre_string) {'Folk'}
let(:song) { Song.new(name: song_name, genre: genre_string) }
context "with valid initialization params" do
it "is assigned an @id" do
expect(song.id).to eq(0)
end
it "is assigned the @name param" do
expect(song.name).to eq(song_name)
end
it "is assigned the @genre param" do
expect(song.genre).to eq(genre_string)
end
it "increments ::next_song_instance_id" do
next_id = song.class.next_song_instance_id
expect(next_id).to eq(song.id + 1)
end
it "uses a unique id for songs" do
song2 = Song.new(name: 'Red Song', genre: 'Punk')
expect(song2.id).not_to eq(song.id)
end
end
context "without all initialization params" do
it "errors without name keyword param" do
expect { Song.new(genre: genre_string)}.to raise_error(ArgumentError)
end
it "errors without genre keyword param" do
expect { Song.new(name: song_name)}.to raise_error(ArgumentError)
end
it "errors with empty string for name" do
expect { Song.new(name: '', genre: genre_string)}.to raise_error(RuntimeError)
end
it "errors with empty string for genre" do
expect { Song.new(name: song_name, genre: '')}.to raise_error(RuntimeError)
end
end
end
end