module Brightbox
  module Config
    module Cache
      def cache_path
        if @cache_path
          @cache_path
        else
          @cache_path = File.join(config_directory, 'cache')
          unless File.exist? @cache_path
            begin
              FileUtils.mkpath @cache_path
            rescue Errno::EEXIST
            end
          end
          @cache_path
        end
      end

      def cache_id(cid)
        FileUtils.touch(File.join(cache_path, cid)) unless cid.nil?
      end
    end
  end
end

module Brightbox
  module Config
    module Cache
      def cache_path
        File.join(config_directory, "cache")
      end

      def cache_id(cid)
        return if cid.nil?
        unless File.exist?(cache_path)
          begin
            FileUtils.mkpath(cache_path)
          rescue Errno::EEXIST
          end
        end
        FileUtils.touch(File.join(cache_path, cid)) unless cid.nil?
      end
    end
  end
end

Fix caching attempts when directory missing
Fix caching attempts when directory missing

Running specs in a random order could trigger a number of failures
related to naughty API classes attempting to cache IDs whilst the
directory used did not exist.

This alters the `#cache_path` method to be read only without side effect
and creates it when  `#cache_id` is called and it does not exist.
