/
loltext_test.rb
143 lines (121 loc) · 3.52 KB
/
loltext_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
require 'test_helper'
describe Lolcommits::Plugin::Loltext do
include Lolcommits::TestHelpers::FakeIO
def plugin_name
'loltext'
end
it 'should have a name' do
::Lolcommits::Plugin::Loltext.name.must_equal plugin_name
end
it 'should run on post capturing' do
::Lolcommits::Plugin::Loltext.runner_order.must_equal [:post_capture]
end
describe 'default font' do
it 'should have the correct file permissions' do
font_permissions = File.lstat(Lolcommits::Plugin::Loltext::DEFAULT_FONT_PATH).mode & 0o777
(font_permissions == 0o644).must_equal(true,
"expected perms of 644/664 but instead got #{format '%o', font_permissions}")
end
end
describe 'with a runner' do
def runner
# a simple lolcommits runner with an empty configuration Hash
@runner ||= Lolcommits::Runner.new(
config: OpenStruct.new(read_configuration: {})
)
end
def plugin
@plugin ||= Lolcommits::Plugin::Loltext.new(runner: runner)
end
def valid_enabled_config
@config ||= OpenStruct.new(
read_configuration: {
'loltext'=> { 'enabled' => true }
}
)
end
describe 'initalizing' do
it 'should assign runner and an enabled option' do
plugin.runner.must_equal runner
plugin.options.must_equal ['enabled']
end
end
describe '#enabled?' do
it 'should be true by default' do
plugin.enabled?.must_equal true
end
it 'should true when configured' do
plugin.config = valid_enabled_config
plugin.enabled?.must_equal true
end
end
describe 'configuration' do
it 'should not be configured by default' do
plugin.configured?.must_equal false
end
it 'should allow plugin options to be configured' do
# enabled
inputs = ['true']
# styling message and sha
inputs += %w(
red
myfont.ttf
SE
38
orange
true
) * 2
# styling overlay
inputs += %w(true #2884ae,#7e231f 40)
# border options
inputs += %w(#e96d46 true 23)
configured_plugin_options = {}
fake_io_capture(inputs: inputs) do
configured_plugin_options = plugin.configure_options!
end
configured_plugin_options.must_equal( {
"enabled" => true,
message: {
color: 'red',
font: 'myfont.ttf',
position: 'SE',
size: 38,
stroke_color: 'orange',
uppercase: true
},
sha: {
color: 'red',
font: 'myfont.ttf',
position: 'SE',
size: 38,
stroke_color: 'orange',
uppercase: true
},
overlay: {
enabled: true,
overlay_colors: ['#2884ae', '#7e231f'],
overlay_percent: 40
},
border: {
color: '#e96d46',
enabled: true,
size: 23,
}
})
end
it 'should indicate when configured' do
plugin.config = valid_enabled_config
plugin.configured?.must_equal true
end
describe '#valid_configuration?' do
it 'should be trye even if config is not set' do
plugin.valid_configuration?.must_equal(true)
end
it 'should be true for a valid configuration' do
plugin.config = valid_enabled_config
plugin.valid_configuration?.must_equal true
end
end
end
end
end