diff --git a/lib/vagrant-lxc/sudo_wrapper.rb b/lib/vagrant-lxc/sudo_wrapper.rb index c6ba2b7..ff267c7 100644 --- a/lib/vagrant-lxc/sudo_wrapper.rb +++ b/lib/vagrant-lxc/sudo_wrapper.rb @@ -58,13 +58,11 @@ module Vagrant # Return the output, making sure to replace any Windows-style # newlines with Unix-style. + stdout = r.stdout.gsub("\r\n", "\n") if opts[:show_stderr] - { - :stdout => r.stdout.gsub("\r\n", "\n"), - :stderr => r.stderr.gsub("\r\n", "\n") - } + { :stdout => stdout, :stderr => r.stderr.gsub("\r\n", "\n") } else - r.stdout.gsub("\r\n", "\n") + stdout end end diff --git a/spec/unit/driver/cli_spec.rb b/spec/unit/driver/cli_spec.rb index 595ff5a..8597648 100644 --- a/spec/unit/driver/cli_spec.rb +++ b/spec/unit/driver/cli_spec.rb @@ -146,13 +146,13 @@ describe Vagrant::LXC::Driver::CLI do end it 'supports a "namespaces" parameter' do - subject.stub(:run).with(:attach, '-h', '2>&1').and_return('--namespaces') + subject.stub(:run).with(:attach, '-h', :show_stderr => true).and_return({:stdout => '', :stderr => '--namespaces'}) subject.attach *(command + [{namespaces: ['network', 'mount']}]) subject.should have_received(:run).with(:attach, '--name', name, '--namespaces', 'NETWORK|MOUNT', '--', *command) end it 'raises a NamespacesNotSupported error if not supported' do - subject.stub(:run).with(:attach, '-h', '2>&1').and_return('not supported') + subject.stub(:run).with(:attach, '-h', :show_stderr => true).and_return({:stdout => '', :stderr => 'not supported'}) expect { subject.attach *(command + [{namespaces: ['network', 'mount']}]) }.to raise_error(Vagrant::LXC::Errors::NamespacesNotSupported)