Skip to content

Commit eb0466d

Browse files
committed
Use YAML.to_json instead of YAML.dump
We're not using any features of YAML outside of dictionaries and lists (hashes and arrays), so why not let our data be parseable by YAML _and_ JSON?
1 parent f9d7532 commit eb0466d

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

lib/metric_fu/reporting/result.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Result
2020
# A YAML object containing the results of the result generation
2121
# process
2222
def as_yaml
23-
result_hash.to_yaml
23+
YAML.to_json(result_hash)
2424
end
2525

2626
def per_file_data

spec/metric_fu/formatter/yaml_spec.rb

+12-2
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,18 @@
5656
out = MetricFu::Utility.capture_output {
5757
MetricFu::Formatter::YAML.new(output: @output).finish
5858
}
59-
expect(out).to include ":#{@metric1}:"
60-
expect(out).to include ":#{@metric2}:"
59+
expected_output = YAML.to_json({
60+
"#{@metric1}" => {
61+
"total_violations" => 0,
62+
"violations" => {},
63+
},
64+
"#{@metric2}" => {
65+
"files" => [],
66+
"classes" => [],
67+
"methods" => [],
68+
}
69+
})
70+
expect(out).to eq(expected_output)
6171
end
6272

6373
end

spec/metric_fu/reporting/result_spec.rb

+6-8
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,15 @@
1818

1919
describe "#as_yaml" do
2020
it "should call #result_hash" do
21-
result_hash = double('result_hash')
22-
expect(result_hash).to receive(:to_yaml)
23-
24-
expect(@result).to receive(:result_hash).and_return(result_hash)
25-
@result.as_yaml
21+
result_hash = {'hi' => 'there'}
22+
@result.result_hash.update(result_hash)
23+
yaml = @result.as_yaml
24+
expected_yaml = '{"hi": "there"}' << "\n"
25+
expect(yaml).to eq(expected_yaml)
26+
expect(JSON.load(yaml)).to eq(result_hash)
2627
end
2728
end
2829

29-
describe "#result_hash" do
30-
end
31-
3230
describe "#add" do
3331
it "should add a passed hash to the result_hash instance variable" do
3432
result_type = double('result_type')

0 commit comments

Comments
 (0)