Skip to content

Commit 19fa5d6

Browse files
authored
Merge pull request #34 from gravitystorm/fixtures
Add tests using file fixtures
2 parents 8c7e35e + a24124f commit 19fa5d6

File tree

6 files changed

+121
-0
lines changed

6 files changed

+121
-0
lines changed

spec/fixtures/basic.glug

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
version 8
2+
name 'My first stylesheet'
3+
source :shortbread, type: 'vector', url: 'https://vector.openstreetmap.org/shortbread_v1/tilejson.json'
4+
5+
layer(:roads, zoom: 10..13, source: :shortbread) do
6+
line_width 6
7+
line_color match(highway,
8+
'motorway', :blue,
9+
'trunk', :green,
10+
'primary', :red,
11+
'secondary', :orange,
12+
0x888888)
13+
end

spec/fixtures/basic.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"version":8,
3+
"name":"My first stylesheet",
4+
"sources":{
5+
"shortbread":{
6+
"type":"vector",
7+
"url":"https://vector.openstreetmap.org/shortbread_v1/tilejson.json"
8+
}
9+
},
10+
"layers":[
11+
{
12+
"paint":{
13+
"line-width":6,
14+
"line-color":[
15+
"match",
16+
["get","highway"],
17+
"motorway",
18+
"blue",
19+
"trunk",
20+
"green",
21+
"primary",
22+
"red",
23+
"secondary",
24+
"orange",
25+
8947848
26+
]
27+
},
28+
"source":"shortbread",
29+
"id":"roads",
30+
"source-layer":"roads",
31+
"type":"line",
32+
"minzoom":10,
33+
"maxzoom":13
34+
}
35+
]
36+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
version 8
2+
name 'My first stylesheet'
3+
source :shortbread, type: 'vector', url: 'https://vector.openstreetmap.org/shortbread_v1/tilejson.json'
4+
5+
include_file('basic_with_include_sub.glug')
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"version":8,
3+
"name":"My first stylesheet",
4+
"sources":{
5+
"shortbread":{
6+
"type":"vector",
7+
"url":"https://vector.openstreetmap.org/shortbread_v1/tilejson.json"
8+
}
9+
},
10+
"layers":[
11+
{
12+
"paint":{
13+
"line-width":6,
14+
"line-color":[
15+
"match",
16+
["get","highway"],
17+
"motorway",
18+
"blue",
19+
"trunk",
20+
"green",
21+
"primary",
22+
"red",
23+
"secondary",
24+
"orange",
25+
8947848
26+
]
27+
},
28+
"source":"shortbread",
29+
"id":"roads",
30+
"source-layer":"roads",
31+
"type":"line",
32+
"minzoom":10,
33+
"maxzoom":13
34+
}
35+
]
36+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
layer(:roads, zoom: 10..13, source: :shortbread) do
2+
line_width 6
3+
line_color match(highway,
4+
'motorway', :blue,
5+
'trunk', :green,
6+
'primary', :red,
7+
'secondary', :orange,
8+
0x888888)
9+
end

spec/lib/glug/stylesheet_spec.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,26 @@
6565
DOC
6666
.strip)
6767
end
68+
69+
context 'with fixtures' do
70+
let!(:fixture_dir) { File.join(File.dirname(__FILE__), '../../fixtures/') }
71+
72+
it 'reads a basic file' do
73+
glug = File.read(File.join(fixture_dir, 'basic.glug'))
74+
stylesheet = described_class.new(base_dir: fixture_dir) do
75+
instance_eval(glug)
76+
end
77+
output = File.read(File.join(fixture_dir, 'basic.json'))
78+
expect(stylesheet.to_json).to eql(output.strip)
79+
end
80+
81+
it 'handles include_file method calls' do
82+
glug = File.read(File.join(fixture_dir, 'basic_with_include.glug'))
83+
stylesheet = described_class.new(base_dir: fixture_dir) do
84+
instance_eval(glug)
85+
end
86+
output = File.read(File.join(fixture_dir, 'basic_with_include.json'))
87+
expect(stylesheet.to_json).to eql(output.strip)
88+
end
89+
end
6890
end

0 commit comments

Comments
 (0)