-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbukfile_spec.rb
214 lines (174 loc) · 5.38 KB
/
bukfile_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
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
require 'spec_helper'
require 'bukin'
describe Bukin::Bukfile do
[:server, :plugin].each do |type|
it "adds a #{type} by method" do
bukfile = Bukin::Bukfile.new{}
bukfile.resources.size.should == 0
bukfile.send(type, 'resource_name')
bukfile.resources.size.should == 1
end
it "adds a #{type} by constructor" do
bukfile = Bukin::Bukfile.new do
send(type, 'resource_name')
end
bukfile.resources.size.should == 1
end
it "adds a #{type} with the correct name" do
bukfile = Bukin::Bukfile.new do
send(type, 'resource_name')
end
bukfile.resources.first[:name].should == 'resource_name'
end
it "adds a #{type} with the correct type" do
bukfile = Bukin::Bukfile.new do
send(type, 'resource_name')
end
resource = bukfile.resources.first[:type].should == type
end
it "adds a #{type} with the correct version" do
bukfile = Bukin::Bukfile.new do
send(type, 'resource_name', '1.0.0')
end
bukfile.resources.first[:version].should == '1.0.0'
end
it "will not add the same #{type} more than once" do
expect do
bukfile = Bukin::Bukfile.new do
send(type, 'duplicate_resource')
send(type, 'duplicate_resource')
end
end.to raise_error(Bukin::BukinError)
end
it "adds a #{type} with the correct jenkins provider" do
bukfile = Bukin::Bukfile.new do
send(type, 'resource_name', :jenkins => 'http://example.com')
end
bukfile.resources.first[:jenkins].should == 'http://example.com'
end
it "adds a #{type} with the correct download link" do
bukfile = Bukin::Bukfile.new do
send(type, 'resource_name', :download => 'http://example.com')
end
bukfile.resources.first[:download].should == 'http://example.com'
end
end
it 'adds both plugins and servers' do
bukfile = Bukin::Bukfile.new do
server 'craftbukkit'
plugin 'worldedit'
end
bukfile.resources.size.should == 2
bukfile.resources.find{|resource| resource[:name] == 'craftbukkit'}.should_not be_nil
bukfile.resources.find{|resource| resource[:name] == 'worldedit'}.should_not be_nil
end
it 'will not add non-existant resources' do
bukfile = Bukin::Bukfile.new do
end
bukfile.resources.size.should == 0
bukfile.resources.find{|resource| resource[:name] == 'missing_plugin'}.should be_nil
end
it 'attaches a single group to a resource' do
bukfile = Bukin::Bukfile.new do
plugin 'test', group: :test
end
bukfile.resources.first[:group].should == [:test]
end
it 'attaches multiple groups to a resource' do
bukfile = Bukin::Bukfile.new do
plugin 'test', group: [:test, :development]
end
bukfile.resources.first[:group].should == [:test, :development]
end
it 'attaches a single group to multiple resources' do
bukfile = Bukin::Bukfile.new do
group :test do
plugin 'test1'
plugin 'test2'
end
end
bukfile.resources[0][:group].should == [:test]
bukfile.resources[1][:group].should == [:test]
end
it 'attaches multiple groups to multiple resources' do
bukfile = Bukin::Bukfile.new do
group :test, :development do
plugin 'test1'
plugin 'test2'
end
end
bukfile.resources[0][:group].should == [:test, :development]
bukfile.resources[1][:group].should == [:test, :development]
end
it 'attaches groups to multiple resources' do
bukfile = Bukin::Bukfile.new do
group :test do
plugin 'test1', group: :development
plugin 'test2'
end
end
bukfile.resources[0][:group].should =~ [:test, :development]
bukfile.resources[1][:group].should == [:test]
end
it 'combines duplicate groups' do
bukfile = Bukin::Bukfile.new do
group :test do
plugin 'test1', group: [:development, :test]
plugin 'test2', group: :test
end
end
bukfile.resources[0][:group].should =~ [:test, :development]
bukfile.resources[1][:group].should == [:test]
end
it 'combines duplicate method groups' do
bukfile = Bukin::Bukfile.new do
group :test, :test do
plugin 'test'
end
end
bukfile.resources.first[:group].should == [:test]
end
it 'combines duplicate resource groups' do
bukfile = Bukin::Bukfile.new do
plugin 'test', group: [:test, :test]
end
bukfile.resources.first[:group].should == [:test]
end
it 'only adds groups inside a block' do
bukfile = Bukin::Bukfile.new do
group :development do
plugin 'test1'
end
plugin 'test2'
end
bukfile.resources[0][:group].should == [:development]
bukfile.resources[1][:group].should == []
end
it 'throws an error when groups are nested' do
expect do
Bukin::Bukfile.new do
group :test do
group :development do
plugin 'test'
end
end
end
end.to raise_error(Bukin::BukfileError)
end
it 'throws an error when group is not a symbol' do
expect do
Bukin::Bukfile.new do
group 'test' do
plugin 'test'
end
end
end.to raise_error(Bukin::BukfileError)
end
it 'throws an error when resource group is not a symbol' do
expect do
Bukin::Bukfile.new do
plugin 'test', group: 'test'
end
end.to raise_error(Bukin::BukfileError)
end
end