spec/command_spec.rb in vagrant-shell-commander-0.1.4 vs spec/command_spec.rb in vagrant-shell-commander-0.2.0
- old
+ new
@@ -55,66 +55,80 @@
before(:each) do
machine.stub_chain(:state, :id).and_return(:not_running)
end
it 'reports information about state' do
- ui.should_receive(:warn).with("Machine #{machine_name} is not running.")
+ expect(ui).to receive(:warn).with("Machine #{machine_name} is not running.")
end
it 'dows not try to execute the command' do
- machine.should_not_receive(:communicate)
+ expect(machine).not_to receive(:communicate)
end
end
context 'running machine' do
let(:cmd) {'command'}
let(:dir) {'dir'}
+ let(:user) {'user'}
let(:communicate) {double(execute: true)}
before(:each) do
VagrantShellCommander::OptionManager.stub_chain(:new, :execute).
and_return(parser: 'parser', values: {cmd: cmd})
machine.stub_chain(:state, :id).and_return(:running)
- machine.stub(:communicate).and_return(communicate)
+ allow(ui).to receive(:success)
+ allow(machine).to receive(:action)
end
it 'executes the given command' do
- communicate.should_receive(:execute).with(cmd)
+ expect(machine).to receive(:action).with(:ssh_run, ssh_run_command: cmd)
end
- it 'shows the command output along with the machine name' do
- data = 'data'
-
- communicate.stub(:execute).and_yield('type', data)
-
- ui.should_receive(:success).with("#{machine_name}::")
- ui.should_receive(:info).with(data)
+ it 'shows the machine name' do
+ expect(ui).to receive(:success).with("#{machine_name}::")
end
it 'executes the command in the given dir' do
VagrantShellCommander::OptionManager.stub_chain(:new, :execute).
and_return(parser: 'parser', values: {cmd: cmd, dir: dir})
- communicate.should_receive(:execute).with("cd #{dir} && #{cmd}")
+ expect(machine).to receive(:action).with(:ssh_run,
+ ssh_run_command: "cd #{dir} && #{cmd}")
end
+ it 'executes the command for the given user' do
+ VagrantShellCommander::OptionManager.stub_chain(:new, :execute).
+ and_return(parser: 'parser', values: {cmd: cmd, user: user})
+
+ expect(machine).to receive(:action).with(:ssh_run,
+ ssh_run_command: "sudo su - #{user} -c \"#{cmd}\"")
+ end
+
+ it 'executes the command for the given user and the given dir' do
+ VagrantShellCommander::OptionManager.stub_chain(:new, :execute).
+ and_return(parser: 'parser', values: {cmd: cmd, user: user, dir: dir})
+
+ expect(machine).to receive(:action).with(:ssh_run,
+ ssh_run_command: "sudo su - #{user} -c \"cd #{dir} && #{cmd}\"")
+ end
+
describe 'shows help' do
let(:parser) {'parser'}
after(:each) do
- subject.should_not_receive(:with_target_vms)
- ui.should_receive(:info).with(parser)
+ expect(subject).not_to receive(:with_target_vms)
+ expect(ui).to receive(:info).with(parser)
end
it 'an empty command' do
VagrantShellCommander::OptionManager.stub_chain(:new, :execute).
and_return(parser: parser, values: {cmd: '', dir: dir})
end
it 'non present command' do
VagrantShellCommander::OptionManager.stub_chain(:new, :execute).
- and_return(parser: parser, values: {dir: dir})
+ and_return(parser: parser, values: {user: user})
end
end
end
end
end