Class: Cog::SpecHelpers::Invocation

Inherits:
Object
  • Object
show all
Defined in:
lib/cog/spec_helpers/runner.rb

Overview

Represents a cog command line invocation, which can be tested with RSpec should and should_not custom Matchers. This is the kind of object returned by Runner#run.

Instance Method Summary collapse

Constructor Details

#initialize(cmd, opt = {}) ⇒ Invocation

Returns a new instance of Invocation.

Parameters:

  • cmd (Array<String>)
  • opt (Hash) (defaults to: {})

    a customizable set of options

Options Hash (opt):

  • :use_bundler (Boolean) — default: false


39
40
41
42
# File 'lib/cog/spec_helpers/runner.rb', line 39

def initialize(cmd, opt={})
  @cmd = cmd
  @use_bundler = opt[:use_bundler]
end

Instance Method Details

#exec {|stdin, stdout, stderr| ... } ⇒ nil

Execute the command

Yields:

  • (stdin, stdout, stderr)

    standard pipes for the invocation

Returns:

  • (nil)


48
49
50
51
52
53
54
55
# File 'lib/cog/spec_helpers/runner.rb', line 48

def exec(&block)
  full_cmd = @cmd
  full_cmd = ['bundle', 'exec'] + full_cmd if @use_bundler
  ENV['HOME'] = SpecHelpers.active_home_fixture_dir
  Open3.popen3 *full_cmd do |i,o,e,t|
    block.call i,o,e
  end
end

#to_sString

Returns loggable representation.

Returns:

  • (String)

    loggable representation



59
60
61
# File 'lib/cog/spec_helpers/runner.rb', line 59

def to_s
  "`#{@cmd.compact.join ' '}`"
end