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 @@ -22,7 +22,7 @@ module Puppet::Parser::Functions
22
22
module_path = function_get_module_path ( [ mod ] )
23
23
metadata_json = File . join ( module_path , 'metadata.json' )
24
24
25
- metadata_exists = File . exists ?( metadata_json ) # rubocop:disable Lint/DeprecatedClassMethods : Changing to .exist? breaks the code
25
+ metadata_exists = File . exist ?( metadata_json )
26
26
if metadata_exists
27
27
metadata = PSON . load ( File . read ( metadata_json ) )
28
28
else
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
PSON . 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
content = File . read ( args [ 0 ] )
55
55
PSON . load ( content ) || args [ 1 ]
56
56
else
Original file line number Diff line number Diff line change @@ -49,7 +49,7 @@ module Puppet::Parser::Functions
49
49
args [ 1 ]
50
50
end
51
51
YAML . safe_load ( contents ) || args [ 1 ]
52
- elsif File . exists ?( args [ 0 ] ) # rubocop:disable Lint/DeprecatedClassMethods : Changing to .exist? breaks the code
52
+ elsif File . exist ?( args [ 0 ] )
53
53
YAML . load_file ( args [ 0 ] ) || args [ 1 ]
54
54
else
55
55
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
allow ( PSON ) . to receive ( :load ) . never
31
31
end
32
32
it { is_expected . to run . with_params ( filename , 'default' => 'value' ) . and_return ( 'default' => 'value' ) }
46
46
let ( :json ) { '{"key":"value", {"ķęŷ":"νậŀųề" }, {"キー":"値" }' }
47
47
48
48
before ( :each ) do
49
- allow ( File ) . to receive ( :exists ? ) . with ( filename ) . and_return ( true ) . once
49
+ allow ( File ) . to receive ( :exist ? ) . with ( filename ) . and_return ( true ) . once
50
50
allow ( File ) . to receive ( :read ) . with ( filename ) . and_return ( json ) . once
51
51
allow ( File ) . to receive ( :read ) . with ( filename ) . and_return ( json ) . once
52
52
allow ( PSON ) . to receive ( :load ) . with ( json ) . and_return ( data ) . once
65
65
let ( :json ) { '{"key":"value"}' }
66
66
67
67
before ( :each ) do
68
- allow ( File ) . to receive ( :exists ? ) . with ( filename ) . and_return ( true ) . once
68
+ allow ( File ) . to receive ( :exist ? ) . with ( filename ) . and_return ( true ) . once
69
69
allow ( File ) . to receive ( :read ) . with ( filename ) . and_return ( json ) . once
70
70
allow ( PSON ) . to receive ( :load ) . with ( json ) . once . and_raise StandardError , 'Something terrible have happened!'
71
71
end
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 ) . to receive ( :load_file ) . never
15
15
is_expected . 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
is_expected . 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
is_expected . 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