Rspec &引用;“找不到食谱”;ChefSpec测试错误
我正在试着运行我的ChefSpec测试 这是我的ChefSpec测试:Rspec &引用;“找不到食谱”;ChefSpec测试错误,rspec,berkshelf,chefspec,Rspec,Berkshelf,Chefspec,我正在试着运行我的ChefSpec测试 这是我的ChefSpec测试: require_relative '../spec_helper' describe 'my-demo::basesystem' do let(:chef_run) { ChefSpec::Runner.new.converge(described_recipe)} describe 'basesystem' do it "should be installed" do expect(ch
require_relative '../spec_helper'
describe 'my-demo::basesystem' do
let(:chef_run) { ChefSpec::Runner.new.converge(described_recipe)}
describe 'basesystem' do
it "should be installed" do
expect(chef_run).to install_package('build-essential')
end
end
end
这是我的食谱
include_recipe 'build-essential::default'
这是我执行ChefSpec测试时的错误输出
================================================================================
Recipe Compile Error in /tmp/d20140208-11211-1tu0tmq/my-demo/recipes/basesystem.rb
================================================================================
Chef::Exceptions::CookbookNotFound
----------------------------------
Cookbook build-essential:: not found. If you're loading build-essential:: from another cookbook, make sure you configure the dependency in your metadata
Cookbook Trace:
---------------
/tmp/d20140208-11211-1tu0tmq/build-essential/recipes/default.rb:21:in `from_file'
/tmp/d20140208-11211-1tu0tmq/my-demo/recipes/basesystem.rb:2:in `from_file'
Relevant File Content:
----------------------
/tmp/d20140208-11211-1tu0tmq/build-essential/recipes/default.rb:
14: # distributed under the License is distributed on an "AS IS" BASIS,
15: # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16: # See the License for the specific language governing permissions and
17: # limitations under the License.
18: #
19:
20: begin
21>> include_recipe "build-essential::#{node['platform_family']}"
22: rescue Chef::Exceptions::RecipeNotFound
23: Chef::Log.warn "A build-essential recipe does not exist for the platform_family: #{node['platform_family']}"
24: end
25:
Chef::Exceptions::CookbookNotFound: Cookbook build-essential:: not found. If you're loading build-essential:: from another cookbook, make sure you configure the dependency in your metadata
/tmp/d20140208-11211-1tu0tmq/build-essential/recipes/default.rb:21:in `from_file'
/tmp/d20140208-11211-1tu0tmq/my-demo/recipes/basesystem.rb:2:in `from_file'
./spec/recipes/base_system_spec.rb:5:in `block (2 levels) in <top (required)>'
./spec/recipes/base_system_spec.rb:8:in `block (2 levels) in <top (required)>'
1 example, 1 failure, 0 passed
Finished in 0.062297226 seconds
Process finished with exit code 1
================================================================================
/tmp/d20140208-11211-1tu0tmq/my demo/recipes/basesystem.rb中的配方编译错误
================================================================================
厨师长::异常::CookbookNotFound
----------------------------------
Cookbook build essential::未找到。如果您正在从另一本烹饪书加载build-essential::,请确保在元数据中配置依赖项
食谱跟踪:
---------------
/tmp/d20140208-11211-1tu0tmq/build-essential/recipes/default.rb:21:in“from_文件”
/tmp/d20140208-11211-1tu0tmq/my demo/recipes/basesystem.rb:2:in'from_file'
相关文件内容:
----------------------
/tmp/d20140208-11211-1tu0tmq/build-essential/recipes/default.rb:
14:#根据许可证分发是按“原样”分发的,
15:#无任何明示或暗示的保证或条件。
16:#请参阅许可证,了解管理权限和权限的特定语言
17:#许可证下的限制。
18: #
19:
20:开始
21>>包括_配方“基本构建::#{node['platform_family']}”
22:救援厨师长::例外::RecipeNotFound
23:Chef::Log.warn“平台族:{node['platform\u family']}不存在构建基本配方”
24:完
25:
厨师::异常::CookbookNotFound:CookbookBuildEssential::未找到。如果您正在从另一本烹饪书加载build-essential::,请确保在元数据中配置依赖项
/tmp/d20140208-11211-1tu0tmq/build-essential/recipes/default.rb:21:in“from_文件”
/tmp/d20140208-11211-1tu0tmq/my demo/recipes/basesystem.rb:2:in'from_file'
./spec/recipes/base_system_spec.rb:5:in'block(2层)in'
./spec/recipes/base_system_spec.rb:8:in'block(2层)in'
1个示例,1个失败,0个通过
以0.062297226秒完成
进程已完成,退出代码为1
我不知道问题出在哪里,我认为Berkself可以解决cookbooks的依赖关系。如果您查看stacktrace:
20: begin
21>> include_recipe "build-essential::#{node['platform_family']}"
22: rescue Chef::Exceptions::RecipeNotFound
23: Chef::Log.warn "A build-essential recipe does not exist for the platform_family: #{node['platform_family']}"
24: end
您将在第21行看到build essential cookbook正在尝试加载与当前节点的平台系列对应的配方。但是,对于ChefSpec,除非您明确告诉ChefSpec要模拟哪种节点,否则不会设置该数据。换句话说,node['platform\u family']
是nil
,因此它试图包含一个名为build-essential::(nothing)
,这是无效的
要解决此问题,可以设置平台族的值:
let(chef_run) do
ChefSpec::Runner.new do |node|
node.automatic['platform_family'] = 'ubuntu'
end.converge(described_recipe)
end
或者(首选),您可以告诉ChefSpec模拟节点:
let(:chef_run) { ChefSpec::Runner.new(platform: 'ubuntu', version: '12.04').converge(described_recipe) }
请张贴您的规格帮助以及