2016-05-25 79 views
1

我正在嘗試編寫serverspec測試,檢查配方是否使用廚師,廚房和流浪者與debian jessie box設置mariadb-server。Serverspec包檢查總是返回true

配方很簡單:

# cookbooks/mariadb/recipes/server.rb 
package 'mariadb-server' do 
    action :install 
end 

它我寫的規格是:

# cookbooks/mariadb/test/integration/default/serverspec/server_spec.rb 
require 'spec_helper' 

describe 'mariadb::server' do 
    context package('mariadb-server') do 
    it 'is installed' do 
     expect be_installed 
    end 
    end 
end 

但是,在運行時kitchen verify,這總是返回true,不管包的狀態。如果我進入流浪箱並取出包裹,然後運行kitchen verify,我也獲得了積極的結果。

即使我將包改爲一些隨機字符串,例如context package('this-is-not-a-package') do測試結果爲真。

我在這裏做錯了什麼?

回答

2

從更一般的意義上說,這不是遵循RSpec 3匹配器語法。

你可以考慮做這樣的:

describe 'mariadb::server' do 
    describe package('mariadb-server') do 
    it { expect(subject).to be_installed } 
    end 
end 

這看起來更乾淨,將輸出清潔劑,因爲serverspec使用的RSpec的輸出文件格式。

爲了讓您更清楚地瞭解發生了什麼,以便了解這裏發生了什麼,並且不是假設這完全是魔術,下面是如何進行這些檢查的一般模板:

describe method(argument) do 
    it { expect(subject).to be_boolean-matcher.with_chain(argument_two) } 
end 

和您的具體情況(你沒有使用version鏈,但我加了它額外的信息)

  • 方法:包
  • 說法:MariaDB的服務器
  • 主題:將解析到包(MariaDB的服務器)
  • 布爾匹配:安裝
  • 鏈:版本
  • argument_two:1.2.3