require 'test/spec'
require 'pyrosoma'
context "Pyrosoma::Frame rendering" do
db = Pyrosoma::Database.new(:dir => Ferret::Store::RAMDirectory.new)
simple = Pyrosoma::Frame.new({:id => "simple",
:foo => "bar",
:quux => "zing"})
db << simple
complex = Pyrosoma::Frame.new({:id => "complex",
:foo => ["bar", "baz"],
:quux => "@simple",
:content => "blah."})
db << complex
templatetest = Pyrosoma::Frame.new({:id => "templatetest",
:title => "wow",
:template => "Title: ${self[:title]}"})
db << templatetest
# context "using Pryosoma::Template" do
# specify "works" do
# db["templatetest"].render.should.equal "Title: wow"
#
# lambda { db["simple"].render }.should.raise(NoMethodError)
# end
# end
context "using XOXO" do
specify "works for simple structures" do
xoxo = db["simple"].to_xoxo
xoxo.should.include "
idsimple"
xoxo.should.include "foobar"
xoxo.should.include "quuxzing"
end
specify "works for complex structures" do
xoxo = db["complex"].to_xoxo
xoxo.should.include "idcomplex"
xoxo.should.include "foo- bar
- baz
"
xoxo.should.include "quuxsimple"
xoxo.should.include "contentblah."
end
specify "can roundtrip" do
Pyrosoma::Frame.from_xoxo(db["complex"].to_xoxo).should.equal db["complex"]
end
specify "can DWIM on loading" do
Pyrosoma::Frame.from_xoxo(< "test"})
- test
EOF
Pyrosoma::Frame.from_xoxo(< ["1", "2", "3"]})
- 1
- 2
- 3
EOF
end
end
context "using Microformats" do
specify "works for simple structures" do
db["simple"].to_microformat.should.equal <simplebarzing
EOF
end
specify "works for complex structures" do
mf = db["complex"].to_microformat
mf.should.include ""
mf.should.include "complex"
mf.should.include "barbaz"
mf.should.include "blah."
mf.should.include "simple"
mf.should =~ /<\/span>\Z/
end
end
end