Permalink
Browse files

don't quietly stub the logger

  • Loading branch information...
1 parent ead38f7 commit 6c25a1722e60ca5e1ab2d319b9ceaaf99fe9507d Brian D. Burns committed Mar 18, 2012
View
@@ -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
@@ -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(
@@ -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')
@@ -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(
View
@@ -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) }
View
@@ -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
View
@@ -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
View
@@ -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
@@ -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'

0 comments on commit 6c25a17

Please sign in to comment.