features/step_definitions/json_steps.rb in berkshelf-1.4.6 vs features/step_definitions/json_steps.rb in berkshelf-2.0.0.beta

- old
+ new

@@ -1,10 +1,27 @@ -Then /^the output should be JSON$/ do - lambda { parse_json(all_output) }.should_not raise_error +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 { |i| i.sort_by_key(&block) } + end + seed + end + end end Then /^the file "(.*?)" should contain JSON:$/ do |file, data| - target = MultiJson.decode(data) - actual = MultiJson.decode(File.read(File.join(current_dir, file))) + target = JSON.pretty_generate(JSON.parse(data).sort_by_key) + actual = JSON.pretty_generate(JSON.parse(File.read(File.join(current_dir, file))).sort_by_key) - target.should eql(actual) + expect(actual).to eq(target) +end + +Then /^the output should contain JSON:$/ do |data| + target = JSON.pretty_generate(JSON.parse(ERB.new(data).result(binding)).sort_by_key) + actual = JSON.pretty_generate(JSON.parse(all_output).sort_by_key) + + expect(actual).to eq(target) end