Browse Source

Some regression tests on loading layouts

dev
Andy Meneely 11 years ago
parent
commit
8bd814fc1a
  1. 4
      lib/squib/deck.rb
  2. 6
      spec/data/easy-circular-extends.yml
  3. 9
      spec/data/hard-circular-extends.yml
  4. 10
      spec/data/multi-level-extends.yml
  5. 5
      spec/data/no-extends.yml
  6. 7
      spec/data/pre-extends.yml
  7. 3
      spec/data/self-circular-extends.yml
  8. 7
      spec/data/single-extends.yml
  9. 12
      spec/data/single-level-multi-extends.yml
  10. 78
      spec/deck_spec.rb
  11. 4
      spec/spec_helper.rb

4
lib/squib/deck.rb

@ -29,6 +29,10 @@ module Squib
# @api private
attr_reader :text_hint
# :nodoc:
# @api private
attr_reader :layout, :config
# 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.

6
spec/data/easy-circular-extends.yml

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

9
spec/data/hard-circular-extends.yml

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

10
spec/data/multi-level-extends.yml

@ -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

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

7
spec/data/pre-extends.yml

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

3
spec/data/self-circular-extends.yml

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

7
spec/data/single-extends.yml

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

12
spec/data/single-level-multi-extends.yml

@ -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

78
spec/deck_spec.rb

@ -45,5 +45,81 @@ describe Squib::Deck do
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

4
spec/spec_helper.rb

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