Some regression tests on loading layouts

dev
Andy Meneely 2014-08-14 14:35:46 -04:00
parent a643cf8025
commit 8bd814fc1a
11 changed files with 144 additions and 1 deletions

View File

@ -29,6 +29,10 @@ module Squib
# @api private # @api private
attr_reader :text_hint attr_reader :text_hint
# :nodoc:
# @api private
attr_reader :layout, :config
# Squib's constructor that sets the immutable properties. # Squib's constructor that sets the immutable properties.
# #
# This is the starting point for Squib. In providing a block to the constructor, you have access to all of Deck's instance methods. # This is the starting point for Squib. In providing a block to the constructor, you have access to all of Deck's instance methods.

View File

@ -0,0 +1,6 @@
a:
extends: b
x: 50
b:
extends: a
x: 150

View File

@ -0,0 +1,9 @@
a:
extends: c
x: 50
b:
extends: a
x: 150
c:
extends: b
y: 250

View File

@ -0,0 +1,10 @@
frame:
x: 38
y: 38
title:
extends: frame
y: 50
width: 100
subtitle:
extends: subtitle
y: 150

5
spec/data/no-extends.yml Normal file
View File

@ -0,0 +1,5 @@
frame:
x: 38
valign: !ruby/symbol middle
str: "blah"
font: Mr. Font

View File

@ -0,0 +1,7 @@
title:
extends: frame
y: 50
width: 100
frame:
x: 38
y: 38

View File

@ -0,0 +1,3 @@
a:
extends: a
x: 50

View File

@ -0,0 +1,7 @@
frame:
x: 38
y: 38
title:
extends: frame
y: 50
width: 100

View File

@ -0,0 +1,12 @@
frame:
x: 38
y: 38
title:
extends: frame
y: 50
width: 100
title2:
extends: frame
x: 75
y: 150
width: 150

View File

@ -45,5 +45,81 @@ describe Squib::Deck do
end end
end end
end#describe context "#load_layout" do
it "loads a normal layout with no extends" do
d = Squib::Deck.new(layout: test_file('no-extends.yml'))
expect(d.layout).to \
eq({'frame' => {
'x' => 38,
'valign' => :middle,
'str' => "blah",
'font' => "Mr. Font",
}
}
)
end
it "loads with a single extends" do
d = Squib::Deck.new(layout: test_file('single-extends.yml'))
expect(d.layout).to \
eq({'frame' => {
'x' => 38,
'y' => 38,
},
'title' => {
'extends' => 'frame',
'x' => 38,
'y' => 50,
'width' => 100,
}
}
)
end
it "applies the extends regardless of order" do
d = Squib::Deck.new(layout: test_file('pre-extends.yml'))
expect(d.layout).to \
eq({'frame' => {
'x' => 38,
'y' => 38,
},
'title' => {
'extends' => 'frame',
'x' => 38,
'y' => 50,
'width' => 100,
}
}
)
end
it "applies the single-level extends multiple timess" do
d = Squib::Deck.new(layout: test_file('single-level-multi-extends.yml'))
expect(d.layout).to \
eq({'frame' => {
'x' => 38,
'y' => 38,
},
'title' => {
'extends' => 'frame',
'x' => 38,
'y' => 50,
'width' => 100,
},
'title2' => {
'extends' => 'frame',
'x' => 75,
'y' => 150,
'width' => 150,
},
}
)
end
end
end

View File

@ -6,3 +6,7 @@ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
Coveralls::SimpleCov::Formatter Coveralls::SimpleCov::Formatter
] ]
SimpleCov.start SimpleCov.start
def test_file(str)
"#{File.expand_path(File.dirname(__FILE__))}/data/#{str}"
end