File tree Expand file tree Collapse file tree 6 files changed +12
-12
lines changed
lib/puppet/parser/functions Expand file tree Collapse file tree 6 files changed +12
-12
lines changed Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ module Puppet::Parser::Functions
23
23
module_path = function_get_module_path ( [ mod ] )
24
24
metadata_json = File . join ( module_path , 'metadata.json' )
25
25
26
- metadata_exists = File . exists ?( metadata_json ) # rubocop:disable Lint/DeprecatedClassMethods : Changing to .exist? breaks the code
26
+ metadata_exists = File . exist ?( metadata_json )
27
27
if metadata_exists
28
28
metadata = if Puppet ::Util ::Package . versioncmp ( Puppet . version , '8.0.0' ) . negative?
29
29
PSON . load ( File . read ( metadata_json ) )
Original file line number Diff line number Diff line change @@ -55,7 +55,7 @@ module Puppet::Parser::Functions
55
55
else
56
56
JSON . parse ( contents ) || args [ 1 ]
57
57
end
58
- elsif File . exists ?( args [ 0 ] ) # rubocop:disable Lint/DeprecatedClassMethods : Changing to .exist? breaks the code
58
+ elsif File . exist ?( args [ 0 ] )
59
59
content = File . read ( args [ 0 ] )
60
60
if Puppet ::Util ::Package . versioncmp ( Puppet . version , '8.0.0' ) . negative?
61
61
PSON . load ( content ) || args [ 1 ]
Original file line number Diff line number Diff line change @@ -50,7 +50,7 @@ module Puppet::Parser::Functions
50
50
args [ 1 ]
51
51
end
52
52
YAML . safe_load ( contents ) || args [ 1 ]
53
- elsif File . exists ?( args [ 0 ] ) # rubocop:disable Lint/DeprecatedClassMethods : Changing to .exist? breaks the code
53
+ elsif File . exist ?( args [ 0 ] )
54
54
YAML . load_file ( args [ 0 ] ) || args [ 1 ]
55
55
else
56
56
warning ( "Can't load '#{ args [ 0 ] } ' File does not exist!" )
Original file line number Diff line number Diff line change 29
29
30
30
it 'jsons parse the file' do
31
31
allow ( scope ) . to receive ( :function_get_module_path ) . with ( [ 'science' ] ) . and_return ( "#{ prefix } /path/to/module/" )
32
- allow ( File ) . to receive ( :exists ? ) . with ( "#{ prefix } /path/to/module/metadata.json" ) . and_return ( true )
32
+ allow ( File ) . to receive ( :exist ? ) . with ( "#{ prefix } /path/to/module/metadata.json" ) . and_return ( true )
33
33
allow ( File ) . to receive ( :read ) . with ( "#{ prefix } /path/to/module/metadata.json" ) . and_return ( '{"name": "spencer-science"}' )
34
34
35
35
result = subject . execute ( 'science' )
38
38
39
39
it 'fails by default if there is no metadata.json' do
40
40
allow ( scope ) . to receive ( :function_get_module_path ) . with ( [ 'science' ] ) . and_return ( "#{ prefix } /path/to/module/" )
41
- allow ( File ) . to receive ( :exists ? ) . with ( "#{ prefix } /path/to/module/metadata.json" ) . and_return ( false )
41
+ allow ( File ) . to receive ( :exist ? ) . with ( "#{ prefix } /path/to/module/metadata.json" ) . and_return ( false )
42
42
expect { subject . call ( [ 'science' ] ) } . to raise_error ( Puppet ::ParseError )
43
43
end
44
44
45
45
it 'returns nil if user allows empty metadata.json' do
46
46
allow ( scope ) . to receive ( :function_get_module_path ) . with ( [ 'science' ] ) . and_return ( "#{ prefix } /path/to/module/" )
47
- allow ( File ) . to receive ( :exists ? ) . with ( "#{ prefix } /path/to/module/metadata.json" ) . and_return ( false )
47
+ allow ( File ) . to receive ( :exist ? ) . with ( "#{ prefix } /path/to/module/metadata.json" ) . and_return ( false )
48
48
result = subject . execute ( 'science' , true )
49
49
expect ( result ) . to eq ( { } )
50
50
end
Original file line number Diff line number Diff line change 26
26
end
27
27
28
28
before ( :each ) do
29
- allow ( File ) . to receive ( :exists ? ) . with ( filename ) . and_return ( false ) . once
29
+ allow ( File ) . to receive ( :exist ? ) . with ( filename ) . and_return ( false ) . once
30
30
if Puppet ::PUPPETVERSION [ 0 ] . to_i < 8
31
31
allow ( PSON ) . to receive ( :load ) . never # rubocop:disable RSpec/ReceiveNever Switching to not_to receive breaks testing in this case
32
32
else
51
51
let ( :json ) { '{"key":"value", {"ķęŷ":"νậŀųề" }, {"キー":"値" }' }
52
52
53
53
before ( :each ) do
54
- allow ( File ) . to receive ( :exists ? ) . with ( filename ) . and_return ( true ) . once
54
+ allow ( File ) . to receive ( :exist ? ) . with ( filename ) . and_return ( true ) . once
55
55
allow ( File ) . to receive ( :read ) . with ( filename ) . and_return ( json ) . once
56
56
allow ( File ) . to receive ( :read ) . with ( filename ) . and_return ( json ) . once
57
57
if Puppet ::PUPPETVERSION [ 0 ] . to_i < 8
75
75
let ( :json ) { '{"key":"value"}' }
76
76
77
77
before ( :each ) do
78
- allow ( File ) . to receive ( :exists ? ) . with ( filename ) . and_return ( true ) . once
78
+ allow ( File ) . to receive ( :exist ? ) . with ( filename ) . and_return ( true ) . once
79
79
allow ( File ) . to receive ( :read ) . with ( filename ) . and_return ( json ) . once
80
80
if Puppet ::PUPPETVERSION [ 0 ] . to_i < 8
81
81
allow ( PSON ) . to receive ( :load ) . with ( json ) . once . and_raise StandardError , 'Something terrible have happened!'
Original file line number Diff line number Diff line change 10
10
let ( :filename ) { '/tmp/doesnotexist' }
11
11
12
12
it "'default' => 'value'" do
13
- expect ( File ) . to receive ( :exists ? ) . with ( filename ) . and_return ( false ) . once
13
+ expect ( File ) . to receive ( :exist ? ) . with ( filename ) . and_return ( false ) . once
14
14
expect ( YAML ) . not_to receive ( :load_file )
15
15
expect ( subject ) . to run . with_params ( filename , 'default' => 'value' ) . and_return ( 'default' => 'value' )
16
16
end
21
21
let ( :data ) { { 'key' => 'value' , 'ķęŷ' => 'νậŀųề' , 'キー' => '値' } }
22
22
23
23
it "returns 'key' => 'value', 'ķęŷ' => 'νậŀųề', 'キー' => '値'" do
24
- expect ( File ) . to receive ( :exists ? ) . with ( filename ) . and_return ( true ) . once
24
+ expect ( File ) . to receive ( :exist ? ) . with ( filename ) . and_return ( true ) . once
25
25
expect ( YAML ) . to receive ( :load_file ) . with ( filename ) . and_return ( data ) . once
26
26
expect ( subject ) . to run . with_params ( filename ) . and_return ( data )
27
27
end
31
31
let ( :filename ) { '/tmp/doesexist' }
32
32
33
33
it 'filename /tmp/doesexist' do
34
- expect ( File ) . to receive ( :exists ? ) . with ( filename ) . and_return ( true ) . once
34
+ expect ( File ) . to receive ( :exist ? ) . with ( filename ) . and_return ( true ) . once
35
35
allow ( YAML ) . to receive ( :load_file ) . with ( filename ) . once . and_raise ( StandardError , 'Something terrible have happened!' )
36
36
expect ( subject ) . to run . with_params ( filename , 'default' => 'value' ) . and_return ( 'default' => 'value' )
37
37
end
You can’t perform that action at this time.
0 commit comments