spec/peekaboo/configuration_spec.rb in peekaboo-0.1.2 vs spec/peekaboo/configuration_spec.rb in peekaboo-0.2.0

- old
+ new

@@ -4,32 +4,99 @@ before(:each) do @config = Peekaboo::Configuration.new end - context "#tracer (default)" do - it "should initialize tracing" do + context "autoinclusion" do + it "should not reference any class by default" do + @config.autoincluded.should be_empty + end + + it "should raise an exception when trying to add a non-class objects" do + lambda { + [ [Object.new], ["", Hash] ].each { |object_list| @config.autoinclude_with *object_list } + }.should raise_exception("Auto-inclusion can only be used with classes") + end + + it "should allow class objects to be added" do + test_class1 = new_test_class + test_class2 = new_test_class + test_class3 = new_test_class + + lambda { + [ [test_class1], + [test_class1, test_class2], + [test_class1, test_class2, test_class3] + ].each { |klass_list| @config.autoinclude_with *klass_list } + }.should_not raise_exception + end + + it "should maintain a list of classes to use" do + test_class1 = new_test_class + test_class2 = new_test_class + test_class3 = new_test_class + + @config.autoinclude_with test_class1, test_class2, test_class3 + @config.autoincluded.should =~ [ test_class1, test_class2, test_class3 ] + end + + it "should ensure its list of classes is unique" do + test_class1 = new_test_class + test_class2 = new_test_class + + @config.autoinclude_with test_class1, test_class2, test_class1, test_class2 + @config.autoincluded.should =~ [ test_class1, test_class2 ] + end + + it "should auto-include Peekaboo into any class in its list" do + test_class = new_test_class + @config.autoinclude_with test_class + lambda { test_class.enable_tracing_on }.should_not raise_exception + end + + it "should auto-include Peekaboo into any class that inherits from a class in its list" do + parent_class = new_test_class + child_class = Class.new(parent_class) + @config.autoinclude_with parent_class + lambda { child_class.enable_tracing_on }.should_not raise_exception + end + end + + context "tracing" do + it "should have a default implementation" do @config.tracer.should_not be_nil end - it "should adhere to the standard 'Logger' interface" do + it "should maintain the 'Logger' interface by default" do [ :debug, :info, :warn, :error, :fatal, :unknown ].each { |logger_msg| @config.tracer.should respond_to(logger_msg) } end - end - context "#trace_with" do - it "should set a new tracer for use" do - new_tracer = Logger.new STDOUT + it "should use any tracer that maintains the 'Logger' interface" do + tmp_file = Tempfile.new 'some-log.txt' + some_logger_obj = MyLogger = Class.new do + def debug(msg) ; end + def info(msg) ; end + def warn(msg) ; end + def error(msg) ; end + def fatal(msg) ; end + def unknown(msg) ; end + end.new - @config.trace_with new_tracer - @config.tracer.should == new_tracer + tracers = [ Logger.new(tmp_file.path), some_logger_obj ] + + tracers.each do |some_tracer| + @config.trace_with some_tracer + @config.tracer.should == some_tracer + end + + tmp_file.close! end - it "should enforce that new tracer adheres to the standard 'Logger' interface" do + it "should raise an exception when attempting to use an object that does not maintaint the 'Logger' interface" do lambda { - @config.trace_with 'garbage value' + @config.trace_with 'garbage object' }.should raise_exception('Tracer must respond to debug(), info(), warn(), error(), fatal(), and unknown()') end end end