Module: CLIntegracon::Adapter::Bacon

Included in:
Bacon::Context
Defined in:
lib/CLIntegracon/adapter/bacon.rb

Overview

Define concrete adapter

Defined Under Namespace

Modules: Context

Instance Method Summary collapse

Instance Method Details

#describe_cli(subject_name, context_options = {}, &block) ⇒ Object

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.

Parameters:

  • subject_name (String)

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

  • context_options (Hash<Symbol,String>) (defaults to: {})

    the options to configure this spec context, could be one or more of:

    • :executable: the executable used to initialize Subject if not given, will fallback to param subject_name.

  • ] (Block<() -> ())

    block the block to provide further sub-specs or requirements, as known from Bacon::Context.describe


182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# 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