Convert specs to RSpec 2.99.0.beta2 syntax with Transpec

This conversion is done by Transpec 1.10.2 with the following command:
    transpec

* 46 conversions
    from: obj.should
      to: expect(obj).to

* 20 conversions
    from: obj.stub(:message)
      to: allow(obj).to receive(:message)

* 10 conversions
    from: == expected
      to: eq(expected)

* 6 conversions
    from: obj.should_receive(:message)
      to: expect(obj).to receive(:message)

* 5 conversions
    from: obj.should_not
      to: expect(obj).not_to

* 5 conversions
    from: Klass.any_instance.stub(:message) { |arg| }
      to: Klass.any_instance.stub(:message) { |instance, arg| }

* 5 conversions
    from: Klass.any_instance.stub(:message)
      to: allow_any_instance_of(Klass).to receive(:message)

* 1 conversion
    from: lambda { }.should
      to: expect { }.to
This commit is contained in:
Fabio Rehm 2014-03-14 11:37:50 -03:00
parent 60f3a67bb0
commit 2e2c2fad56
10 changed files with 91 additions and 83 deletions

View file

@ -24,4 +24,8 @@ RSpec.configure do |config|
# the seed, which is printed after each run. # the seed, which is printed after each run.
# --seed 1234 # --seed 1234
config.order = 'random' config.order = 'random'
config.mock_with :rspec do |c|
c.yield_receiver_to_any_instance_implementation_blocks = true
end
end end

View file

@ -24,12 +24,12 @@ describe Vagrant::LXC::Action::ClearForwardedPorts do
after { FileUtils.rm_rf data_dir.to_s } after { FileUtils.rm_rf data_dir.to_s }
it 'removes all files under pid directory' do it 'removes all files under pid directory' do
Dir[pids_dir.to_s + "/redir_*.pid"].should be_empty expect(Dir[pids_dir.to_s + "/redir_*.pid"]).to be_empty
end end
context 'with a valid redir pid' do context 'with a valid redir pid' do
it 'kills known processes' do it 'kills known processes' do
subject.should have_received(:system).with("pkill -TERM -P #{pid}") expect(subject).to have_received(:system).with("pkill -TERM -P #{pid}")
end end
end end
@ -37,7 +37,7 @@ describe Vagrant::LXC::Action::ClearForwardedPorts do
let(:pid_cmd) { 'sudo ls' } let(:pid_cmd) { 'sudo ls' }
it 'does not kill the process' do it 'does not kill the process' do
subject.should_not have_received(:system).with("pkill -TERM -P #{pid}") expect(subject).not_to have_received(:system).with("pkill -TERM -P #{pid}")
end end
end end
end end

View file

@ -20,10 +20,10 @@ describe Vagrant::LXC::Action::CompressRootFS do
end end
it "asks the driver to compress container's rootfs" do it "asks the driver to compress container's rootfs" do
driver.should have_received(:compress_rootfs) expect(driver).to have_received(:compress_rootfs)
end end
it 'sets export.temp_dir on action env' do it 'sets export.temp_dir on action env' do
env['package.rootfs'].should == compressed_rootfs_path expect(env['package.rootfs']).to eq(compressed_rootfs_path)
end end
end end

View file

@ -33,7 +33,7 @@ describe Vagrant::LXC::Action::ForwardPorts do
it 'forwards ports using redir' do it 'forwards ports using redir' do
subject.stub(system: true) subject.stub(system: true)
subject.call(env) subject.call(env)
subject.should have_received(:spawn).with( expect(subject).to have_received(:spawn).with(
"redir --laddr=#{host_ip} --lport=#{host_port} --caddr=#{container_ip} --cport=#{guest_port} 2>/dev/null" "redir --laddr=#{host_ip} --lport=#{host_port} --caddr=#{container_ip} --cport=#{guest_port} 2>/dev/null"
) )
end end
@ -42,7 +42,7 @@ describe Vagrant::LXC::Action::ForwardPorts do
forward_conf.delete(:host_ip) forward_conf.delete(:host_ip)
subject.stub(system: true) subject.stub(system: true)
subject.call(env) subject.call(env)
subject.should have_received(:spawn).with( expect(subject).to have_received(:spawn).with(
"redir --lport=#{host_port} --caddr=#{container_ip} --cport=#{guest_port} 2>/dev/null" "redir --lport=#{host_port} --caddr=#{container_ip} --cport=#{guest_port} 2>/dev/null"
) )
end end
@ -51,7 +51,7 @@ describe Vagrant::LXC::Action::ForwardPorts do
forward_conf[:host_ip] = ' ' forward_conf[:host_ip] = ' '
subject.stub(system: true) subject.stub(system: true)
subject.call(env) subject.call(env)
subject.should have_received(:spawn).with( expect(subject).to have_received(:spawn).with(
"redir --lport=#{host_port} --caddr=#{container_ip} --cport=#{guest_port} 2>/dev/null" "redir --lport=#{host_port} --caddr=#{container_ip} --cport=#{guest_port} 2>/dev/null"
) )
end end
@ -60,18 +60,18 @@ describe Vagrant::LXC::Action::ForwardPorts do
subject.stub(system: true) subject.stub(system: true)
subject.call(env) subject.call(env)
pid_file = data_dir.join('pids', "redir_#{host_port}.pid").read pid_file = data_dir.join('pids', "redir_#{host_port}.pid").read
pid_file.should == pid expect(pid_file).to eq(pid)
end end
it 'allows disabling a previously forwarded port' do it 'allows disabling a previously forwarded port' do
forward_conf[:disabled] = true forward_conf[:disabled] = true
subject.stub(system: true) subject.stub(system: true)
subject.call(env) subject.call(env)
subject.should_not have_received(:spawn) expect(subject).not_to have_received(:spawn)
end end
it 'raises RedirNotInstalled error if `redir` is not installed' do it 'raises RedirNotInstalled error if `redir` is not installed' do
subject.stub(system: false) subject.stub(system: false)
lambda { subject.call(env) }.should raise_error(Vagrant::LXC::Errors::RedirNotInstalled) expect { subject.call(env) }.to raise_error(Vagrant::LXC::Errors::RedirNotInstalled)
end end
end end

View file

@ -28,33 +28,33 @@ describe Vagrant::LXC::Action::HandleBoxMetadata do
end end
it 'sets the tarball argument for the template' do it 'sets the tarball argument for the template' do
env[:lxc_template_opts].should include( expect(env[:lxc_template_opts]).to include(
'--tarball' => box_directory.join('rootfs.tar.gz').to_s '--tarball' => box_directory.join('rootfs.tar.gz').to_s
) )
end end
it 'sets the template --config parameter' do it 'sets the template --config parameter' do
env[:lxc_template_opts].should include( expect(env[:lxc_template_opts]).to include(
'--config' => box_directory.join('lxc-config').to_s '--config' => box_directory.join('lxc-config').to_s
) )
end end
it 'does not set the auth key argument for the template' do it 'does not set the auth key argument for the template' do
env[:lxc_template_opts].should_not include( expect(env[:lxc_template_opts]).not_to include(
'--auth-key' => vagrant_key '--auth-key' => vagrant_key
) )
end end
it 'sets the template options from metadata on env hash' do it 'sets the template options from metadata on env hash' do
env[:lxc_template_opts].should include(metadata['template-opts']) expect(env[:lxc_template_opts]).to include(metadata['template-opts'])
end end
xit 'sets the template source path on env hash' do xit 'sets the template source path on env hash' do
env[:lxc_template_src].should == box_directory.join('lxc-template').to_s expect(env[:lxc_template_src]).to eq(box_directory.join('lxc-template').to_s)
end end
it 'does not warn about deprecation' do it 'does not warn about deprecation' do
env[:ui].should_not have_received(:warn) expect(env[:ui]).not_to have_received(:warn)
end end
end end
@ -68,31 +68,31 @@ describe Vagrant::LXC::Action::HandleBoxMetadata do
end end
it 'sets the tarball argument for the template' do it 'sets the tarball argument for the template' do
env[:lxc_template_opts].should include( expect(env[:lxc_template_opts]).to include(
'--tarball' => box_directory.join('rootfs.tar.gz').to_s '--tarball' => box_directory.join('rootfs.tar.gz').to_s
) )
end end
it 'sets the auth key argument for the template' do it 'sets the auth key argument for the template' do
env[:lxc_template_opts].should include( expect(env[:lxc_template_opts]).to include(
'--auth-key' => vagrant_key '--auth-key' => vagrant_key
) )
end end
it 'sets the lxc config file parameter' do it 'sets the lxc config file parameter' do
env[:lxc_template_config].should == box_directory.join('lxc.conf').to_s expect(env[:lxc_template_config]).to eq(box_directory.join('lxc.conf').to_s)
end end
it 'sets the template options from metadata on env hash' do it 'sets the template options from metadata on env hash' do
env[:lxc_template_opts].should include(metadata['template-opts']) expect(env[:lxc_template_opts]).to include(metadata['template-opts'])
end end
xit 'sets the template source path on env hash' do xit 'sets the template source path on env hash' do
env[:lxc_template_src].should == box_directory.join('lxc-template').to_s expect(env[:lxc_template_src]).to eq(box_directory.join('lxc-template').to_s)
end end
it 'warns about deprecation' do it 'warns about deprecation' do
env[:ui].should have_received(:warn) expect(env[:ui]).to have_received(:warn)
end end
end end
@ -110,14 +110,14 @@ describe Vagrant::LXC::Action::HandleBoxMetadata do
end end
it 'raises an error if the rootfs tarball cant be found' do it 'raises an error if the rootfs tarball cant be found' do
File.stub(:exists?).with(box_directory.join('rootfs.tar.gz').to_s).and_return(false) allow(File).to receive(:exists?).with(box_directory.join('rootfs.tar.gz').to_s).and_return(false)
expect { expect {
subject.call(env) subject.call(env)
}.to raise_error(Vagrant::LXC::Errors::RootFSTarballMissing) }.to raise_error(Vagrant::LXC::Errors::RootFSTarballMissing)
end end
it 'does not raise an error if the lxc-template script cant be found' do it 'does not raise an error if the lxc-template script cant be found' do
File.stub(:exists?).with(box_directory.join('lxc-template').to_s).and_return(false) allow(File).to receive(:exists?).with(box_directory.join('lxc-template').to_s).and_return(false)
expect { expect {
subject.call(env) subject.call(env)
}.to_not raise_error }.to_not raise_error

View file

@ -30,24 +30,24 @@ describe Vagrant::LXC::Action::SetupPackageFiles do
before { subject.call(env) } before { subject.call(env) }
it 'copies box lxc-template to package directory' do it 'copies box lxc-template to package directory' do
env['package.directory'].join('lxc-template').should be_file expect(env['package.directory'].join('lxc-template')).to be_file
end end
it 'copies metadata.json to package directory' do it 'copies metadata.json to package directory' do
env['package.directory'].join('metadata.json').should be_file expect(env['package.directory'].join('metadata.json')).to be_file
end end
it 'copies box lxc.conf to package directory' do it 'copies box lxc.conf to package directory' do
env['package.directory'].join('lxc-template').should be_file expect(env['package.directory'].join('lxc-template')).to be_file
end end
it 'copies box lxc-config to package directory' do it 'copies box lxc-config to package directory' do
env['package.directory'].join('lxc-config').should be_file expect(env['package.directory'].join('lxc-config')).to be_file
end end
it 'moves the compressed rootfs to package directory' do it 'moves the compressed rootfs to package directory' do
env['package.directory'].join(rootfs_path.basename).should be_file expect(env['package.directory'].join(rootfs_path.basename)).to be_file
env['package.rootfs'].should_not be_file expect(env['package.rootfs']).not_to be_file
end end
end end

View file

@ -13,18 +13,18 @@ describe Vagrant::LXC::Driver::CLI do
let(:result) { @result } let(:result) { @result }
before do before do
subject.stub(:run).with(:ls).and_return(lxc_ls_out) allow(subject).to receive(:run).with(:ls).and_return(lxc_ls_out)
@result = subject.list @result = subject.list
end end
it 'grabs previously created containers from lxc-ls output' do it 'grabs previously created containers from lxc-ls output' do
result.should be_an Enumerable expect(result).to be_an Enumerable
result.should include 'a-container' expect(result).to include 'a-container'
result.should include 'dup-container' expect(result).to include 'dup-container'
end end
it 'removes duplicates from lxc-ls output' do it 'removes duplicates from lxc-ls output' do
result.uniq.should == result expect(result.uniq).to eq(result)
end end
end end
@ -32,11 +32,11 @@ describe Vagrant::LXC::Driver::CLI do
let(:lxc_version_out) { "lxc version: 0.x.y-rc1\n" } let(:lxc_version_out) { "lxc version: 0.x.y-rc1\n" }
before do before do
subject.stub(:run).with(:version).and_return(lxc_version_out) allow(subject).to receive(:run).with(:version).and_return(lxc_version_out)
end end
it 'parses the version from the output' do it 'parses the version from the output' do
subject.version.should == '0.x.y-rc1' expect(subject.version).to eq('0.x.y-rc1')
end end
end end
@ -49,12 +49,12 @@ describe Vagrant::LXC::Driver::CLI do
subject { described_class.new(sudo_wrapper, name) } subject { described_class.new(sudo_wrapper, name) }
before do before do
subject.stub(:run) { |*args| @run_args = args } allow(subject).to receive(:run) { |*args| @run_args = args }
end end
it 'issues a lxc-create with provided template, container name and hash of arguments' do it 'issues a lxc-create with provided template, container name and hash of arguments' do
subject.create(template, config_file, template_args) subject.create(template, config_file, template_args)
subject.should have_received(:run).with( expect(subject).to have_received(:run).with(
:create, :create,
'--template', template, '--template', template,
'--name', name, '--name', name,
@ -66,7 +66,7 @@ describe Vagrant::LXC::Driver::CLI do
end end
it 'wraps a low level error into something more meaningful in case the container already exists' do it 'wraps a low level error into something more meaningful in case the container already exists' do
subject.stub(:run) { raise Vagrant::LXC::Errors::ExecuteError, stderr: 'alreAdy Exists' } allow(subject).to receive(:run) { raise Vagrant::LXC::Errors::ExecuteError, stderr: 'alreAdy Exists' }
expect { expect {
subject.create(template, config_file, template_args) subject.create(template, config_file, template_args)
}.to raise_error(Vagrant::LXC::Errors::ContainerAlreadyExists) }.to raise_error(Vagrant::LXC::Errors::ContainerAlreadyExists)
@ -79,12 +79,12 @@ describe Vagrant::LXC::Driver::CLI do
subject { described_class.new(sudo_wrapper, name) } subject { described_class.new(sudo_wrapper, name) }
before do before do
subject.stub(:run) allow(subject).to receive(:run)
subject.destroy subject.destroy
end end
it 'issues a lxc-destroy with container name' do it 'issues a lxc-destroy with container name' do
subject.should have_received(:run).with(:destroy, '--name', name) expect(subject).to have_received(:run).with(:destroy, '--name', name)
end end
end end
@ -93,12 +93,12 @@ describe Vagrant::LXC::Driver::CLI do
subject { described_class.new(sudo_wrapper, name) } subject { described_class.new(sudo_wrapper, name) }
before do before do
subject.stub(:run) allow(subject).to receive(:run)
end end
it 'starts container on the background' do it 'starts container on the background' do
subject.start subject.start
subject.should have_received(:run).with( expect(subject).to have_received(:run).with(
:start, :start,
'-d', '-d',
'--name', name '--name', name
@ -112,16 +112,16 @@ describe Vagrant::LXC::Driver::CLI do
before do before do
subject.stub(system: true) subject.stub(system: true)
subject.stub(:run) allow(subject).to receive(:run)
end end
it 'issues a lxc-shutdown with provided container name' do it 'issues a lxc-shutdown with provided container name' do
subject.shutdown subject.shutdown
subject.should have_received(:run).with(:shutdown, '--name', name) expect(subject).to have_received(:run).with(:shutdown, '--name', name)
end end
it 'raises a ShutdownNotSupported in case it is not supported' do it 'raises a ShutdownNotSupported in case it is not supported' do
subject.stub(:system).with('which lxc-shutdown > /dev/null').and_return(false) allow(subject).to receive(:system).with('which lxc-shutdown > /dev/null').and_return(false)
expect { subject.shutdown }.to raise_error(described_class::ShutdownNotSupported) expect { subject.shutdown }.to raise_error(described_class::ShutdownNotSupported)
end end
end end
@ -131,21 +131,21 @@ describe Vagrant::LXC::Driver::CLI do
subject { described_class.new(sudo_wrapper, name) } subject { described_class.new(sudo_wrapper, name) }
before do before do
subject.stub(:run).and_return("state: STOPPED\npid: 2") allow(subject).to receive(:run).and_return("state: STOPPED\npid: 2")
end end
it 'calls lxc-info with the right arguments' do it 'calls lxc-info with the right arguments' do
subject.state subject.state
subject.should have_received(:run).with(:info, '--name', name, retryable: true) expect(subject).to have_received(:run).with(:info, '--name', name, retryable: true)
end end
it 'maps the output of lxc-info status out to a symbol' do it 'maps the output of lxc-info status out to a symbol' do
subject.state.should == :stopped expect(subject.state).to eq(:stopped)
end end
it 'is not case sensitive' do it 'is not case sensitive' do
subject.stub(:run).and_return("StatE: STarTED\npid: 2") allow(subject).to receive(:run).and_return("StatE: STarTED\npid: 2")
subject.state.should == :started expect(subject.state).to eq(:started)
end end
end end
@ -161,17 +161,17 @@ describe Vagrant::LXC::Driver::CLI do
it 'calls lxc-attach with specified command' do it 'calls lxc-attach with specified command' do
subject.attach(*command) subject.attach(*command)
subject.should have_received(:run).with(:attach, '--name', name, '--', *command) expect(subject).to have_received(:run).with(:attach, '--name', name, '--', *command)
end end
it 'supports a "namespaces" parameter' do it 'supports a "namespaces" parameter' do
subject.stub(:run).with(:attach, '-h', :show_stderr => true).and_return({:stdout => '', :stderr => '--namespaces'}) allow(subject).to receive(:run).with(:attach, '-h', :show_stderr => true).and_return({:stdout => '', :stderr => '--namespaces'})
subject.attach *(command + [{namespaces: ['network', 'mount']}]) subject.attach *(command + [{namespaces: ['network', 'mount']}])
subject.should have_received(:run).with(:attach, '--name', name, '--namespaces', 'NETWORK|MOUNT', '--', *command) expect(subject).to have_received(:run).with(:attach, '--name', name, '--namespaces', 'NETWORK|MOUNT', '--', *command)
end end
it 'raises a NamespacesNotSupported error if not supported' do it 'raises a NamespacesNotSupported error if not supported' do
subject.stub(:run).with(:attach, '-h', :show_stderr => true).and_return({:stdout => '', :stderr => 'not supported'}) allow(subject).to receive(:run).with(:attach, '-h', :show_stderr => true).and_return({:stdout => '', :stderr => 'not supported'})
expect { expect {
subject.attach *(command + [{namespaces: ['network', 'mount']}]) subject.attach *(command + [{namespaces: ['network', 'mount']}])
}.to raise_error(Vagrant::LXC::Errors::NamespacesNotSupported) }.to raise_error(Vagrant::LXC::Errors::NamespacesNotSupported)
@ -187,9 +187,9 @@ describe Vagrant::LXC::Driver::CLI do
end end
it 'yields a cli object' do it 'yields a cli object' do
subject.stub(:shutdown) allow(subject).to receive(:shutdown)
subject.transition_to(:stopped) { |c| c.shutdown } subject.transition_to(:stopped) { |c| c.shutdown }
subject.should have_received(:shutdown) expect(subject).to have_received(:shutdown)
end end
it 'throws an exception if block is not provided' do it 'throws an exception if block is not provided' do

View file

@ -42,16 +42,16 @@ describe Vagrant::LXC::Driver do
subject { described_class.new(nil, nil, cli) } subject { described_class.new(nil, nil, cli) }
before do before do
subject.stub(:import_template).and_yield(template_name) allow(subject).to receive(:import_template).and_yield(template_name)
subject.create name, template_path, config_file, template_opts subject.create name, template_path, config_file, template_opts
end end
it 'sets the cli object container name' do it 'sets the cli object container name' do
cli.should have_received(:name=).with(name) expect(cli).to have_received(:name=).with(name)
end end
it 'creates container with the right arguments' do it 'creates container with the right arguments' do
cli.should have_received(:create).with( expect(cli).to have_received(:create).with(
template_name, template_name,
config_file, config_file,
template_opts template_opts
@ -67,7 +67,7 @@ describe Vagrant::LXC::Driver do
before { subject.destroy } before { subject.destroy }
it 'delegates to cli object' do it 'delegates to cli object' do
cli.should have_received(:destroy) expect(cli).to have_received(:destroy)
end end
end end
@ -89,7 +89,7 @@ describe Vagrant::LXC::Driver do
it 'writes configurations to config file' it 'writes configurations to config file'
it 'starts container with configured customizations' do it 'starts container with configured customizations' do
cli.should have_received(:start) expect(cli).to have_received(:start)
end end
end end
@ -99,30 +99,30 @@ describe Vagrant::LXC::Driver do
subject { described_class.new('name', nil, cli) } subject { described_class.new('name', nil, cli) }
before do before do
cli.stub(:transition_to).and_yield(cli) allow(cli).to receive(:transition_to).and_yield(cli)
end end
it 'delegates to cli shutdown' do it 'delegates to cli shutdown' do
cli.should_receive(:shutdown) expect(cli).to receive(:shutdown)
subject.forced_halt subject.forced_halt
end end
it 'expects a transition to running state to take place' do it 'expects a transition to running state to take place' do
cli.should_receive(:transition_to).with(:stopped) expect(cli).to receive(:transition_to).with(:stopped)
subject.forced_halt subject.forced_halt
end end
it 'attempts to force the container to stop in case a shutdown doesnt work' do it 'attempts to force the container to stop in case a shutdown doesnt work' do
cli.stub(:shutdown).and_raise(Vagrant::LXC::Driver::CLI::TargetStateNotReached.new :target, :source) allow(cli).to receive(:shutdown).and_raise(Vagrant::LXC::Driver::CLI::TargetStateNotReached.new :target, :source)
cli.should_receive(:transition_to).with(:stopped).twice expect(cli).to receive(:transition_to).with(:stopped).twice
cli.should_receive(:stop) expect(cli).to receive(:stop)
subject.forced_halt subject.forced_halt
end end
it 'attempts to force the container to stop in case lxc-shutdown is not supported' do it 'attempts to force the container to stop in case lxc-shutdown is not supported' do
cli.stub(:shutdown).and_raise(Vagrant::LXC::Driver::CLI::ShutdownNotSupported) allow(cli).to receive(:shutdown).and_raise(Vagrant::LXC::Driver::CLI::ShutdownNotSupported)
cli.should_receive(:transition_to).with(:stopped).twice expect(cli).to receive(:transition_to).with(:stopped).twice
cli.should_receive(:stop) expect(cli).to receive(:stop)
subject.forced_halt subject.forced_halt
end end
end end
@ -134,7 +134,7 @@ describe Vagrant::LXC::Driver do
subject { described_class.new('name', nil, cli) } subject { described_class.new('name', nil, cli) }
it 'delegates to cli' do it 'delegates to cli' do
subject.state.should == cli_state expect(subject.state).to eq(cli_state)
end end
end end
@ -154,18 +154,18 @@ describe Vagrant::LXC::Driver do
end end
it "creates guest folder under container's rootfs" do it "creates guest folder under container's rootfs" do
sudo_wrapper.should have_received(:run).with("mkdir", "-p", expected_guest_path) expect(sudo_wrapper).to have_received(:run).with("mkdir", "-p", expected_guest_path)
end end
it 'adds a mount.entry to its local customizations' do it 'adds a mount.entry to its local customizations' do
subject.customizations.should include [ expect(subject.customizations).to include [
'mount.entry', 'mount.entry',
"#{shared_folder[:hostpath]} #{expected_guest_path} none bind 0 0" "#{shared_folder[:hostpath]} #{expected_guest_path} none bind 0 0"
] ]
end end
it 'supports additional mount options' do it 'supports additional mount options' do
subject.customizations.should include [ expect(subject.customizations).to include [
'mount.entry', 'mount.entry',
"#{ro_rw_folder[:hostpath]} #{rootfs_path}/vagrant/ro_rw none ro,rw 0 0" "#{ro_rw_folder[:hostpath]} #{rootfs_path}/vagrant/ro_rw none ro,rw 0 0"
] ]

View file

@ -2,23 +2,23 @@ module UnitExampleGroup
def self.included(base) def self.included(base)
base.metadata[:type] = :unit base.metadata[:type] = :unit
base.before do base.before do
Object.any_instance.stub(:system) { |*args, &block| allow_any_instance_of(Object).to receive(:system) { |instance, *args, &block|
UnitExampleGroup.prevent_system_calls(*args, &block) UnitExampleGroup.prevent_system_calls(*args, &block)
} }
Object.any_instance.stub(:`) { |*args, &block| allow_any_instance_of(Object).to receive(:`) { |instance, *args, &block|
UnitExampleGroup.prevent_system_calls(*args, &block) UnitExampleGroup.prevent_system_calls(*args, &block)
} }
Object.any_instance.stub(:exec) { |*args, &block| allow_any_instance_of(Object).to receive(:exec) { |instance, *args, &block|
UnitExampleGroup.prevent_system_calls(*args, &block) UnitExampleGroup.prevent_system_calls(*args, &block)
} }
Object.any_instance.stub(:fork) { |*args, &block| allow_any_instance_of(Object).to receive(:fork) { |instance, *args, &block|
UnitExampleGroup.prevent_system_calls(*args, &block) UnitExampleGroup.prevent_system_calls(*args, &block)
} }
Object.any_instance.stub(:spawn) { |*args, &block| allow_any_instance_of(Object).to receive(:spawn) { |instance, *args, &block|
UnitExampleGroup.prevent_system_calls(*args, &block) UnitExampleGroup.prevent_system_calls(*args, &block)
} }
require 'vagrant/util/subprocess' require 'vagrant/util/subprocess'
Vagrant::Util::Subprocess.stub(:execute) { |*args, &block| allow(Vagrant::Util::Subprocess).to receive(:execute) { |*args, &block|
UnitExampleGroup.prevent_system_calls(*args, &block) UnitExampleGroup.prevent_system_calls(*args, &block)
} }
end end

View file

@ -10,4 +10,8 @@ RSpec.configure do |config|
config.include UnitExampleGroup, :type => :unit, :example_group => { config.include UnitExampleGroup, :type => :unit, :example_group => {
:file_path => /\bspec\/unit\// :file_path => /\bspec\/unit\//
} }
config.mock_with :rspec do |c|
c.yield_receiver_to_any_instance_implementation_blocks = true
end
end end