From 42cffeea6182f0dc14bd6b8e6b54653fbd19dddb Mon Sep 17 00:00:00 2001 From: Makoto Nozaki Date: Thu, 15 Dec 2016 08:00:56 -0500 Subject: [PATCH] Fix variable name. Add test. Signed-off-by: Makoto Nozaki --- lib/resources/json.rb | 4 ++-- test/helper.rb | 1 + test/unit/resources/json_test.rb | 7 +++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/resources/json.rb b/lib/resources/json.rb index 62cf7432d..43f598343 100644 --- a/lib/resources/json.rb +++ b/lib/resources/json.rb @@ -44,13 +44,13 @@ module Inspec::Resources # check if file is available if !@file.file? - skip_resource "Can't find file \"#{@conf_path}\"" + skip_resource "Can't find file \"#{@path}\"" return @params = {} end # check if file is readable if @file_content.empty? && @file.size > 0 - skip_resource "Can't read file \"#{@conf_path}\"" + skip_resource "Can't read file \"#{@path}\"" return @params = {} end end diff --git a/test/helper.rb b/test/helper.rb index 91732ddf2..a7f79dbfa 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -114,6 +114,7 @@ class MockLoader 'kitchen.yml' => mockfile.call('kitchen.yml'), 'example.csv' => mockfile.call('example.csv'), 'policyfile.lock.json' => mockfile.call('policyfile.lock.json'), + 'nonexistent.json' => mockfile.call('nonexistent.json'), '/sys/class/net/br0/bridge' => mockdir.call(true), 'rootwrap.conf' => mockfile.call('rootwrap.conf'), '/etc/apache2/apache2.conf' => mockfile.call('apache2.conf'), diff --git a/test/unit/resources/json_test.rb b/test/unit/resources/json_test.rb index d65e12e64..72c2c5270 100644 --- a/test/unit/resources/json_test.rb +++ b/test/unit/resources/json_test.rb @@ -33,4 +33,11 @@ describe 'Inspec::Resources::JSON' do _(resource.send(:'x.y.z')).must_be_nil end end + describe 'when loading a nonexistent file' do + let (:resource) { load_resource('json', 'nonexistent.json') } + + it 'produces an error' do + _(resource.resource_skipped).must_equal 'Can\'t find file "nonexistent.json"' + end + end end