Sha256: 248f6f21205f2a541203e4b98b65cb8d19cc7eec5269397c04904dfde6124dfc

Contents?: true

Size: 1.62 KB

Versions: 6

Compression:

Stored size: 1.62 KB

Contents

require 'chef_zero/server'
require_relative 'spec_helpers'

module Ridley::RSpec
  module ChefServer
    PORT = 8889

    class << self
      include Ridley::SpecHelpers

      def clear_request_log
        @request_log = Array.new
      end

      def request_log
        @request_log ||= Array.new
      end

      def server
        @server ||= ChefZero::Server.new(port: PORT, signals: false, log_requests: true)
      end

      def server_url
        "http://localhost:#{PORT}"
      end

      def start
        Thin::Logging.silent = true
        server.start_background
        server.on_response do |request, response|
          request_log << [ request, response ]
        end
        clear_request_log

        server
      end

      def stop
        @server.stop if @server
      end

      def running?
        @server && @server.running?
      end
    end

    def chef_client(name, hash = Hash.new)
      load_data(:clients, name, hash)
    end

    def chef_cookbook(name, version, cookbook = Hash.new)
      ChefServer.server.load_data("cookbooks" => { "#{name}-#{version}" => cookbook })
    end

    def chef_data_bag(name, hash = Hash.new)
      ChefServer.server.load_data({ 'data' => { name => hash }})
    end

    def chef_environment(name, hash = Hash.new)
      load_data(:environments, name, hash)
    end

    def chef_node(name, hash = Hash.new)
      load_data(:nodes, name, hash)
    end

    def chef_role(name, hash = Hash.new)
      load_data(:roles, name, hash)
    end

    private

      def load_data(key, name, hash)
        ChefServer.server.load_data(key.to_s => { name => MultiJson.encode(hash) })
      end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ridley-0.12.2 spec/support/chef_server.rb
ridley-0.12.1 spec/support/chef_server.rb
ridley-0.12.0 spec/support/chef_server.rb
ridley-0.11.2 spec/support/chef_server.rb
ridley-0.12.0.rc1 spec/support/chef_server.rb
ridley-0.11.1 spec/support/chef_server.rb