module CLIntegracon::Adapter::Bacon::Context

Public Instance Methods

behaves_like_a(name, *args) click to toggle source

Works like `behaves_like`, but takes arguments for the shared example

@param [String] name

name of the shared context.

@param […] args

params to pass to the shared context
# File lib/CLIntegracon/adapter/bacon.rb, line 57
def behaves_like_a(name, *args)
  instance_exec(*args, &Bacon::Shared[name])
end
cli_spec(spec_dir, head_args=nil, tail_args=nil, based_on: nil) click to toggle source

Ad-hoc defines a set of shared expectations to be consumed directly by `behaves_like`. See the following example for usage:

behaves_like cli_spec('my_spec_dir', 'install --verbose')

@note This expects that a method `file_tree_spec_context` is defined, which is

returning an instance of {FileTreeSpecContext}.

@param [String] spec_dir

the concrete directory of the spec, see {file_spec}.

@param [String] head_args

the arguments to pass before the +default_args+ on launch to {CLIntegracon::Subject}.

@param [String] tail_args

the arguments to pass after the +default_args+ on launch to {CLIntegracon::Subject}.

@param [String] based_on

Allows to specify an optional base spec, whose after directory will be used
as before directory. You have to ensure that the specs are defined in order,
so that the base spec was executed before.

@return [String]

name of the set of shared expectations
# File lib/CLIntegracon/adapter/bacon.rb, line 86
def cli_spec(spec_dir, head_args=nil, tail_args=nil, based_on: nil)
  file_spec(spec_dir, based_on: based_on) do
    output, status = subject.launch(head_args, tail_args)

    args = [head_args, tail_args].compact
    it "$ #{subject.name} #{args.join(' ')}" do
      status.should.satisfy("Binary failed\n\n#{output}") do
        status.success?
      end
    end
    status.success?
  end
end
file_spec(spec_dir, based_on: nil, &block) click to toggle source

Ad-hoc defines a set of shared expectations to be consumed directly by `behaves_like`. See the following example for usage:

behaves_like file_spec('my_spec_dir') do
  # do some changes to the current dir
end

@note This expects that a method `file_tree_spec_context` is defined, which is

returning an instance of {FileTreeSpecContext}.

@param [String] spec_dir

the concrete directory of the spec to be passed to
{FileTreeSpecContext.spec}

@param [String] based_on

Allows to specify an optional base spec, whose after directory will be used
as before directory.

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

the block which will be executed after the before state is laid out in the
temporary directory, which normally will make modifications to file system,
which will be compare to the state given in the after directory.

@return [String]

name of the set of shared expectations
# File lib/CLIntegracon/adapter/bacon.rb, line 126
def file_spec(spec_dir, based_on: nil, &block)
  raise ArgumentError.new("Spec directory is missing!") if spec_dir.nil?

  shared_name = spec_dir

  shared shared_name do
    file_tree_spec_context.spec(spec_dir, based_on: based_on).run do |spec|
      break unless instance_eval &block

      formatter = spec.formatter.lazy

      spec.compare do |diff|
        it diff.relative_path.to_s do
          diff.produced.should.satisfy(formatter.describe_missing_file(diff.relative_path)) do
            diff.produced.exist?
          end

          diff.produced.should.satisfy(formatter.describe_file_diff(diff)) do
            diff.is_equal?
          end
        end
      end

      spec.check_unexpected_files do |files|
        it "should not produce unexpected files" do
          files.should.satisfy(formatter.describe_unexpected_files(files)) do
            files.size == 0
          end
        end
      end
    end
  end

  shared_name
end
file_tree_spec_context(&block) click to toggle source

Get or configure the current context for FileTreeSpecs

@note On first call this will create a new context on base of the

shared configuration and store it in the ivar `@file_tree_spec_context`.

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

This block, if given, will be evaluated on the caller.
It receives as first argument the context itself.

@return [FileTreeSpecContext]

the spec context, will be lazily created if not already present.
# File lib/CLIntegracon/adapter/bacon.rb, line 43
def file_tree_spec_context &block
  @file_tree_spec_context ||= CLIntegracon.shared_config.file_tree_spec_context.dup
  return @file_tree_spec_context if block.nil?
  instance_exec(@file_tree_spec_context, &block)
end
subject(&block) click to toggle source

Get or configure the current subject

@note On first call this will create a new subject on base of the

shared configuration and store it in the ivar `@subject`.

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

This block, if given, will be evaluated on the caller.
It receives as first argument the subject itself.

@return [Subject]

the subject
# File lib/CLIntegracon/adapter/bacon.rb, line 25
def subject &block
  @subject ||= CLIntegracon::shared_config.subject.dup
  return @subject if block.nil?
  instance_exec(@subject, &block)
end