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