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 71 72 73 74 75 76 77
|
require 'spec_helper'
describe TablePrint::Config do
it "defaults max_width to 30" do
TablePrint::Config.max_width.should == 30
end
it "defaults time_format to year-month-day-hour-minute-second" do
TablePrint::Config.time_format.should == "%Y-%m-%d %H:%M:%S"
end
describe "individual config options" do
describe "storing and retrieving" do
it "sets the variable" do
TablePrint::Config.set(:max_width, [10])
TablePrint::Config.max_width.should == 10
TablePrint::Config.set(:max_width, [30])
end
end
describe "clearing" do
it "resets the variable to its initial value" do
TablePrint::Config.set(:max_width, [10])
TablePrint::Config.clear(:max_width)
TablePrint::Config.max_width.should == 30
end
end
end
describe "class-based column config" do
before :all do
Sandbox.add_class("Blog")
end
describe "storing and retrieving" do
it "stores the column hash" do
TablePrint::Config.set(Sandbox::Blog, [:title, :author])
TablePrint::Config.for(Sandbox::Blog).should == [:title, :author]
end
end
describe "clearing" do
it "removes the class from storage" do
TablePrint::Config.set(Sandbox::Blog, [:title, :author])
TablePrint::Config.clear(Sandbox::Blog)
TablePrint::Config.for(Sandbox::Blog).should be_nil
end
end
end
describe "io" do
before :all do
Sandbox.add_class("MyIO")
Sandbox.add_method("MyIO", :puts) {}
end
it "accepts object that respond to puts" do
myIO = Sandbox::MyIO.new
TablePrint::Config.set(:io, [myIO])
TablePrint::Config.io.should == myIO
end
it "doesn't accept objects unless they respond to puts" do
lambda {
TablePrint::Config.set(:io, [""])
}.should raise_error StandardError
end
it "defaults to STDOUT" do
myIO = Sandbox::MyIO.new
TablePrint::Config.set(:io, [myIO])
TablePrint::Config.clear(:io)
TablePrint::Config.io.should == STDOUT
end
end
end
|