Skip to content

Commit

Permalink
Improve testing by covering additional edge cases
Browse files Browse the repository at this point in the history
* make sure the time is current is also tested
* adjust file paths so they actually end up trying to get merged
  and not being ignored
  • Loading branch information
PragTob committed Jan 16, 2020
1 parent 564accc commit 542090d
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 5 deletions.
14 changes: 12 additions & 2 deletions features/old_version_json.feature
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,18 @@ Feature:
path from 0.17 and below to our current version this cuke should pass :) #820

Scenario: Running the tests succeeds
Given the paths in the old .resultset.json are adjusted to the current environment
When I open the coverage report generated with `bundle exec rspec spec`
Then I should see the groups:
| name | coverage | files |
| All Files | 80.0% | 1 |
And I should see a line coverage summary of 4/5
| All Files | 88.89% | 2 |
And I should see a line coverage summary of 8/9

Scenario: Running the tests succeeds even with a current time stamp
Given the paths in the old .resultset.json are adjusted to the current environment
And the timestamp in the .resultset.json is current
When I open the coverage report generated with `bundle exec rspec spec`
Then I should see the groups:
| name | coverage | files |
| All Files | 88.89% | 2 |
And I should see a line coverage summary of 8/9
21 changes: 21 additions & 0 deletions features/step_definitions/old_coverage_json_steps.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

RESULTSET_JSON_PATH = "coverage/.resultset.json"
PATH_PLACE_HOLDER = "$$path"
COMMAND_NAME = "RSpec Different Name to avoid overriding"

Given "the paths in the old .resultset.json are adjusted to the current environment" do
in_current_directory do
resultset_json_content = File.read(RESULTSET_JSON_PATH)
File.write(RESULTSET_JSON_PATH, resultset_json_content.gsub(PATH_PLACE_HOLDER, Dir.pwd))
end
end

Given "the timestamp in the .resultset.json is current" do
in_current_directory do
resultset_json = File.read(RESULTSET_JSON_PATH)
resultset_hash = JSON.parse(resultset_json)
resultset_hash[COMMAND_NAME]["time"] = Time.now.to_i
File.write(RESULTSET_JSON_PATH, JSON.pretty_generate(resultset_hash))
end
end
1 change: 0 additions & 1 deletion features/support/env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
@test_project_name = "old_coverage_json"
end


Before do
this_dir = File.dirname(__FILE__)

Expand Down
1 change: 1 addition & 0 deletions test_projects/old_coverage_json/.rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--require spec_helper
4 changes: 2 additions & 2 deletions test_projects/old_coverage_json/coverage/.resultset.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"RSpec Different Name to avoid overriding": {
"coverage": {
"/home/tobi/github/simplecov/test_projects/old_coverage_json/lib/code.rb": [
"$$path/lib/code.rb": [
null,
null,
1,
Expand All @@ -14,7 +14,7 @@
null,
null
],
"/home/tobi/github/simplecov/test_projects/old_coverage_json/spec/code_spec.rb": [
"$$path/spec/code_spec.rb": [
null,
null,
1,
Expand Down

0 comments on commit 542090d

Please sign in to comment.