Sha256: cde01a2d1281b791d5fb1cecf3a23f07e74a2ada5fbbdbe9af22a5b59ea5d548

Contents?: true

Size: 1.1 KB

Versions: 3

Compression:

Stored size: 1.1 KB

Contents

require 'coverage_helper'
require 'minitest/autorun'
require 'turn'
require 'yaml'
require 'datacenter'
require 'pry-nav'

Turn.config do |c|
  c.format = :pretty
  c.natural = true
  c.ansi = true
end

class Module
  include Minitest::Spec::DSL
end

module Datacenter
  module Shell
    class Mock

      def initialize(file=nil)
        @commands = file ? YAML.load_file(file) : {}
      end

      def stub(command, value=nil, &block)
        commands[command] = value || block.call
      end

      def run(command)
        raise "Undefined command: #{command}" unless commands.key? command
        commands[command]
      end

      private

      attr_reader :commands

    end

    class Kill
      def initialize(pid)
        @pid = pid
      end

      def run(command)
        if command == "kill -s 0 #{@pid}"
          ''
        elsif command == "kill -s KILL #{@pid}"
          @pid = nil
          ''
        else
          'kill: No such process'
        end
      end
    end
  end
end

class Minitest::Spec
  let(:mock_shell) { Datacenter::Shell::Mock.new File.expand_path('../commands.yml', __FILE__) }
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
datacenter-0.1.2 spec/minitest_helper.rb
datacenter-0.1.1 spec/minitest_helper.rb
datacenter-0.1.0 spec/minitest_helper.rb