Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/bookworm/keys.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ module Bookworm
'determine_cookbook_name' => true,
'path_name_regex' => 'providers/(.*)\.rb',
},
'cookbookrspec' => {
'glob_pattern' => '*/spec/*_spec.rb',
'determine_cookbook_name' => true,
'path_name_regex' => 'spec/(.*)_spec\.rb',
},
}.freeze

# Set defaults
Expand Down
22 changes: 22 additions & 0 deletions lib/bookworm/rules/CookbookRspecExists.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright (c) 2026-present, Meta Platforms, Inc. and affiliates
# All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
description 'Helper rule to show existence of a cookbook rspec file'
keys %w{
cookbookrspec
}

def output
true
end
11 changes: 11 additions & 0 deletions spec/knowledge_base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,17 @@
} })
end

it 'holds all yer cookbookrspecs' do
kb = Bookworm::KnowledgeBase.new(
{ 'cookbookrspec' => [['mycookbook/spec/default_spec.rb', '(ast)']] },
)
expect(kb.cookbookrspecs).to eq({ 'mycookbook::default' => {
'path' => 'mycookbook/spec/default_spec.rb',
'cookbook' => 'mycookbook',
'ast' => '(ast)',
} })
end

it 'handles empty input' do
kb = Bookworm::KnowledgeBase.new({})
expect(kb.recipes).to eq({})
Expand Down
6 changes: 3 additions & 3 deletions spec/lib/keys_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
it 'contains expected key types' do
expected_keys = %w{
cookbook role metadatarb metadatajson recipe recipejson
attribute library resource provider
attribute library resource provider cookbookrspec
}
expect(keys.keys).to match_array(expected_keys)
end
Expand Down Expand Up @@ -77,8 +77,8 @@
end

describe 'determine_cookbook_name' do
it 'is true for recipe, attribute, library, resource, provider' do
%w{recipe attribute library resource provider}.each do |key|
it 'is true for recipe, attribute, library, resource, provider, cookbookrspec' do
%w{recipe attribute library resource provider cookbookrspec}.each do |key|
expect(keys[key]['determine_cookbook_name']).to eq(true)
end
end
Expand Down
26 changes: 26 additions & 0 deletions spec/rules/CookbookRspecExists_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright (c) 2026-present, Meta Platforms, Inc. and affiliates
# All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
require_relative './spec_helper'

describe Bookworm::InferRules::CookbookRspecExists do
it 'returns true when cookbookrspec file exists' do
ast = generate_ast(<<~RUBY)
describe 'my_cookbook::default' do
end
RUBY
rule = described_class.new({ 'ast' => ast })
expect(rule.output).to eq(true)
end
end
Loading