-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathto_a_spec.rb
48 lines (38 loc) · 1.09 KB
/
to_a_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'
class Tam
attr_reader :obsession, :face, :intelligence
def initialize(obsession, face, intelligence)
@obsession = obsession
@face = face
@intelligence = intelligence
end
def characteristics
{
obsessions: @obsession,
face: @face,
intelligence: @intelligence
}
end
describe '#to_a' do
let(:tarn_shoes) {Tam.new("kitchen towelz", "dumb cake face", false)}
it "returns an array" do
result = tarn_shoes.characteristics.to_a
expect(result).to eq [[:obsessions, "kitchen towelz"], [:face, "dumb cake face"], [:intelligence, false]]
end
it "returns an array if called on an array" do
array = ["hallo", "rubycorns"]
result = array.to_a
expect(result).to eq ["hallo", "rubycorns"]
end
class MyArray
# normally that should be the representation of the object that makes sense
def to_a
['torn', 'shoes']
end
end
it "is used to convert custom objects to an array" do
object = MyArray.new
expect(object.to_a).to eq ['torn', 'shoes']
end
end
end