diff --git a/Gemfile b/Gemfile index c1221edaa1..efd8a6c791 100644 --- a/Gemfile +++ b/Gemfile @@ -47,6 +47,7 @@ group(:test) do gem "rspec", "~> 3.1", require: false gem "rspec-expectations", ["~> 3.9", "!= 3.9.3"] gem "rspec-its", "~> 1.1", require: false + gem 'rspec-mocks', '< 3.13.3', require: false # breaking change afterwards: https://github.com/rspec/rspec-mocks/pull/1596 gem 'vcr', '~> 5.0', require: false gem 'webmock', '~> 3.0', require: false gem 'webrick', '~> 1.7', require: false if RUBY_VERSION.to_f >= 3.0 diff --git a/lib/puppet/face/facts.rb b/lib/puppet/face/facts.rb index 1c16905ac4..20eda733b4 100644 --- a/lib/puppet/face/facts.rb +++ b/lib/puppet/face/facts.rb @@ -164,7 +164,15 @@ case result when Array, Hash - Puppet::Util::Json.dump(result, :pretty => true) + # JSON < 2.8.0 would pretty print empty arrays and hashes with newlines + # Maintain that behavior for our users for now + if result.is_a?(Array) && result.empty? + "[\n\n]" + elsif result.is_a?(Hash) && result.empty? + "{\n}" + else + Puppet::Util::Json.dump(result, :pretty => true) + end else # one of VALID_TYPES above result end diff --git a/puppet.gemspec b/puppet.gemspec index ed9817807a..9047db7cbe 100644 --- a/puppet.gemspec +++ b/puppet.gemspec @@ -29,6 +29,7 @@ Gem::Specification.new do |spec| spec.add_runtime_dependency(%q, "~> 1.0") spec.add_runtime_dependency(%q, "~> 1.0") spec.add_runtime_dependency(%q, "~> 1.0") + spec.add_runtime_dependency(%q, "< 2.9") # last known good version is 2.8.2 # For building platform specific puppet gems...the --platform flag is only supported in newer Ruby versions platform = spec.platform.to_s diff --git a/spec/unit/application/facts_spec.rb b/spec/unit/application/facts_spec.rb index 24d08c59a2..c3aecd0425 100644 --- a/spec/unit/application/facts_spec.rb +++ b/spec/unit/application/facts_spec.rb @@ -91,6 +91,7 @@ { "type_hash" => [{'a' => 2}, "{\n \"a\": 2\n}"], + "type_empty_hash" => [{}, "{\n}"], "type_array" => [[], "[\n\n]"], "type_string" => ["str", "str"], "type_int" => [1, "1"], diff --git a/spec/unit/provider/package/puppetserver_gem_spec.rb b/spec/unit/provider/package/puppetserver_gem_spec.rb index 170877b8a7..37b32cf1b3 100644 --- a/spec/unit/provider/package/puppetserver_gem_spec.rb +++ b/spec/unit/provider/package/puppetserver_gem_spec.rb @@ -77,7 +77,13 @@ it "raises if given an invalid URI" do resource[:source] = 'h;ttp://rubygems.com' - expect { provider.install }.to raise_error(Puppet::Error, /Invalid source '': bad URI\(is not URI\?\)/) + # Older versions of URI don't have a space before the opening + # parenthesis in the error message, newer versions do + if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('3.0.0') + expect { provider.install }.to raise_error(Puppet::Error, /Invalid source '': bad URI\(is not URI\?\)/) + else + expect { provider.install }.to raise_error(Puppet::Error, /Invalid source '': bad URI \(is not URI\?\)/) + end end end end