module RSpecCommand::ClassMethods

def command(cmd=nil, options={}, &block)

Options Hash: (**options)
  • allow_error (Boolean) -- If true, don't raise an error on

Parameters:
  • block (Proc) -- Optional block to return a command to run.
  • options (Hash) -- Options to pass to
  • cmd (String, Array) -- Command to run. If passed as an array, no shell

Other tags:
    See: #command -
def command(cmd=nil, options={}, &block)
  metadata[:command] = true
  subject do |example|
    # If a block is given, use it to get the command.
    cmd = instance_eval(&block) if block
    command(cmd, options)
  end
end

def environment(variables)

Parameters:
  • variables (Hash) -- Key/value pairs to set.
def environment(variables)
  before do
    variables.each do |key, value|
      if value.nil?
        _environment.delete(key.to_s)
      else
        _environment[key.to_s] = value.to_s
      end
    end
  end
end

def file(path, content=nil, &block)

Parameters:
  • block (Proc) -- Optional block to return file data to write.
  • content (String) -- File data to write.
  • path (String) -- Path within the temporary directory to write to.
def file(path, content=nil, &block)
  raise "file path should be relative the the temporary directory." if path == File.expand_path(path)
  before do
    content = instance_eval(&block) if block
    dest_path = File.join(temp_path, path)
    FileUtils.mkdir_p(File.dirname(dest_path))
    IO.write(dest_path, content)
  end
end

def fixture_file(path, dest=nil)

Parameters:
  • dest (String) -- Optional destination path. By default the destination
  • path (String) -- Path of the fixture to copy.
def fixture_file(path, dest=nil)
  raise "file path should be relative the the temporary directory." if path == File.expand_path(path)
  before do |example|
    fixture_path = find_fixture(example.file_path, path)
    dest_path = dest ? File.join(temp_path, dest) : temp_path
    FileUtils.mkdir_p(dest_path)
    file_list = MatchFixture::FileList.new(fixture_path)
    file_list.files.each do |file|
      abs = file_list.absolute(file)
      if File.directory?(abs)
        FileUtils.mkdir_p(File.join(dest_path, file))
      else
        FileUtils.copy(abs , File.join(dest_path, file), preserve: true)
      end
    end
  end
end

def included(klass)

def included(klass)
  super
  klass.extend ClassMethods
end