测试没有动作并接收到通知的块吗?

问题描述:

所以,我想在我的食谱中添加一些单元测试。测试没有动作并接收到通知的块吗?

测试有动作的东西很容易。 但是当你的行动是:什么都不是,因为它被通知触发,然后它很糟糕。 以下块被调用: 通知:创建“目录[创建我的目录]”,:立即

directory 'Create my directory' do 
    path myPath 
    mode '0755' 
    owner 'me' 
    group 'aGroup' 
    action :nothing 
    notifies :create_if_missing, 'remote_file[Download artifact]', :immediately 
    notifies :run, 'execute[unpack artifact]', :immediately 
end 

当动作是以前:创建单元测试很简单

it 'Test create directory' do 
    expect(chef_run).to create_directory('Create my directory') 
     .with_path('myPath') 
     .with_mode('0755') 
     .with_owner('me') 
     .with_group('aGroup') 
end 

那么如何在收到通知时测试一些东西?

评论action :nothing,进行厨房测试运行并查看结果。测试结束后,不要忘记取消注释。