spec/cli/helpers_spec.rb in backup-3.0.26 vs spec/cli/helpers_spec.rb in backup-3.0.27
- old
+ new
@@ -28,11 +28,11 @@
context 'and generates no messages' do
let(:stdout_messages) { '' }
let(:stderr_messages) { '' }
it 'should return stdout and generate no additional log messages' do
- helpers.run(command).should == ''
+ helpers.send(:run, command).should == ''
end
end
context 'and generates only stdout messages' do
let(:stdout_messages) { "out line1\nout line2\n" }
@@ -40,11 +40,11 @@
it 'should return stdout and log the stdout messages' do
Backup::Logger.expects(:message).with(
"cmd_name:STDOUT: out line1\ncmd_name:STDOUT: out line2"
)
- helpers.run(command).should == stdout_messages.strip
+ helpers.send(:run, command).should == stdout_messages.strip
end
end
context 'and generates only stderr messages' do
let(:stdout_messages) { '' }
@@ -52,11 +52,11 @@
it 'should return stdout and log the stderr messages' do
Backup::Logger.expects(:warn).with(
"cmd_name:STDERR: err line1\ncmd_name:STDERR: err line2"
)
- helpers.run(command).should == ''
+ helpers.send(:run, command).should == ''
end
end
context 'and generates messages on both stdout and stderr' do
let(:stdout_messages) { "out line1\nout line2\n" }
@@ -67,11 +67,11 @@
"cmd_name:STDOUT: out line1\ncmd_name:STDOUT: out line2"
)
Backup::Logger.expects(:warn).with(
"cmd_name:STDERR: err line1\ncmd_name:STDERR: err line2"
)
- helpers.run(command).should == stdout_messages.strip
+ helpers.send(:run, command).should == stdout_messages.strip
end
end
end # context 'when the command is successful'
context 'when the command is not successful' do
@@ -99,11 +99,11 @@
let(:stdout_messages) { '' }
let(:stderr_messages) { '' }
it 'should raise an error reporting no messages' do
expect do
- helpers.run(command)
+ helpers.send(:run, command)
end.to raise_error {|err|
err.message.should == message_head +
" STDOUT Messages: None\n" +
" STDERR Messages: None"
}
@@ -114,11 +114,11 @@
let(:stdout_messages) { "out line1\nout line2\n" }
let(:stderr_messages) { '' }
it 'should raise an error and report the stdout messages' do
expect do
- helpers.run(command)
+ helpers.send(:run, command)
end.to raise_error {|err|
err.message.should == message_head +
" STDOUT Messages: \n" +
" out line1\n" +
" out line2\n" +
@@ -131,11 +131,11 @@
let(:stdout_messages) { '' }
let(:stderr_messages) { "err line1\nerr line2\n" }
it 'should raise an error and report the stderr messages' do
expect do
- helpers.run(command)
+ helpers.send(:run, command)
end.to raise_error {|err|
err.message.should == message_head +
" STDOUT Messages: None\n" +
" STDERR Messages: \n" +
" err line1\n" +
@@ -148,11 +148,11 @@
let(:stdout_messages) { "out line1\nout line2\n" }
let(:stderr_messages) { "err line1\nerr line2\n" }
it 'should raise an error and report the stdout and stderr messages' do
expect do
- helpers.run(command)
+ helpers.send(:run, command)
end.to raise_error {|err|
err.message.should == message_head +
" STDOUT Messages: \n" +
" out line1\n" +
" out line2\n" +
@@ -173,11 +173,11 @@
Open4.expects(:popen4).raises("exec call failed")
end
it 'should raise an error wrapping the system error raised' do
expect do
- helpers.run(command)
+ helpers.send(:run, command)
end.to raise_error {|err|
err.message.should == "CLI::SystemCallError: " +
"Failed to execute system command on #{ RUBY_PLATFORM }\n" +
" Command was: /path/to/cmd_name arg1 arg2\n" +
" Reason: RuntimeError\n" +
@@ -191,71 +191,71 @@
after { Backup::CLI::Helpers::UTILITY.clear }
context 'when a system path for the utility is available' do
it 'should return the system path with newline removed' do
helpers.expects(:`).with('which foo 2>/dev/null').returns("system_path\n")
- helpers.utility(:foo).should == 'system_path'
+ helpers.send(:utility, :foo).should == 'system_path'
end
it 'should cache the returned path' do
helpers.expects(:`).once.with('which cache_me 2>/dev/null').
returns("cached_path\n")
- helpers.utility(:cache_me).should == 'cached_path'
- helpers.utility(:cache_me).should == 'cached_path'
+ helpers.send(:utility, :cache_me).should == 'cached_path'
+ helpers.send(:utility, :cache_me).should == 'cached_path'
end
it 'should cache the value for all extended objects' do
helpers.expects(:`).once.with('which once_only 2>/dev/null').
returns("cached_path\n")
- helpers.utility(:once_only).should == 'cached_path'
- Class.new.extend(Backup::CLI::Helpers).utility(:once_only).
- should == 'cached_path'
+ helpers.send(:utility, :once_only).should == 'cached_path'
+ Class.new.extend(Backup::CLI::Helpers).send(
+ :utility, :once_only).should == 'cached_path'
end
end
context 'when a system path for the utility is not available' do
it 'should raise an error' do
helpers.expects(:`).with('which unknown 2>/dev/null').returns("\n")
expect do
- helpers.utility(:unknown)
+ helpers.send(:utility, :unknown)
end.to raise_error(Backup::Errors::CLI::UtilityNotFoundError) {|err|
err.message.should match(/Could not locate 'unknown'/)
}
end
it 'should not cache any value for the utility' do
helpers.expects(:`).with('which not_cached 2>/dev/null').twice.returns("\n")
expect do
- helpers.utility(:not_cached)
+ helpers.send(:utility, :not_cached)
end.to raise_error(Backup::Errors::CLI::UtilityNotFoundError) {|err|
err.message.should match(/Could not locate 'not_cached'/)
}
expect do
- helpers.utility(:not_cached)
+ helpers.send(:utility, :not_cached)
end.to raise_error(Backup::Errors::CLI::UtilityNotFoundError) {|err|
err.message.should match(/Could not locate 'not_cached'/)
}
end
end
it 'should raise an error if name is nil' do
expect do
- helpers.utility(nil)
+ helpers.send(:utility, nil)
end.to raise_error(
Backup::Errors::CLI::UtilityNotFoundError,
'CLI::UtilityNotFoundError: Utility Name Empty'
)
end
it 'should raise an error if name is empty' do
expect do
- helpers.utility(' ')
+ helpers.send(:utility, ' ')
end.to raise_error(
Backup::Errors::CLI::UtilityNotFoundError,
'CLI::UtilityNotFoundError: Utility Name Empty'
)
end
@@ -263,38 +263,38 @@
describe '#command_name' do
context 'given a command line path with no arguments' do
it 'should return the base command name' do
cmd = '/path/to/a/command'
- helpers.command_name(cmd).should == 'command'
+ helpers.send(:command_name, cmd).should == 'command'
end
end
context 'given a command line path with a single argument' do
it 'should return the base command name' do
cmd = '/path/to/a/command with_args'
- helpers.command_name(cmd).should == 'command'
+ helpers.send(:command_name, cmd).should == 'command'
end
end
context 'given a command line path with multiple arguments' do
it 'should return the base command name' do
cmd = '/path/to/a/command with multiple args'
- helpers.command_name(cmd).should == 'command'
+ helpers.send(:command_name, cmd).should == 'command'
end
end
context 'given a command with no path and arguments' do
it 'should return the base command name' do
cmd = 'command args'
- helpers.command_name(cmd).should == 'command'
+ helpers.send(:command_name, cmd).should == 'command'
end
end
context 'given a command with no path and no arguments' do
it 'should return the base command name' do
cmd = 'command'
- helpers.command_name(cmd).should == 'command'
+ helpers.send(:command_name, cmd).should == 'command'
end
end
end # describe '#command_name'
end