-
Notifications
You must be signed in to change notification settings - Fork 2
/
avatar_test.rb
73 lines (60 loc) · 1.88 KB
/
avatar_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
require "test_helper"
class PixitarTest < Minitest::Test
def test_that_it_has_a_version_number
refute_nil ::Pixitar::VERSION
end
def setup
@avatar = Pixitar::Avatar.new
end
def test_initializer_with_default_values
assert_instance_of Pixitar::Image, @avatar.image
assert_equal "data/images", @avatar.assets_path
assert_equal "png", @avatar.image_extention
end
def test_predefined_parts_is_array
assert_kind_of Array, @avatar.face_parts
end
def test_predefined_parts_is_not_empty
refute_empty @avatar.face_parts
end
def test_predefined_genders_is_array
assert_kind_of Array, @avatar.genders
end
def test_predefined_genders_with_correct_values
assert_equal [:male, :female], @avatar.genders
end
def test_random_gender
assert_includes [:male, :female], @avatar.random_gender
end
def test_avatar_generation_with_invalid_gender
assert_raises Pixitar::Avatar::InvalidGenderError do
@avatar.generate_avatar(:human)
end
end
def test_random_asset_for_with_empty_files
assert_raises Pixitar::Avatar::MissingImageFilesError do
@avatar.stub(:assets, []) do
@avatar.send(:random_asset_for, :eye)
end
end
end
def test_random_asset_for_with_valid_files
asset = @avatar.stub(:assets, ["images/male/eye1.png"]) {
@avatar.send(:random_asset_for, :eye)
}
assert_equal "images/male/eye1.png", asset
end
def test_assets_to_return_list_of_files
assets = @avatar.stub(:path, "test/images/male/*.png") {
@avatar.send(:assets)
}
assert_kind_of Array, assets
assert_equal ["test/images/male/eye1.png"], assets
end
def test_path_generation
avatar = Pixitar::Avatar.new(Pixitar::Image.new, {assets_path: "data/images", image_extention: "png"})
avatar.stub(:gender, :male) do
assert_equal "data/images/male/*.png", avatar.send(:path)
end
end
end