module CLIntegracon::Adapter::Bacon

Define concrete adapter

Public Instance Methods

describe_cli(subject_name, context_options = {}, &block) click to toggle source

Describe a command line interface This method basically behaves like {Bacon::Context.describe}, but it provides automatically the methods subject, file_tree_spec_context, cli_spec and file_spec.

@param [String] subject_name

the subject name will be used as first argument to initialize
a new {CLIntegracon::Subject}, which will be accessible in the
spec by #subject.

@param [Hash<Symbol,String>] context_options

the options to configure this spec context, could be one or more of:
* :executable: the executable used to initialize {CLIntegracon::Subject}
  if not given, will fallback to param {subject_name}.

@param [Block<() -> ()>] block

the block to provide further sub-specs or requirements, as
known from {Bacon::Context.describe}
# File lib/CLIntegracon/adapter/bacon.rb, line 182
def describe_cli(subject_name, context_options = {}, &block)
  context = describe subject_name do
    # Make Context methods available
    # WORKAROUND: Bacon auto-inherits singleton methods to child contexts
    # by using the runtime and won't include methods in modules included
    # by the parent context. We have to ensure that the methods will be
    # accessible by the child contexts by defining them as singleton methods.
    extended = self.extend Context
    Context.instance_methods.each do |method|
      class << self; self end.instance_eval do
        unbound_method = extended.method(method).unbind

        send :define_method, method do |*args, &b|
          unbound_method.bind(self).call(*args, &b)
        end
      end
    end

    subject do |s|
      s.name       = subject_name
      s.executable = context_options[:executable] || subject_name
    end

    instance_eval &block
  end

  Bacon::ErrorLog.gsub! %r{^.*lib/CLIntegracon/.*\n}, ''

  context
end