Sha256: 0d6697421b3792cf04be929c118a78900793b140f3b9d80fa4977889e9426789

Contents?: true

Size: 610 Bytes

Versions: 10

Compression:

Stored size: 610 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|
  target = JSON.pretty_generate(JSON.parse(data).sort_by_key)
  actual = JSON.pretty_generate(JSON.parse(all_output).sort_by_key)

  expect(actual).to eq(target)
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
berkshelf-3.0.1 features/step_definitions/json_steps.rb
berkshelf-3.0.0 features/step_definitions/json_steps.rb
berkshelf-3.0.0.rc1 features/step_definitions/json_steps.rb
berkshelf-3.0.0.beta9 features/step_definitions/json_steps.rb
berkshelf-3.0.0.beta8 features/step_definitions/json_steps.rb
berkshelf-3.0.0.beta7 features/step_definitions/json_steps.rb
berkshelf-3.0.0.beta6 features/step_definitions/json_steps.rb
berkshelf-3.0.0.beta5 features/step_definitions/json_steps.rb
berkshelf-3.0.0.beta4 features/step_definitions/json_steps.rb
berkshelf-3.0.0.beta3 features/step_definitions/json_steps.rb