2015-11-30 24 views
-1

提交項目時我收到以下錯誤特拉維斯CI:Rspec的塊(3級),在<頂部(必填)>錯誤

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

不知道爲什麼這得到了否決票。答案並不是很明顯,我不得不通過git來尋找解決方案。 – beardedeagle

回答

0

通過改變以下解決這個{{:osfamily => '不支持的'}}

it 'we fail' do 
    expect { subject }.to raise_error(/Unsupported platform: Unsupported/) 
end 

向該:

(:事實){{:osfamily => '不支持的'}}

it 'we fail' do 
    should compile.and_raise_error(/Unsupported platform: Unsupported/) 
end 

'上不支持的分佈' 做 設上下文

相關問題