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
|
require File.expand_path(File.dirname(__FILE__)+"/spec_helper.rb")
shared_examples_for "Ruby API for Rubyvis" do
before do
@h=200
@w=200
end
it "should create a Panel with a block" do
lambda {@vis = Rubyvis.Panel.new {
width @w
height @h
}
}.should_not raise_exception
@vis._properties.size.should==2
end
it "should create a Bar with new method" do
vis1=Rubyvis.Panel.new.width(@w).height(@h)
vis1.add(Rubyvis::Bar).
data([1,2,3]).
width(10).
height(10).
left(lambda {|x| x*10}).anchor('top').
add(Rubyvis::Label).
text(lambda {|x| x})
vis1.render
svg1=vis1.to_svg
ww=@w
hh=@h
vis2=Rubyvis.Panel.new {|pan|
pan.width ww
pan.height hh
pan.bar {
data([1,2,3])
width 10
height 10
left {|x| x*10}
label(:anchor=>'top') {
text {|x| x}
}
}
}
vis2.render
svg2=vis2.to_svg
svg1.should==svg2
end
end
describe "Rubyvis with REXML" do
before(:all) do
$rubyvis_no_nokogiri=true
end
after(:all) do
$rubyvis_no_nokogiri=false
end
it_should_behave_like "Ruby API for Rubyvis"
end
if Rubyvis.has_nokogiri?
describe "Rubyvis with Nokogiri" do
before(:all) do
$rubyvis_no_nokogiri=false
end
it_should_behave_like "Ruby API for Rubyvis"
end
end
|