【发布时间】:2018-05-29 11:30:59
【问题描述】:
我正在编写chefspec测试,我有以下代码
recipe
execute 'stop Server' do
user '123'
group 'ad'
live_stream true
command "/udd001/app/WebSphere/AppServer/profiles/AppSrv01/bin/stopServer.sh $server -username wasserver -password #{password}"
only_if { ::File.exist?('/mypath/'+variable[:myserver) }
spec
require 'spec_helper'
describe 'cookbook::myserver' do
before do
allow(File).to receive(:exist?).and_call_original
allow(File).to receive(:exist?).with('/mypath/'+variable[:appserver_profile]).and_return(true)
end
context 'When all attributes are default, on Ubuntu 16.04' do
let(:chef_run) do
runner = ChefSpec::ServerRunner.new(platform: 'ubuntu', version: '16.04')
runner.converge(described_recipe)
end
it 'converges successfully' do
expect { chef_run }.to_not raise_error
end
it 'stop Server' do
expect(chef_run).to run_execute('myserver').with(
user: '123',
group: 'ad',
live_stream: true)
end
end
end
由于未定义局部变量“变量”而失败
【问题讨论】:
标签: ruby-on-rails rspec chef-infra chefspec