@@ -20,24 +20,33 @@ def run_sidecar(cmd_options)
2020 return stdout . bytes . pack ( 'U*' )
2121 end
2222
23- let ( :default_fact_names ) { [ 'hostname' , 'fixture_agent_custom_fact' ] }
24- let ( :module_fact_names ) { [ 'fixture_module_custom_fact' , 'fixture_module_external_fact' ] }
25- let ( :environment_fact_names ) { [ 'fixture_environment_custom_fact' , 'fixture_environment_external_fact' ] }
23+ RSpec ::Matchers . define :contain_child_with_key do |key |
24+ match do |actual |
25+ !( actual . index { |item | item . key == key } ) . nil?
26+ end
27+
28+ failure_message do |actual |
29+ "expected that #{ actual . class . to_s } would contain a child with key #{ key } "
30+ end
31+ end
32+
33+ let ( :default_fact_names ) { %i[ hostname fixture_agent_custom_fact ] }
34+ let ( :module_fact_names ) { %i[ fixture_module_custom_fact fixture_module_external_fact ] }
35+ let ( :environment_fact_names ) { %i[ fixture_environment_custom_fact fixture_environment_external_fact ] }
2636
2737 describe 'when running facts action' do
2838 let ( :cmd_options ) { [ '--action' , 'facts' ] }
2939
3040 it 'should return a deserializable facts object with all default facts' do
3141 result = run_sidecar ( cmd_options )
32- deserial = PuppetLanguageServer ::Sidecar ::Protocol ::Facts . new
42+ deserial = PuppetLanguageServer ::Sidecar ::Protocol ::FactList . new
3343 expect { deserial . from_json! ( result ) } . to_not raise_error
34-
3544 default_fact_names . each do |name |
36- expect ( deserial ) . to include ( name )
45+ expect ( deserial ) . to contain_child_with_key ( name )
3746 end
3847
3948 module_fact_names . each do |name |
40- expect ( deserial ) . not_to include ( name )
49+ expect ( deserial ) . to_not contain_child_with_key ( name )
4150 end
4251 end
4352 end
@@ -51,15 +60,15 @@ def run_sidecar(cmd_options)
5160
5261 it 'should return a deserializable facts object with default facts and workspace facts' do
5362 result = run_sidecar ( cmd_options )
54- deserial = PuppetLanguageServer ::Sidecar ::Protocol ::Facts . new
63+ deserial = PuppetLanguageServer ::Sidecar ::Protocol ::FactList . new
5564 expect { deserial . from_json! ( result ) } . to_not raise_error
5665
5766 default_fact_names . each do |name |
58- expect ( deserial ) . to include ( name )
67+ expect ( deserial ) . to contain_child_with_key ( name )
5968 end
6069
6170 module_fact_names . each do |name |
62- expect ( deserial ) . to include ( name )
71+ expect ( deserial ) . to contain_child_with_key ( name )
6372 end
6473 end
6574 end
@@ -74,15 +83,15 @@ def run_sidecar(cmd_options)
7483
7584 it 'should return a deserializable facts object with default facts and workspace facts' do
7685 result = run_sidecar ( cmd_options )
77- deserial = PuppetLanguageServer ::Sidecar ::Protocol ::Facts . new
86+ deserial = PuppetLanguageServer ::Sidecar ::Protocol ::FactList . new
7887 expect { deserial . from_json! ( result ) } . to_not raise_error
7988
8089 default_fact_names . each do |name |
81- expect ( deserial ) . to include ( name )
90+ expect ( deserial ) . to contain_child_with_key ( name )
8291 end
8392
8493 environment_fact_names . each do |name |
85- expect ( deserial ) . to include ( name )
94+ expect ( deserial ) . to contain_child_with_key ( name )
8695 end
8796 end
8897 end
0 commit comments