From 6c25a1722e60ca5e1ab2d319b9ceaaf99fe9507d Mon Sep 17 00:00:00 2001 From: "Brian D. Burns" Date: Sun, 18 Mar 2012 00:03:28 -0400 Subject: [PATCH] don't quietly stub the logger --- spec/archive_spec.rb | 14 +++++++------- spec/configuration_spec.rb | 2 ++ spec/database/mongodb_spec.rb | 5 +++++ spec/dependency_spec.rb | 2 ++ spec/model_spec.rb | 2 ++ spec/pipeline_spec.rb | 4 +++- spec/spec_helper.rb | 9 +++++---- spec/syncer/cloud/base_spec.rb | 15 +++++++++------ 8 files changed, 35 insertions(+), 18 deletions(-) diff --git a/spec/archive_spec.rb b/spec/archive_spec.rb index 152b25fca..a88914b30 100644 --- a/spec/archive_spec.rb +++ b/spec/archive_spec.rb @@ -138,6 +138,7 @@ let(:s) { sequence '' } before do + archive.instance_variable_set(:@paths, paths) archive.expects(:utility).with(:tar).returns('tar') FileUtils.expects(:mkdir_p).with(archive_path) Backup::Pipeline.expects(:new).returns(pipeline) @@ -145,7 +146,6 @@ context 'when both #paths and #excludes were added' do before do - archive.instance_variable_set(:@paths, paths) archive.instance_variable_set(:@excludes, excludes) end @@ -176,10 +176,6 @@ end # context 'when both #paths and #excludes were added' context 'when no excludes were added' do - before do - archive.instance_variable_set(:@paths, paths) - end - it 'should render only the syntax for adds' do Backup::Logger.expects(:message).in_sequence(s).with( "Backup::Archive has started archiving:\n" + @@ -206,7 +202,6 @@ context 'with #paths, #excludes and #tar_args' do before do - archive.instance_variable_set(:@paths, paths) archive.instance_variable_set(:@excludes, excludes) archive.instance_variable_set(:@tar_args, '-h --xattrs') end @@ -239,7 +234,6 @@ context 'with #paths, #excludes, #tar_args and a Gzip Compressor' do before do - archive.instance_variable_set(:@paths, paths) archive.instance_variable_set(:@excludes, excludes) archive.instance_variable_set(:@tar_args, '-h --xattrs') compressor = mock @@ -283,6 +277,12 @@ end it 'should raise an error' do + Backup::Logger.expects(:message).with( + "Backup::Archive has started archiving:\n" + + " /path/to/add\n" + + " /another/path/to/add" + ) + expect do archive.perform! end.to raise_error( diff --git a/spec/configuration_spec.rb b/spec/configuration_spec.rb index ff297e4d7..03357d073 100644 --- a/spec/configuration_spec.rb +++ b/spec/configuration_spec.rb @@ -29,11 +29,13 @@ class Foo; end end it 'should pass calls to .defaults to the proper class' do + Backup::Logger.expects(:warn) Backup::Foo.expects(:defaults) Backup::Configuration::Foo.defaults end it 'should pass a given block to .defaults to the proper class' do + Backup::Logger.expects(:warn) configuration = mock Backup::Foo.expects(:defaults).yields(configuration) configuration.expects(:foo=).with('bar') diff --git a/spec/database/mongodb_spec.rb b/spec/database/mongodb_spec.rb index ba30bf146..9ec52f902 100644 --- a/spec/database/mongodb_spec.rb +++ b/spec/database/mongodb_spec.rb @@ -331,6 +331,11 @@ end it 'should raise an error' do + Backup::Logger.expects(:message).with( + "Database::MongoDB started compressing and packaging:\n" + + " '/path/to/dump/folder'" + ) + expect do db.send(:package!) end.to raise_error( diff --git a/spec/dependency_spec.rb b/spec/dependency_spec.rb index 9551919ab..3146d9c7c 100644 --- a/spec/dependency_spec.rb +++ b/spec/dependency_spec.rb @@ -40,6 +40,8 @@ end it "should exit with status code 1" do + Backup::Logger.expects(:error) + expect do Backup::Dependency.load("net-sftp") end.to raise_error { |exit| exit.status.should be(1) } diff --git a/spec/model_spec.rb b/spec/model_spec.rb index ae63cdbec..01eebaacc 100644 --- a/spec/model_spec.rb +++ b/spec/model_spec.rb @@ -342,6 +342,8 @@ def using_fake(const, replacement) Timecop.freeze(Time.now) started_at = Time.now time = started_at.strftime("%Y.%m.%d.%H.%M.%S") + model.expects(:log!).with(:started) + model.expects(:log!).with(:finished) model.perform! model.time.should == time diff --git a/spec/pipeline_spec.rb b/spec/pipeline_spec.rb index 59d58ab11..18be84057 100644 --- a/spec/pipeline_spec.rb +++ b/spec/pipeline_spec.rb @@ -26,7 +26,6 @@ before do pipeline.expects(:pipeline).returns('foo') - pipeline.stubs(:stderr_messages).returns('stderr_messages_output') # stub CLI::Helpers#command_name so it simply returns what it's passed pipeline.class.send(:define_method, :command_name, lambda {|arg| arg } ) end @@ -44,6 +43,7 @@ context 'when commands output no stderr messages' do before do stderr.expects(:read).returns('') + pipeline.stubs(:stderr_messages).returns(false) end it 'should process the returned stdout/stderr and report no errors' do @@ -58,6 +58,7 @@ context 'when successful commands output messages on stderr' do before do stderr.expects(:read).returns("stderr output\n") + pipeline.stubs(:stderr_messages).returns('stderr_messages_output') end it 'should log a warning with the stderr messages' do @@ -74,6 +75,7 @@ before do pipeline.instance_variable_set(:@commands, ['first', 'second', 'third']) stderr.expects(:read).returns("stderr output\n") + pipeline.stubs(:stderr_messages).returns('success? should be false') end context 'when the commands return in sequence' do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index e3461dcd7..bdb1fa875 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -44,16 +44,17 @@ def capture_io # Actions to perform before each example config.before(:each) do FileUtils.collect_method(:noop).each do |method| - FileUtils.stubs(method).raises("Unexpected call to FileUtils.#{method}") + FileUtils.stubs(method).raises("Unexpected call to FileUtils.#{ method }") end + Open4.stubs(:popen4).raises('Unexpected call to Open4::popen4()') - [:message, :error, :warn, :normal, :silent].each do |message_type| - Backup::Logger.stubs(message_type) + [:message, :error, :warn, :normal, :silent].each do |method| + Backup::Logger.stubs(method).raises("Unexpected call to Backup::Logger.#{ method }") end end end unless @_put_ruby_version - puts @_put_ruby_version = "\n\nRuby version: #{RUBY_DESCRIPTION}\n\n" + puts @_put_ruby_version = "\n\nRuby version: #{ RUBY_DESCRIPTION }\n\n" end diff --git a/spec/syncer/cloud/base_spec.rb b/spec/syncer/cloud/base_spec.rb index c54638949..2cf85003d 100644 --- a/spec/syncer/cloud/base_spec.rb +++ b/spec/syncer/cloud/base_spec.rb @@ -53,6 +53,13 @@ before do syncer.stubs(:repository_object).returns(:a_repository_object) + + Backup::Logger.expects(:message).with( + 'Syncer::Cloud::Base started the syncing process:' + ) + Backup::Logger.expects(:message).with( + 'Syncer::Cloud::Base Syncing Complete!' + ) end it 'should sync each directory' do @@ -61,9 +68,6 @@ add '/dir/two' end - Backup::Logger.expects(:message).in_sequence(s).with( - 'Syncer::Cloud::Base started the syncing process:' - ) Backup::Syncer::Cloud::Base::SyncContext.expects(:new).in_sequence(s).with( '/dir/one', :a_repository_object, 'backups' ).returns(sync_context) @@ -76,9 +80,6 @@ sync_context.expects(:sync!).in_sequence(s).with( false, false, 2 ) - Backup::Logger.expects(:message).in_sequence(s).with( - 'Syncer::Cloud::Base Syncing Complete!' - ) syncer.perform! end @@ -485,6 +486,8 @@ it 'should return nil if the object is invalid' do local_file_class.any_instance.expects(:invalid?).returns(true) + Backup::Syncer::Cloud::Base::MUTEX.expects(:synchronize).yields + Backup::Logger.expects(:warn) local_file.should be_nil end end # describe '#initialize'