Sha256: 8cb1e5e7680fc2643e817e82bdbced9fa3a7fe222f2f4e0c36ba9eacd53ade36

Contents?: true

Size: 1.86 KB

Versions: 9

Compression:

Stored size: 1.86 KB

Contents

require 'rubygems'
require 'stringio'
require 'simplecov'
SimpleCov.start do
  add_filter '/spec/'
end

# Unshift so that local files load instead of something in gems
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'

# This basically replicates the behavior of `require 'commander/import'`
# but without adding an `at_exit` hook, which interferes with exit code
require 'commander'
require 'commander/methods'

# Mock terminal IO streams so we can spec against them

def mock_terminal
  @input = StringIO.new
  @output = StringIO.new
  $terminal = HighLine.new @input, @output
end

# Create test command for usage within several specs

def create_test_command
  stub_const('Commander::Patches::ValidateInputs::PatchEnabled', false)
  command :test do |c|
    c.syntax = 'test [options] <file>'
    c.description = 'test description'
    c.example 'description', 'command'
    c.example 'description 2', 'command 2'
    c.option '-v', '--verbose', 'verbose description'
    c.when_called do |args, _options|
      format('test %s', args.join)
    end
  end
  @command = command :test
end

# Create a new command runner

def new_command_runner(*args, &block)
  Commander::Runner.instance_variable_set :"@singleton", Commander::Runner.new(args)
  program :name, 'test'
  program :version, '1.2.3'
  program :description, 'something'
  create_test_command
  yield if block
  Commander::Runner.instance
end

# Comply with how specs were previously written

def command_runner
  Commander::Runner.instance
end

def run(*args)
  new_command_runner(*args) do
    program :help_formatter, Commander::HelpFormatter::Base
    yield if block_given?
  end.run!
  @output.string
end

RSpec.configure do |c|
  c.expect_with(:rspec) do |e|
    e.syntax = :expect
  end

  c.mock_with(:rspec) do |m|
    m.syntax = :expect
  end

  c.before(:each) do
    allow(Commander::UI).to receive(:enable_paging)
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
commander-openflighthpc-2.0.2 spec/spec_helper.rb
commander-openflighthpc-2.0.1 spec/spec_helper.rb
commander-openflighthpc-2.0.0 spec/spec_helper.rb
commander-openflighthpc-1.2.0 spec/spec_helper.rb
commander-openflighthpc-1.1.2 spec/spec_helper.rb
commander-openflighthpc-1.1.1 spec/spec_helper.rb
commander-openflighthpc-1.1.0 spec/spec_helper.rb
commander-openflighthpc-1.0.0 spec/spec_helper.rb
commander-openflighthpc-1.0.0.pre.alpha1 spec/spec_helper.rb