From aa64b87536c051beec09686e70c5dcf9ed700f6d Mon Sep 17 00:00:00 2001 From: Tobias Pfeiffer Date: Sun, 29 Nov 2020 17:49:13 +0100 Subject: [PATCH] Minor fixups in test code --- features/config_json_formatter.feature | 6 +- features/step_definitions/json_steps.rb | 11 +- features/test_unit_basic.feature | 156 +----------------------- 3 files changed, 13 insertions(+), 160 deletions(-) diff --git a/features/config_json_formatter.feature b/features/config_json_formatter.feature index 363e51a4..ed7a4473 100644 --- a/features/config_json_formatter.feature +++ b/features/config_json_formatter.feature @@ -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: """ @@ -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! @@ -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" diff --git a/features/step_definitions/json_steps.rb b/features/step_definitions/json_steps.rb index 9d4c9f01..a66f1461 100644 --- a/features/step_definitions/json_steps.rb +++ b/features/step_definitions/json_steps.rb @@ -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 diff --git a/features/test_unit_basic.feature b/features/test_unit_basic.feature index 2c475561..8bf20f0a 100644 --- a/features/test_unit_basic.feature +++ b/features/test_unit_basic.feature @@ -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