我創建了一個簡單的木偶4類和單元測試與它一起去如下(執行後touch metadata.json; rspec-puppet-init
而在modules/test/
):正確啓動RSpec的木偶單元方法進行試驗,
# modules/test/manifests/hello_world1.pp
class test::hello_world1 {
file { "/tmp/hello_world1":
content => "Hello, world!\n"
}
}
# modules/test/spec/classes/test__hello_world1_spec.rb
require 'spec_helper'
describe 'test::hello_world1' do
it { is_expected.to compile }
it { is_expected.to contain_file('/tmp/hello_world1')\
.with_content(/^Hello, world!$/) }
end
我可以成功通過在modules/test/
中執行rspec spec/classes/test__hello_world1_spec.rb
來運行單元測試。
我現在想繼續使用代碼從另一個模塊一個稍微更先進的階級,即concat
(模塊已arleady被安裝在modules/concat
):
# modules/test/manifests/hello_world2.pp
class test::hello_world2
{
concat{ "/tmp/hello_world2":
ensure => present,
}
concat::fragment{ "/tmp/hello_world2_01":
target => "/tmp/hello_world2",
content => "Hello, world!\n",
order => '01',
}
}
# modules/test/spec/classes/test__hello_world2_spec.rb
require 'spec_helper'
describe 'test::hello_world2' do
it { is_expected.to compile }
# ...
end
當我試圖運行這個單元測試與rspec spec/classes/test__hello_world2_spec.rb
而在modules/test
我接收包括的錯誤消息:
Failure/Error: it { is_expected.to compile } error during compilation: Evaluation Error: Error while evaluating a Resource Statement, Unknown resource type: 'concat'
我懷疑的根本原因是,rspec
找不到其它模塊(多個) ,因爲它沒有被告知「模塊路徑」。
我的問題是:我該如何開始單元測試,尤其是那些需要訪問其他模塊的單元測試?