Skip to content

Commit 4d13aea

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 3c9d982 commit 4d13aea

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
@@ -18,7 +18,7 @@ class Result
1818
# A YAML object containing the results of the result generation
1919
# process
2020
def as_yaml
21-
result_hash.to_yaml
21+
YAML.to_json(result_hash)
2222
end
2323

2424
def per_file_data

spec/metric_fu/formatter/yaml_spec.rb

+12-2
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,18 @@
5050
out = MetricFu::Utility.capture_output {
5151
MetricFu::Formatter::YAML.new(output: @output).finish
5252
}
53-
expect(out).to include ":#{@metric1}:"
54-
expect(out).to include ":#{@metric2}:"
53+
expected_output = YAML.to_json(
54+
"#{@metric1}" => {
55+
"total_violations" => 0,
56+
"violations" => {},
57+
},
58+
"#{@metric2}" => {
59+
"files" => [],
60+
"classes" => [],
61+
"methods" => [],
62+
}
63+
)
64+
expect(out).to eq(expected_output)
5565
end
5666
end
5767

spec/metric_fu/reporting/result_spec.rb

+6-8
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,15 @@
1616

1717
describe "#as_yaml" do
1818
it "should call #result_hash" do
19-
result_hash = double("result_hash")
20-
expect(result_hash).to receive(:to_yaml)
21-
22-
expect(@result).to receive(:result_hash).and_return(result_hash)
23-
@result.as_yaml
19+
result_hash = { "hi" => "there" }
20+
@result.result_hash.update(result_hash)
21+
yaml = @result.as_yaml
22+
expected_yaml = '{"hi": "there"}' << "\n"
23+
expect(yaml).to eq(expected_yaml)
24+
expect(JSON.load(yaml)).to eq(result_hash)
2425
end
2526
end
2627

27-
describe "#result_hash" do
28-
end
29-
3028
describe "#add" do
3129
it "should add a passed hash to the result_hash instance variable" do
3230
result_type = double("result_type")

0 commit comments

Comments
 (0)