test/examples/log_methods_test.rb in vigetlabs-loggable-0.2.0 vs test/examples/log_methods_test.rb in vigetlabs-loggable-0.3.0

- old
+ new

@@ -6,49 +6,49 @@ end end module MyModule; end -describe "MyClass, with loggable mix-in" do - - before(:each) do - @logger = mock() +class LogMethodsTest < Test::Unit::TestCase + context "An instance of MyClass, with loggable mix-in" do + + setup { @logger = mock() } + teardown { MyClass.logger = nil} + + should "have a logger stub by default" do + MyClass.logger.should be_kind_of(LoggerStub) + end + + should "not fail when an instance calls an uninitialized logger" do + m = MyClass.new + lambda { m.logged_method }.should_not raise_error + end + + should "allow the asssignment of a logger" do + MyClass.logger = @logger + MyClass.logger.should == @logger + end + + should "allow access to the logger from an instance" do + MyClass.logger = @logger + MyClass.new.logger.should == @logger + end + end - - after(:each) do - MyClass.logger = nil - end - - it "should have a logger stub by default" do - MyClass.logger.should.be.an.instance_of(LoggerStub) - end - - it "should not fail when an instance calls an uninitialized logger" do - m = MyClass.new - lambda { m.logged_method }.should.not.raise - end - - it "should allow the asssignment of a logger" do - MyClass.logger = @logger - MyClass.logger.should.equal @logger - end - - it "should allow access to the logger from an instance" do - MyClass.logger = @logger - MyClass.new.logger.should.equal @logger - end - -end -describe "MyModule, with loggable mix-in" do - - it "should have a logger stub by default" do - MyModule.logger.should.be.an.instance_of(LoggerStub) + context "MyModule, with loggable mix-in" do + + should "have a logger stub by default" do + MyModule.logger = nil + MyModule.logger.should be_kind_of(LoggerStub) + end + + should "be able to log messages" do + logger = mock() + logger.expects(:debug).with('blip') + + MyModule.logger = logger + MyModule.logger.debug('blip') + end + end - - it "should be able to log messages" do - logger = mock {|m| m.expects(:debug).with('blip') } - MyModule.logger = logger - MyModule.logger.debug('blip') - end - end \ No newline at end of file