我在提交项目时在travis ci中收到以下错误:
Failures:
1) salt on unsupported distributions we fail
Failure/Error: expect { subject }.to raise_error(/Unsupported platform: Unsupported/)
expected Exception with message matching /Unsupported platform: Unsupported/ but nothing was raised
# ./spec/classes/salt_spec.rb:9:in `block (3 levels) in <top (required)>'
Finished in 6.5 seconds
47 examples, 1 failure
Failed examples:
rspec ./spec/classes/salt_spec.rb:8 # salt on unsupported distributions we fail
/home/travis/.rvm/rubies/ruby-2.0.0-p598/bin/ruby -S rspec spec/classes/salt_spec.rb --color failed
这是salt_spec.rb
:
require 'spec_helper'
describe 'salt' do
context 'on unsupported distributions' do
let(:facts) {{ :osfamily => 'Unsupported' }}
it 'we fail' do
expect { subject }.to raise_error(/Unsupported platform: Unsupported/)
end
end
['Debian', 'RedHat', 'SUSE', ].each do |distro|
context "on #{distro}" do
let(:facts) {{
:osfamily => distro,
}}
it { should contain_class('salt::master::install') }
it { should contain_class('salt::master::config') }
it { should contain_class('salt::master::service') }
it { should contain_class('salt::minion::install') }
it { should contain_class('salt::minion::config') }
it { should contain_class('salt::minion::service') }
##
## salt-master config file
##
describe 'config file with default params' do
it { should contain_file('/etc/salt/master')}
end
##
## salt-minion config file
##
describe 'config file with default params' do
it { should contain_file('/etc/salt/minion')}
end
##
## salt-master service
##
describe 'service with default params' do
it { should contain_service('salt-master').with(
'ensure' => 'running',
'enable' => 'true',
'hasstatus' => 'true',
'hasrestart' => 'true'
)}
end
##
## salt-minion service
##
describe 'service with default params' do
it { should contain_service('salt-minion').with(
'ensure' => 'running',
'enable' => 'true',
'hasstatus' => 'true',
'hasrestart' => 'true'
)}
end
##
## salt::master::install
##
it 'installs the salt-master package' do
should contain_package('salt-master').with(
'ensure' => 'present',
'name' => 'salt-master'
)
end
##
## salt::minion::install
##
it 'installs the salt-minion package' do
should contain_package('salt-minion').with(
'ensure' => 'present',
'name' => 'salt-minion'
)
end
end
end
['Archlinux', ].each do |distro|
context "on #{distro}" do
let(:facts) {{
:osfamily => distro,
}}
it { should contain_class('salt::master::install') }
it { should contain_class('salt::master::config') }
it { should contain_class('salt::master::service') }
it { should contain_class('salt::minion::install') }
it { should contain_class('salt::minion::config') }
it { should contain_class('salt::minion::service') }
##
## salt-master config file
##
describe 'config file with default params' do
it { should contain_file('/etc/salt/master')}
end
##
## salt-minion config file
##
describe 'config file with default params' do
it { should contain_file('/etc/salt/minion')}
end
##
## salt-master service
##
describe 'service with default params' do
it { should contain_service('salt-master').with(
'ensure' => 'running',
'enable' => 'true',
'hasstatus' => 'true',
'hasrestart' => 'true'
)}
end
##
## salt-minion service
##
describe 'service with default params' do
it { should contain_service('salt-minion').with(
'ensure' => 'running',
'enable' => 'true',
'hasstatus' => 'true',
'hasrestart' => 'true'
)}
end
end
end
end
如果我正确理解block (3 levels) in <top (required)>
,那么第5行和第11行之间的缩进是错误的,但是对我来说似乎是正确的。任何和所有这方面的帮助将不胜感激,因为这是我第一次处理rspec而我正在努力学习。
修改 我自己解决了这个问题。我改变了我的代码:
context 'on unsupported distributions' do
let(:facts) {{ :osfamily => 'Unsupported' }}
it 'we fail' do
expect { subject }.to raise_error(/Unsupported platform: Unsupported/)
end
end
对此:
context 'on unsupported distributions' do
let(:facts) {{ :osfamily => 'Unsupported' }}
it 'we fail' do
should compile.and_raise_error(/Unsupported platform: Unsupported/)
end
end
现在似乎正在过去。我想我的问题是:这是正确的还是我错误地通过了考试?
答案 0 :(得分:0)
通过更改以下内容解决了这个问题:
关于不受支持的发行版的背景&#39;做 let(:facts){{:osfamily =&gt; &#39;不支持&#39; }}
it 'we fail' do
expect { subject }.to raise_error(/Unsupported platform: Unsupported/)
end
对此:
关于不受支持的发行版的背景&#39;做 let(:facts){{:osfamily =&gt; &#39;不支持&#39; }}
it 'we fail' do
should compile.and_raise_error(/Unsupported platform: Unsupported/)
end