Skip to content

Commit

Permalink
Add tests for symbol conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
bastelfreak committed Jun 7, 2024
1 parent 6503541 commit d55cbf4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/facterdb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def self.valid_filters?(filters)
# @param symbolize_keys [Boolean]
# Whether to symbolize the keys. Note this is only on the top level and not
# on nested values.
def self.get_facts(filter = nil, cache = true, symbolize_keys: true)
def self.get_facts(filter = nil, cache = true, symbolize_keys = true)
if cache && filter && filter == Thread.current[:facterdb_last_filter_seen]
return Thread.current[:facterdb_last_facts_seen]
end
Expand Down
24 changes: 23 additions & 1 deletion spec/facter_db_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -319,14 +319,36 @@
end

describe '.get_facts' do

Check failure on line 321 in spec/facter_db_spec.rb

View workflow job for this annotation

GitHub Actions / rubocop

RSpec/MultipleMemoizedHelpers: Example group has too many memoized helpers [7/6] (https://rspec.rubystyle.guide/#let-blocks, https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/MultipleMemoizedHelpers)
subject(:result) { FacterDB.get_facts(filter) }
subject(:result) { FacterDB.get_facts(filter, cache, symbolize_keys) }

let(:filter) { nil }
let(:cache) { nil }
let(:symbolize_keys) { nil }

context 'without parameters' do

Check failure on line 328 in spec/facter_db_spec.rb

View workflow job for this annotation

GitHub Actions / rubocop

RSpec/MultipleMemoizedHelpers: Example group has too many memoized helpers [7/6] (https://rspec.rubystyle.guide/#let-blocks, https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/MultipleMemoizedHelpers)
include_examples 'returns a result'
end

context 'with stringified output' do

Check failure on line 332 in spec/facter_db_spec.rb

View workflow job for this annotation

GitHub Actions / rubocop

RSpec/MultipleMemoizedHelpers: Example group has too many memoized helpers [7/6] (https://rspec.rubystyle.guide/#let-blocks, https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/MultipleMemoizedHelpers)
let(:symbolize_keys) { false }

it 'returns strings as keys in factsets' do
result.each do |factset|
expect(factset.keys).to all(be_an_instance_of(String))
end
end
end

context 'with symbolized output' do

Check failure on line 342 in spec/facter_db_spec.rb

View workflow job for this annotation

GitHub Actions / rubocop

RSpec/MultipleMemoizedHelpers: Example group has too many memoized helpers [7/6] (https://rspec.rubystyle.guide/#let-blocks, https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/MultipleMemoizedHelpers)
let(:symbolize_keys) { true }

it 'returns strings as keys in factsets' do
result.each do |factset|
expect(factset.keys).to all(be_an_instance_of(Symbol))
end
end
end

context 'with an Array filter' do

Check failure on line 352 in spec/facter_db_spec.rb

View workflow job for this annotation

GitHub Actions / rubocop

RSpec/MultipleMemoizedHelpers: Example group has too many memoized helpers [7/6] (https://rspec.rubystyle.guide/#let-blocks, https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/MultipleMemoizedHelpers)
let(:filter) { [osfamily: 'Debian'] }

Expand Down

0 comments on commit d55cbf4

Please sign in to comment.