spec/beaker/logger_spec.rb in beaker-1.21.0 vs spec/beaker/logger_spec.rb in beaker-2.0.0

- old
+ new

@@ -1,14 +1,14 @@ # encoding: UTF-8 require 'spec_helper' module Beaker - describe Logger, :use_fakefs => true do - let(:my_io) { MockIO.new } - let(:logger) { Logger.new(my_io, :quiet => true) } + describe Logger do + let(:my_io) { MockIO.new } + let(:logger) { Logger.new(my_io, :quiet => true) } + let(:test_dir) { 'tmp/tests' } - context '#convert' do let(:valid_utf8) { "/etc/puppet/modules\n├── jimmy-appleseed (\e[0;36mv1.1.0\e[0m)\n├── jimmy-crakorn (\e[0;36mv0.4.0\e[0m)\n└── jimmy-thelock (\e[0;36mv1.0.0\e[0m)\n" } let(:invalid_utf8) {"/etc/puppet/modules\n├── jimmy-appleseed (\e[0;36mv1.1.0\e[0m)\n├── jimmy-crakorn (\e[0;36mv0.4.0\e[0m)\n└── jimmy-thelock (\e[0;36mv1.0.0\e[0m)\xAD\n"} it 'preserves valid utf-8 strings' do @@ -22,14 +22,28 @@ pending "not supported in ruby 1.8 (using #{RUBY_VERSION})" end end end + context '#generate_dated_log_folder' do + + it 'generates path for a given timestamp' do + input_time = Time.new(2014, 6, 2, 16, 31, 22, '-07:00') + expect( Logger.generate_dated_log_folder(test_dir, input_time) ).to be === File.join(test_dir, '2014-06-02_16_31_22') + end + + it 'generates directory for a given timestamp' do + input_time = Time.new(2011, 6, 10, 13, 7, 55, '-09:00') + expect( File.directory? Logger.generate_dated_log_folder(test_dir, input_time) ).to be_truthy + end + + end + context 'new' do it 'does not duplicate STDOUT when directly passed to it' do stdout_logger = Logger.new STDOUT - expect( stdout_logger ).to have(1).destinations + expect( stdout_logger.destinations.size ).to be === 1 end context 'default for' do its(:destinations) { should include(STDOUT) } @@ -40,11 +54,11 @@ context 'it can' do it 'open/create a file when a string is given to add_destination' do logger.add_destination 'my_tmp_file' - expect( File.exists?( 'my_tmp_file' ) ).to be_true + expect( File.exists?( 'my_tmp_file' ) ).to be_truthy io = logger.destinations.select {|d| d.respond_to? :path }.first expect( io.path ).to match /my_tmp_file/ end @@ -63,13 +77,13 @@ end it 'colors strings if @color is set' do colorized_logger = Logger.new my_io, :color => true, :quiet => true - my_io.should_receive( :print ).with "\e[00;30m" - my_io.should_receive( :print ) - my_io.should_receive( :puts ).with 'my string' + expect( my_io ).to receive( :print ).with "\e[00;30m" + expect( my_io ).to receive( :print ) + expect( my_io ).to receive( :puts ).with 'my string' colorized_logger.optionally_color "\e[00;30m", 'my string' end context 'at trace log_level' do @@ -77,18 +91,18 @@ :log_level => 'trace', :quiet => true, :color => true ) } - its( :is_debug? ) { should be_true } - its( :is_trace? ) { should be_true } - its( :is_warn? ) { should be_true } + its( :is_debug? ) { should be_truthy } + its( :is_trace? ) { should be_truthy } + its( :is_warn? ) { should be_truthy } context 'but print' do before do - my_io.stub :puts - my_io.should_receive( :print ).at_least :twice + allow( my_io ).to receive :puts + expect( my_io ).to receive( :print ).at_least :twice end it( 'warnings' ) { trace_logger.warn 'IMA WARNING!' } it( 'successes' ) { trace_logger.success 'SUCCESS!' } it( 'errors' ) { trace_logger.error 'ERROR!' } @@ -103,19 +117,19 @@ :log_level => 'verbose', :quiet => true, :color => true ) } - its( :is_trace? ) { should be_false } - its( :is_debug? ) { should be_false } - its( :is_verbose? ) { should be_true } - its( :is_warn? ) { should be_true } + its( :is_trace? ) { should be_falsy } + its( :is_debug? ) { should be_falsy } + its( :is_verbose? ) { should be_truthy } + its( :is_warn? ) { should be_truthy } context 'but print' do before do - my_io.stub :puts - my_io.should_receive( :print ).at_least :twice + allow( my_io ).to receive :puts + expect( my_io ).to receive( :print ).at_least :twice end it( 'warnings' ) { verbose_logger.warn 'IMA WARNING!' } it( 'successes' ) { verbose_logger.success 'SUCCESS!' } it( 'errors' ) { verbose_logger.error 'ERROR!' } @@ -129,18 +143,18 @@ :log_level => 'debug', :quiet => true, :color => true ) } - its( :is_trace? ) { should be_false } - its( :is_debug? ) { should be_true } - its( :is_warn? ) { should be_true } + its( :is_trace? ) { should be_falsy } + its( :is_debug? ) { should be_truthy } + its( :is_warn? ) { should be_truthy } context 'successfully print' do before do - my_io.stub :puts - my_io.should_receive( :print ).at_least :twice + allow( my_io ).to receive :puts + expect( my_io ).to receive( :print ).at_least :twice end it( 'warnings' ) { debug_logger.warn 'IMA WARNING!' } it( 'debugs' ) { debug_logger.debug 'IMA DEBUGGING!' } it( 'successes' ) { debug_logger.success 'SUCCESS!' } @@ -154,28 +168,28 @@ :log_level => :info, :quiet => true, :color => true ) } - its( :is_debug? ) { should be_false } - its( :is_trace? ) { should be_false } + its( :is_debug? ) { should be_falsy } + its( :is_trace? ) { should be_falsy } context 'skip' do before do - my_io.should_not_receive :puts - my_io.should_not_receive :print + expect( my_io ).to_not receive :puts + expect( my_io ).to_not receive :print end it( 'debugs' ) { info_logger.debug 'NOT DEBUGGING!' } it( 'traces' ) { info_logger.debug 'NOT TRACING!' } end context 'but print' do before do - my_io.should_receive :puts - my_io.should_receive( :print ).twice + expect( my_io ).to receive :puts + expect( my_io ).to receive( :print ).twice end it( 'successes' ) { info_logger.success 'SUCCESS!' } it( 'notifications' ) { info_logger.notify 'NOTFIY!' } it( 'errors' ) { info_logger.error 'ERROR!' }