Skip to content

Commit

Permalink
Use YAML.to_json instead of YAML.dump
Browse files Browse the repository at this point in the history
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?
  • Loading branch information
bf4 committed Feb 27, 2015
1 parent 3c9d982 commit 4d13aea
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lib/metric_fu/reporting/result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Result
# A YAML object containing the results of the result generation
# process
def as_yaml
result_hash.to_yaml
YAML.to_json(result_hash)
end

def per_file_data
Expand Down
14 changes: 12 additions & 2 deletions spec/metric_fu/formatter/yaml_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,18 @@
out = MetricFu::Utility.capture_output {
MetricFu::Formatter::YAML.new(output: @output).finish
}
expect(out).to include ":#{@metric1}:"
expect(out).to include ":#{@metric2}:"
expected_output = YAML.to_json(
"#{@metric1}" => {
"total_violations" => 0,
"violations" => {},
},
"#{@metric2}" => {
"files" => [],
"classes" => [],
"methods" => [],
}
)
expect(out).to eq(expected_output)
end
end

Expand Down
14 changes: 6 additions & 8 deletions spec/metric_fu/reporting/result_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,15 @@

describe "#as_yaml" do
it "should call #result_hash" do
result_hash = double("result_hash")
expect(result_hash).to receive(:to_yaml)

expect(@result).to receive(:result_hash).and_return(result_hash)
@result.as_yaml
result_hash = { "hi" => "there" }
@result.result_hash.update(result_hash)
yaml = @result.as_yaml
expected_yaml = '{"hi": "there"}' << "\n"
expect(yaml).to eq(expected_yaml)
expect(JSON.load(yaml)).to eq(result_hash)
end
end

describe "#result_hash" do
end

describe "#add" do
it "should add a passed hash to the result_hash instance variable" do
result_type = double("result_type")
Expand Down

0 comments on commit 4d13aea

Please sign in to comment.