diff --git a/Gemfile b/Gemfile index ce123893..fbaca788 100644 --- a/Gemfile +++ b/Gemfile @@ -10,6 +10,8 @@ source "https://rubygems.org" gem "matrix" +gem "simplecov_json_formatter", github: "PragTob/simplecov_json_formatter", branch: "group-support" + group :development do gem "apparition", github: "twalpole/apparition" # LOCKED: When this is released, use a released version https://github.com/twalpole/apparition/pull/79 gem "aruba", "~> 1.0" diff --git a/Gemfile.lock b/Gemfile.lock index b938f605..e01db583 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,3 +1,10 @@ +GIT + remote: https://github.com/PragTob/simplecov_json_formatter.git + revision: 9c78d46bd6577b2e74fba91335f013750f57dd14 + branch: group-support + specs: + simplecov_json_formatter (0.1.3) + GIT remote: https://github.com/twalpole/apparition.git revision: ca86be4d54af835d531dbcd2b86e7b2c77f85f34 @@ -148,7 +155,6 @@ GEM parser (>= 3.0.1.1) ruby-progressbar (1.11.0) simplecov-html (0.12.3) - simplecov_json_formatter (0.1.3) spoon (0.0.6) ffi sys-uname (1.2.2) @@ -189,6 +195,7 @@ DEPENDENCIES rspec (~> 3.2) rubocop simplecov! + simplecov_json_formatter! test-unit webrick diff --git a/features/config_json_formatter.feature b/features/config_json_formatter.feature index ed7a4473..349ecc15 100644 --- a/features/config_json_formatter.feature +++ b/features/config_json_formatter.feature @@ -24,6 +24,7 @@ Feature: When I successfully run `bundle exec rake test` Then a JSON coverage report should have been generated in "coverage" + And the JSON report should have the right content And the output should contain "JSON Coverage report generated" Scenario: When CC_TEST_REPORTER_ID is set in the environment @@ -44,4 +45,5 @@ Feature: When I successfully run `bundle exec rake test` Then a JSON coverage report should have been generated in "coverage" + And the JSON report should have the right content And the output should contain "JSON Coverage report generated" diff --git a/features/fixtures/json_formatter.json b/features/fixtures/json_formatter.json new file mode 100644 index 00000000..529c3825 --- /dev/null +++ b/features/fixtures/json_formatter.json @@ -0,0 +1,164 @@ +{ + "meta": { + "simplecov_version": "STUB_VERSION" + }, + "coverage": { + "/STUB_BASE_DIRECTORY/tmp/aruba/project/lib/faked_project.rb": { + "lines": [ + null, + null, + 1, + 1, + 1, + null, + null, + null, + 5, + 3, + null, + null, + 1 + ] + }, + "/STUB_BASE_DIRECTORY/tmp/aruba/project/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 + ] + }, + "/STUB_BASE_DIRECTORY/tmp/aruba/project/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 + ] + }, + "/STUB_BASE_DIRECTORY/tmp/aruba/project/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 + ] + }, + "/STUB_BASE_DIRECTORY/tmp/aruba/project/test/meta_magic_test.rb": { + "lines": [ + null, + null, + 1, + null, + 1, + 1, + 1, + null, + null, + 1, + 1, + 1, + 1, + null, + null + ] + }, + "/STUB_BASE_DIRECTORY/tmp/aruba/project/test/some_class_test.rb": { + "lines": [ + null, + null, + 1, + null, + 1, + 1, + 2, + null, + null, + 1, + 1, + null, + null, + 1, + 1, + null, + null + ] + } + }, + "groups": { + "Libs": { + "lines": { + "covered_percent": 86.11111111111111 + } + }, + "Ungrouped": { + "lines": { + "covered_percent": 100.0 + } + } + } +} diff --git a/features/step_definitions/simplecov_steps.rb b/features/step_definitions/simplecov_steps.rb index 406be390..fb4bb573 100644 --- a/features/step_definitions/simplecov_steps.rb +++ b/features/step_definitions/simplecov_steps.rb @@ -55,6 +55,31 @@ ) end +# this is highly bound to the test itself right now and might need +# adjustments in the future +Then /^the JSON report should have the right content$/ do + with_file_content "coverage/coverage.json" do |content| + expect(JSON.parse(content)).to eq(json_fixture) + end +end + +DEFAULT_WORKING_DIRECTORY = "STUB_BASE_DIRECTORY" +def use_current_working_directory(file) + current_working_directory = File.expand_path("../..", File.dirname(__FILE__)) + file.gsub!("/#{DEFAULT_WORKING_DIRECTORY}/", "#{current_working_directory}/") + + file +end + +VERSION_STUB = "STUB_VERSION" +def json_fixture + content = File.read("features/fixtures/json_formatter.json") + content = use_current_working_directory(content) + content.gsub!("STUB_VERSION", SimpleCov::VERSION) + + JSON.parse(content) +end + Then /^no coverage report should have been generated(?: in "([^"]*)")?$/ do |coverage_dir| coverage_dir ||= "coverage" steps %(