Skip to content

Commit

Permalink
Minor fixups in test code
Browse files Browse the repository at this point in the history
  • Loading branch information
PragTob committed Nov 29, 2020
1 parent 2226051 commit aa64b87
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 160 deletions.
6 changes: 5 additions & 1 deletion features/config_json_formatter.feature
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Feature:

Background:
Given I'm working on the project "faked_project"

Scenario: With JSONFormatter
Given SimpleCov for Test/Unit is configured with:
"""
Expand All @@ -28,7 +29,6 @@ Feature:
Scenario: When CC_TEST_REPORTER_ID is set in the environment
Given SimpleCov for Test/Unit is configured with:
"""
ENV['CC_TEST_REPORTER_ID'] = "9719ac886877886b7e325d1e828373114f633683e429107d1221d25270baeabf"
require 'simplecov'
SimpleCov.at_exit do
puts SimpleCov.result.format!
Expand All @@ -37,7 +37,11 @@ Feature:
add_group 'Libs', 'lib/faked_project/'
end
"""
And I set the environment variables to:
| variable | value |
| CC_TEST_REPORTER_ID | some-id |

When I successfully run `bundle exec rake test`

Then a JSON coverage report should have been generated in "coverage"
And the output should contain "JSON Coverage report generated"
11 changes: 7 additions & 4 deletions features/step_definitions/json_steps.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# frozen_string_literal: true

Then /^the JSON coverage report should map:/ do |expected_report|
Then /^the JSON coverage report should match the output for the basic case$/ do
cd(".") do
json_report = File.open("coverage/coverage.json").read
expected_report = ERB.new(expected_report).result(binding)
expect(json_report).to eq(expected_report)
json_report = JSON.parse(File.read("coverage/coverage.json"))
coverage_hash = json_report.fetch "coverage"
directory = Dir.pwd

expect(coverage_hash.fetch("#{directory}/lib/faked_project.rb")).to eq "lines" => [nil, nil, 1, 1, 1, nil, nil, nil, 5, 3, nil, nil, 1]
expect(coverage_hash.fetch("#{directory}/lib/faked_project/some_class.rb")).to eq "lines" => [nil, nil, 1, 1, 1, nil, 1, 2, nil, nil, 1, 1, nil, nil, 1, 1, 1, nil, 0, nil, nil, 0, nil, nil, 1, nil, 1, 0, nil, nil]
end
end
156 changes: 1 addition & 155 deletions features/test_unit_basic.feature
Original file line number Diff line number Diff line change
Expand Up @@ -67,158 +67,4 @@ Feature:
| Unit Tests |

And a JSON coverage report should have been generated
And the JSON coverage report should map:
"""
{
"meta": {
"simplecov_version": "<%= SimpleCov::VERSION %>"
},
"coverage": {
"<%= Dir.pwd %>/lib/faked_project.rb": {
"lines": [
null,
null,
1,
1,
1,
null,
null,
null,
5,
3,
null,
null,
1
]
},
"<%= Dir.pwd %>/lib/faked_project/framework_specific.rb": {
"lines": [
null,
null,
null,
null,
null,
1,
1,
1,
0,
null,
null,
1,
0,
null,
null,
1,
1,
null,
null,
null
]
},
"<%= Dir.pwd %>/lib/faked_project/meta_magic.rb": {
"lines": [
null,
null,
1,
1,
1,
1,
null,
null,
null,
1,
1,
1,
null,
null,
null,
1,
1,
1,
null,
1,
1,
1,
null,
null,
null,
null
]
},
"<%= Dir.pwd %>/lib/faked_project/some_class.rb": {
"lines": [
null,
null,
1,
1,
1,
null,
1,
2,
null,
null,
1,
1,
null,
null,
1,
1,
1,
null,
0,
null,
null,
0,
null,
null,
1,
null,
1,
0,
null,
null
]
},
"<%= Dir.pwd %>/test/meta_magic_test.rb": {
"lines": [
null,
null,
1,
null,
1,
1,
1,
null,
null,
1,
1,
1,
1,
null,
null
]
},
"<%= Dir.pwd %>/test/some_class_test.rb": {
"lines": [
null,
null,
1,
null,
1,
1,
2,
null,
null,
1,
1,
null,
null,
1,
1,
null,
null
]
}
}
}
"""
And the JSON coverage report should match the output for the basic case

0 comments on commit aa64b87

Please sign in to comment.