Sha256: 14739c9827a06f17ba64bd4d3f6a94b39d36b466295c6c680d4359192ac71b58

Contents?: true

Size: 938 Bytes

Versions: 17

Compression:

Stored size: 938 Bytes

Contents

class Hash
  def sort_by_key(&block)
    keys.sort(&block).reduce({}) do |seed, key|
      seed[key] = self[key]
      if seed[key].is_a?(Hash)
        seed[key] = seed[key].sort_by_key(&block)
      elsif seed[key].is_a?(Array)
        seed[key] = seed[key].map do |i|
          i.respond_to?(:sort_by_key) ? i.sort_by_key(&block) : i
        end
      end
      seed
    end
  end
end

# Pending Ridley allowing newer Faraday and Celluloid.
def clean_json_output(output)
  output.gsub(/^.+warning: constant ::Fixnum is deprecated$/, "") \
        .gsub(/^.*forwarding to private method Celluloid::PoolManager#url_prefix$/, "")
end

Then /^the output should contain JSON:$/ do |data|
  parsed = ERB.new(data).result
  target = JSON.pretty_generate(JSON.parse(parsed).sort_by_key)
  actual = JSON.pretty_generate(JSON.parse(all_commands.map { |c| clean_json_output(c.output) }.join("\n")).sort_by_key)

  expect(actual).to eq(target)
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
berkshelf-7.0.7 features/step_definitions/json_steps.rb
berkshelf-6.3.4 features/step_definitions/json_steps.rb
berkshelf-7.0.6 features/step_definitions/json_steps.rb
berkshelf-7.0.5 features/step_definitions/json_steps.rb
berkshelf-6.3.3 features/step_definitions/json_steps.rb
berkshelf-7.0.4 features/step_definitions/json_steps.rb
berkshelf-7.0.3 features/step_definitions/json_steps.rb
berkshelf-7.0.2 features/step_definitions/json_steps.rb
berkshelf-7.0.1 features/step_definitions/json_steps.rb
berkshelf-7.0.0 features/step_definitions/json_steps.rb
berkshelf-6.3.2 features/step_definitions/json_steps.rb
berkshelf-6.3.1 features/step_definitions/json_steps.rb
berkshelf-6.3.0 features/step_definitions/json_steps.rb
berkshelf-6.2.2 features/step_definitions/json_steps.rb
berkshelf-6.2.1 features/step_definitions/json_steps.rb
berkshelf-6.2.0 features/step_definitions/json_steps.rb
berkshelf-6.1.1 features/step_definitions/json_steps.rb