Skip to content

Commit

Permalink
don't quietly stub the logger
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian D. Burns committed Mar 18, 2012
1 parent ead38f7 commit 6c25a17
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 18 deletions.
14 changes: 7 additions & 7 deletions spec/archive_spec.rb
Expand Up @@ -138,14 +138,14 @@
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)
end

context 'when both #paths and #excludes were added' do
before do
archive.instance_variable_set(:@paths, paths)
archive.instance_variable_set(:@excludes, excludes)
end

Expand Down Expand Up @@ -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" +
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 2 additions & 0 deletions spec/configuration_spec.rb
Expand Up @@ -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')
Expand Down
5 changes: 5 additions & 0 deletions spec/database/mongodb_spec.rb
Expand Up @@ -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(
Expand Down
2 changes: 2 additions & 0 deletions spec/dependency_spec.rb
Expand Up @@ -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) }
Expand Down
2 changes: 2 additions & 0 deletions spec/model_spec.rb
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion spec/pipeline_spec.rb
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
9 changes: 5 additions & 4 deletions spec/spec_helper.rb
Expand Up @@ -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
15 changes: 9 additions & 6 deletions spec/syncer/cloud/base_spec.rb
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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'
Expand Down

0 comments on commit 6c25a17

Please sign in to comment.