-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfirst_cake_spec.rb
64 lines (49 loc) · 1.61 KB
/
first_cake_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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
require 'rspec'
class FirstCake
attr_reader :name
def initialize(name)
@name = name
end
def self.all_da_cakes
['New York Cheesecake', 'Birthday Cake', 'Black Forest Cake', 'Ice Cream Cake', 'Fruit Cake' ].map do |name|
new(name)
end
end
end
describe 'first cake' do
subject { FirstCake.all_da_cakes }
context '.all_da_cakes' do
specify 'returns all da cakes!' do
cake_array = []
subject.each do |cake|
cake_array << cake.name
end
expect(cake_array).to include 'Birthday Cake'
end
end
context '.first' do
specify 'returns the first object in the array' do
expect(subject.first.name).to eql 'New York Cheesecake'
end
specify 'does not return the last object in the array' do
expect(subject.first.name).to_not eql 'Fruit Cake'
end
specify 'returns nil if there is no element' do
expect([].first).to eql nil
end
end
context '.first(n)' do
specify 'returns the first two objects in the array' do
array = subject.first(2).map(&:name)
expect(array).to eql ['New York Cheesecake', 'Birthday Cake']
end
specify 'returns the first three objects in the array' do
array = subject.first(3).map(&:name)
expect(array).to eql ['New York Cheesecake', 'Birthday Cake', 'Black Forest Cake']
end
specify 'does not return moar cake than is available' do
array = subject.first(100).map(&:name)
expect(array).to eql ['New York Cheesecake', 'Birthday Cake', 'Black Forest Cake', 'Ice Cream Cake', 'Fruit Cake' ]
end
end
end