summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/chef_zero/rspec.rb13
-rw-r--r--lib/chef_zero/server.rb3
2 files changed, 14 insertions, 2 deletions
diff --git a/lib/chef_zero/rspec.rb b/lib/chef_zero/rspec.rb
index bb883f0..f6fca10 100644
--- a/lib/chef_zero/rspec.rb
+++ b/lib/chef_zero/rspec.rb
@@ -26,9 +26,20 @@ module ChefZero
def when_the_chef_server(description, *tags, &block)
context "When the Chef server #{description}", *tags do
before :each do
+
unless ChefZero::RSpec.server
+ default_opts = {:port => 8889, :signals => false, :log_requests => true}
+ server_opts = if self.respond_to?(:chef_zero_opts)
+ default_opts.merge(chef_zero_opts)
+ else
+ default_opts
+ end
+
+ # TODO: can this be logged easily?
+ # pp :zero_opts => server_opts
+
# Set up configuration so that clients will point to the server
- ChefZero::RSpec.server = ChefZero::Server.new(:port => 8889, :signals => false, :log_requests => true)
+ ChefZero::RSpec.server = ChefZero::Server.new(server_opts)
ChefZero::RSpec.client_key = Tempfile.new(['chef_zero_client_key', '.pem'])
ChefZero::RSpec.client_key.write(ChefZero::PRIVATE_KEY)
ChefZero::RSpec.client_key.close
diff --git a/lib/chef_zero/server.rb b/lib/chef_zero/server.rb
index 6c690c7..b5c4bbf 100644
--- a/lib/chef_zero/server.rb
+++ b/lib/chef_zero/server.rb
@@ -69,7 +69,8 @@ module ChefZero
def initialize(options = {})
options = DEFAULT_OPTIONS.merge(options)
@options = options
- @url = "http://#{options[:host]}:#{options[:port]}"
+ uri_safe_host = options[:host].include?(":") ? "[#{options[:host]}]" : options[:host]
+ @url = "http://#{uri_safe_host}:#{options[:port]}"
@generate_real_keys = options[:generate_real_keys]
ChefZero::Log.level = options[:log_level].to_sym