Sha256: f78f9ceffafb396657c567bcb2be08b65d784beb704391ad5bf5caafc53933f2

Contents?: true

Size: 1.72 KB

Versions: 122

Compression:

Stored size: 1.72 KB

Contents

require 'rspec/mocks'

module MockNet
  class HTTP

    class Response
      class ResponseHash
        def []key
          if key == "domain"
            nil
          else
            { 'ok' => true, 'hostname' => 'pool' }
          end
        end

      end

      def body
        ResponseHash.new
      end

    end

    class Post
      def initialize uri
        @uri = uri
      end

      def body= *args
        hash
      end
    end

    class Put
      def initialize uri
        @uri = uri
      end

      def body= *args
        hash
      end
    end

    class Delete
      def initialize uri
        @uri = uri
      end
    end

    def initialize host, port
      @host = host
      @port = port
    end

    def request req
      Response.new
    end
  end

end

module FakeHost
  include RSpec::Mocks::TestDouble

  def self.create(name = 'fakevm', platform = 'redhat-version-arch', options = {})
    options_hash = Beaker::Options::OptionsHash.new.merge(options)
    options_hash[:logger] = RSpec::Mocks::Double.new('logger').as_null_object
    host = Beaker::Host.create(name, { 'platform' => Beaker::Platform.new(platform) } , options_hash)
    host.extend(MockedExec)
    host
  end

  module MockedExec

    def self.extended(other)
      other.instance_eval do
        send(:instance_variable_set, :@commands, [])
      end
    end

    attr_accessor :commands

    def port_open?(port)
      true
    end

    def any_exec_result
      RSpec::Mocks::Double.new('exec-result').as_null_object
    end

    def exec(command, options = {})
      commands << command
      any_exec_result
    end

    def command_strings
      commands.map { |c| [c.command, c.args].join(' ') }
    end
  end

  def log_prefix
    "FakeHost"
  end
end

Version data entries

122 entries across 122 versions & 1 rubygems

Version Path
beaker-4.38.1 spec/mocks.rb
beaker-4.38.0 spec/mocks.rb
beaker-4.37.2 spec/mocks.rb
beaker-4.37.1 spec/mocks.rb
beaker-4.37.0 spec/mocks.rb
beaker-4.36.1 spec/mocks.rb
beaker-4.36.0 spec/mocks.rb
beaker-4.35.0 spec/mocks.rb
beaker-4.34.0 spec/mocks.rb
beaker-4.33.0 spec/mocks.rb
beaker-4.32.0 spec/mocks.rb
beaker-4.31.0 spec/mocks.rb
beaker-4.30.0 spec/mocks.rb
beaker-4.29.1 spec/mocks.rb
beaker-4.29.0 spec/mocks.rb
beaker-4.28.1 spec/mocks.rb
beaker-4.28.0 spec/mocks.rb
beaker-4.27.1 spec/mocks.rb
beaker-4.27.0 spec/mocks.rb
beaker-4.26.0 spec/mocks.rb