Sha256: 2bb6ed3b2ddb80b8dae0186888c393af8dd3cdad4690ae1a3acc5af27e0d750d

Contents?: true

Size: 1.57 KB

Versions: 1

Compression:

Stored size: 1.57 KB

Contents

require 'pathname'

module CLIntegracon

  class << self

    # @return [Configuration]
    #         Get the shared configuration, set by {self.configure}.
    attr_accessor :shared_config

    # Set a new shared configuration
    #
    # @param  [Block<() -> ()>] block
    #         the block which is evaluated on the new shared configuration
    #
    def configure(&block)
      self.shared_config ||= Configuration.new
      shared_config.instance_eval &block
    end

  end

  class Configuration

    # Get the subject to configure it
    #
    # @return [Subject]
    #
    def subject
      @subject ||= Subject.new()
    end

    # Get the context to configure it
    #
    # @return [FileTreeSpecContext]
    #
    def context
      @context ||= FileTreeSpecContext.new()
    end

    # Hook this gem in a test framework by a supported adapter
    #
    # @param  [Symbol] test_framework
    #         the test framework
    #
    def hook_into test_framework
      adapter = self.class.adapters[test_framework]
      raise ArgumentError.new "No adapter for test framework #{test_framework}" if adapter.nil?
      require adapter
    end

    private

    # Get the file paths of supported adapter implementations by test framework
    #
    # @return [Hash<Symbol, String>]
    #         test framework to adapter implementation files
    #
    def self.adapters
      adapter_dir = Pathname('../adapter').expand_path(__FILE__)
      @adapters ||= Dir.chdir(adapter_dir) do
        Hash[Dir['*.rb'].map { |path| [path.gsub(/\.rb$/, '').to_sym, adapter_dir + path] }]
      end
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
clintegracon-0.4.1 lib/CLIntegracon/configuration.rb