diff --git a/lib/server_settings/host_collection.rb b/lib/server_settings/host_collection.rb index 3c46fae..a2174eb 100644 --- a/lib/server_settings/host_collection.rb +++ b/lib/server_settings/host_collection.rb @@ -4,6 +4,8 @@ class HostCollection < Array attr_reader :properties def initialize(hosts, properties) @properties = properties + return if hosts.nil? + unless hosts.kind_of?(Array) raise InvalidHosts, "hosts: #{hosts} is not array" end diff --git a/spec/lib/servers_config_spec.rb b/spec/lib/servers_config_spec.rb index 8192c57..580c27e 100644 --- a/spec/lib/servers_config_spec.rb +++ b/spec/lib/servers_config_spec.rb @@ -12,6 +12,10 @@ role2: hosts: - 3.3.3.3 + +role3: + hosts: + EOF } @@ -127,6 +131,7 @@ it 'can iterate each server' do ServerSettings.load_from_yaml(config1) expect { |b| ServerSettings.each_role(&b) }.to yield_successive_args([String, Array], + [String, Array], [String, Array]) end end