2016-12-05 37 views
0

我正在用InSpec創建我的測試。這是我對Apache的測試:如何使用InSpec創建上下文?

require 'inspec' 

if os[:family] == 'redhat' 

    describe package 'httpd' do 
    it { should be_installed } 
    end 

    describe service 'httpd' do 
    it { should be_enabled } 
    it { should be_running } 
    end 

    describe file '/etc/httpd/conf/httpd.conf' do 
    it { should be_file } 
    end 
end 
describe port(80) do 
    it { should_not be_listening } 
end 

describe port(9000) do 
    it { should be_listening } 
end 

我的問題與上下文有關。在使用InSpec之前,我使用了ChefSpec,我喜歡如何創建上下文,輸出顯示您的上下文。對於輸出上面的例子是這樣的:

System Package 
    ✔ httpd should be installed 
    Service httpd 
    ✔ should be enabled 
    ✔ should be running 
    File /etc/httpd/conf/httpd.conf 
    ✔ should be file 
    Port 80 
    ✔ should not be listening 
    Port 9000 
    ✔ should be listening 

我會想在輸出中包括家庭風味或版本或拱,以瞭解和獲得更清晰的輸出,我的測試。

有什麼建議嗎?

+1

我認爲你正在尋找'control'請參閱[文檔](http://inspec.io/docs/reference/dsl_inspec/) – Tensibai

回答

3

首先,ChefSpec和InSpec做了完全不同的事情,所以兩者真的可比。其次,雖然InSpec支持某些級別的RSpec語法兼容性,但它幾乎不像ChefSpec或ServerSpec那樣都是完整的RSpec輔助程序庫。正如@Tensibai提到的,​​InSpec提供自己的custom syntax for more complex tests。如果您特別想使用RSpec describecontext塊系統或自定義RSpec格式化器,我會建議使用ServerSpec來代替。