Sha256: 03fcf83dfc225eb9d82af9ec188dadc4539febf24c6643e46c6b9a844acb2280

Contents?: true

Size: 1.43 KB

Versions: 1

Compression:

Stored size: 1.43 KB

Contents

# frozen_string_literal: true

require 'eac_ruby_utils/core_ext'
require 'eac_ruby_utils/fs_cache'
require 'eac_ruby_utils/listable'
require 'eac_ruby_utils/on_clean_ruby_environment'

module EacRubyUtils
  module Tests
    class Base
      include ::EacRubyUtils::Listable

      enable_simple_cache
      lists.add_string :result, :failed, :nonexistent, :successful

      common_constructor :gem

      def elegible?
        dependency_present? && gem.root.join(test_directory).exist?
      end

      def dependency_present?
        gem.gemfile_path.exist? && gem.gemfile_lock_gem_version(dependency_gem).present?
      end

      def name
        self.class.name.demodulize.gsub(/Test\z/, '')
      end

      def stdout_cache
        root_cache.child('stdout')
      end

      def stderr_cache
        root_cache.child('stderr')
      end

      def to_s
        "#{gem}[#{name}]"
      end

      private

      def result_uncached
        return RESULT_NONEXISTENT unless elegible?
        bundle_run ? RESULT_SUCCESSFUL : RESULT_FAILED
      end

      def bundle_run
        r = ::EacRubyUtils.on_clean_ruby_environment do
          gem.bundle('exec', *bundle_exec_args).execute
        end
        stdout_cache.write(r[:stdout])
        stderr_cache.write(r[:stderr])
        r[:exit_code].zero?
      end

      def root_cache
        ::EacRubyUtils.fs_cache.child(gem.root.to_s.parameterize, self.class.name.parameterize)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
eac_ruby_gems_utils-0.1.0 lib/eac_ruby_gems_utils/tests/base.rb