spec/support/chef_server.rb in berkshelf-2.0.18 vs spec/support/chef_server.rb in berkshelf-3.0.0.beta1
- old
+ new
@@ -1,45 +1,54 @@
require 'chef_zero/server'
+require 'json'
module Berkshelf::RSpec
module ChefServer
- PORT = 8889
+ PORT = 4000
class << self
+ attr_reader :server
+
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, generate_real_keys: false)
- end
-
def server_url
- (@server && @server.url) || "http://localhost:#{PORT}"
+ @server && @server.url
end
- def start
- server.start_background
- server.on_response do |request, response|
+ def start(options = {})
+ return @server if @server
+
+ options = options.reverse_merge(port: PORT)
+ options[:generate_real_keys] = false
+
+ @server = ChefZero::Server.new(options)
+ @server.start_background
+ @server.on_response do |request, response|
request_log << [ request, response ]
end
clear_request_log
- server
+ @server
end
def stop
@server.stop if running?
end
def running?
@server && @server.running?
end
+
+ def reset!
+ @server && @server.clear_data
+ end
end
def chef_server
ChefServer.server
end
@@ -65,9 +74,9 @@
end
private
def load_data(key, name, hash)
- ChefServer.server.load_data({ key.to_s => { name => MultiJson.encode(hash) }})
+ ChefServer.server.load_data({ key.to_s => { name => JSON.generate(hash) }})
end
end
end