Sha256: d7930a0fae8d7a8fff8752ec49273cba547108d39d5ce0ceccefbc9b364908ba

Contents?: true

Size: 644 Bytes

Versions: 14

Compression:

Stored size: 644 Bytes

Contents

class Hash
  def sort_by_key(&block)
    self.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

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_output).sort_by_key)

  expect(actual).to eq(target)
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
berkshelf-4.0.1 features/step_definitions/json_steps.rb
berkshelf-4.0.0 features/step_definitions/json_steps.rb
berkshelf-3.3.0 features/step_definitions/json_steps.rb
berkshelf-3.2.4 features/step_definitions/json_steps.rb
berkshelf-3.2.3 features/step_definitions/json_steps.rb
berkshelf-3.2.2 features/step_definitions/json_steps.rb
berkshelf-3.2.1 features/step_definitions/json_steps.rb
berkshelf-3.2.0 features/step_definitions/json_steps.rb
berkshelf-3.1.5 features/step_definitions/json_steps.rb
berkshelf-3.1.4 features/step_definitions/json_steps.rb
berkshelf-3.1.3 features/step_definitions/json_steps.rb
berkshelf-3.1.2 features/step_definitions/json_steps.rb
berkshelf-3.1.1 features/step_definitions/json_steps.rb
berkshelf-3.1.0 features/step_definitions/json_steps.rb