module GitReflow::RSpec::CommandLineHelpers

@nodoc

Public Instance Methods

reset_stubbed_command_line() click to toggle source
# File lib/git_reflow/rspec/command_line_helpers.rb, line 50
def reset_stubbed_command_line
  $commands_ran = []
  $stubbed_commands = {}
  $output = []
  $says = []
end
stub_command(command:, return_value: "", options: {}) click to toggle source
# File lib/git_reflow/rspec/command_line_helpers.rb, line 57
def stub_command(command:, return_value: "", options: {})
  $stubbed_commands[command] = return_value
  $stubbed_runners.each do |runner|
    allow(runner).to receive(:run).with(command, options) do |command, options|
      options = { loud: true, blocking: true }.merge(options || {})
      $commands_ran << Hashie::Mash.new(command: command, options: options)
      $stubbed_commands[command] = return_value
      raise GitReflow::Sandbox::CommandError.new(return_value, "\"#{command}\" failed to run.") if options[:raise]
    end
  end
end
stub_command_line() click to toggle source
# File lib/git_reflow/rspec/command_line_helpers.rb, line 7
def stub_command_line
  $commands_ran     = []
  $stubbed_commands = {}
  $stubbed_runners  = Set.new
  $output           = []
  $says             = []

  stub_run_for GitReflow
  stub_run_for GitReflow::Sandbox
  stub_run_for GitReflow::Workflow
  stub_run_for GitReflow::Workflows::Core if defined? GitReflow::Workflows

  stub_output_for(GitReflow)
  stub_output_for(GitReflow::Sandbox)
  stub_output_for(GitReflow::Workflow)

  allow_any_instance_of(GitReflow::GitServer::PullRequest).to receive(:printf) do |format, *output|
    $output << Array(output).join(" ")
    output = ''
  end.and_return("")
end
stub_command_line_inputs(inputs) click to toggle source
# File lib/git_reflow/rspec/command_line_helpers.rb, line 77
def stub_command_line_inputs(inputs)
  allow_any_instance_of(HighLine).to receive(:ask) do |terminal, question|
    return_value = inputs[question]
    question = ""
    return_value
  end
end
stub_command_line_inputs_for(module_to_stub, inputs) click to toggle source
# File lib/git_reflow/rspec/command_line_helpers.rb, line 69
def stub_command_line_inputs_for(module_to_stub, inputs)
  allow(module_to_stub).to receive(:ask) do |terminal, question|
    return_value = inputs[question]
    question = ""
    return_value
  end
end
stub_output_for(object_to_stub, method_to_stub = :puts) click to toggle source
# File lib/git_reflow/rspec/command_line_helpers.rb, line 29
def stub_output_for(object_to_stub, method_to_stub = :puts)
  allow_any_instance_of(object_to_stub).to receive(method_to_stub) do |output|
    $output << output
    output = ''
  end
end
stub_run_for(module_to_stub) click to toggle source
# File lib/git_reflow/rspec/command_line_helpers.rb, line 36
def stub_run_for(module_to_stub)
  $stubbed_runners << module_to_stub
  allow(module_to_stub).to receive(:run) do |command, options|
    options = { loud: true, blocking: true }.merge(options || {})
    $commands_ran << Hashie::Mash.new(command: command, options: options)
    ret_value = $stubbed_commands[command] || ""
    command = "" # we need this due to a bug in rspec that will keep this assignment on subsequent runs of the stub
    ret_value
  end
  allow(module_to_stub).to receive(:say) do |output, type|
    $says << {message: output, type: type}
  end
end