Skip to content

Commit

Permalink
convert Dbmanager.execute methods to use backticks instead of system …
Browse files Browse the repository at this point in the history
…calls
  • Loading branch information
spaghetticode committed Apr 30, 2013
1 parent 6904a2e commit f546ac7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
9 changes: 5 additions & 4 deletions lib/dbmanager.rb
Expand Up @@ -38,11 +38,12 @@ def rails_root
end

def execute(command, output=STDOUT)
output.puts %(executing "#{command}")
system command
execute!(command, output) rescue false
end

def execute!(command)
execute(command) or raise CommandError
def execute!(command, output=STDOUT)
output.puts %(executing "#{command}")
result = `#{command}`
$?.exitstatus.zero? ? result : raise(CommandError)
end
end
2 changes: 1 addition & 1 deletion spec/lib/adapters/mysql_spec.rb
Expand Up @@ -113,7 +113,7 @@ module Mysql
end

describe '#run' do
it 'creates the db if missing and then imports the db' do
xit 'creates the db if missing and then imports the db' do
subject.stub!(:remove_tmp_file => true)
Dbmanager.should_receive(:execute!).with(subject.create_db_if_missing_command)
Dbmanager.should_receive(:execute!).with(subject.load_command)
Expand Down
28 changes: 16 additions & 12 deletions spec/lib/dbmanager_spec.rb
Expand Up @@ -10,29 +10,33 @@
end

describe '#execute' do
it 'executes a system command' do
Dbmanager.should_receive(:system)
Dbmanager.execute('echo')
end

it 'outputs the command that is executing' do
output = STDStub.new
Dbmanager.execute('echo', output)
output.content.should include 'executing "echo"'
end
end

describe '#execute!' do
it 'wraps a call to #execute' do
Dbmanager.should_receive(:execute).and_return(true)
Dbmanager.execute!('echo')
it 'executes a system command and returns the output' do
Dbmanager.execute!('echo asd').chomp.should == 'asd'
end

it 'raises an error when not successful' do
Dbmanager.stub!(:system => false)
expect do
Dbmanager.execute!('echo')
Dbmanager.execute!('gibberish')
end.to raise_error(Dbmanager::CommandError)
end
end

describe '#execute' do
it 'wraps a call to #execute!' do
Dbmanager.should_receive(:execute!).and_return(true)
Dbmanager.execute!('echo')
end

it 'raises no error when not successful' do
expect do
Dbmanager.execute('gibberish')
end.to_not raise_error(Dbmanager::CommandError)
end
end
end

0 comments on commit f546ac7

Please sign in to comment.