diff --git a/.codeclimate.yml b/.codeclimate.yml new file mode 100644 index 0000000..455a62d --- /dev/null +++ b/.codeclimate.yml @@ -0,0 +1,27 @@ +version: "2" +checks: + file-lines: + config: + threshold: 300 + method-complexity: + config: + threshold: 10 + method-count: + config: + threshold: 50 + similar-code: + config: + threshold: 50 + identical-code: + config: + threshold: 50 +plugins: + duplication: + enabled: true + exclude_patterns: + - "spec/" +exclude_patterns: + - "lib/rspec_tracer/html_reporter/assets" + - "lib/rspec_tracer/html_reporter/public" + - "sample_projects" + - "tmp" diff --git a/.github/workflows/lint-and-specs.yml b/.github/workflows/lint-and-specs.yml index 20f875b..ca67ae9 100644 --- a/.github/workflows/lint-and-specs.yml +++ b/.github/workflows/lint-and-specs.yml @@ -6,7 +6,7 @@ on: pull_request: concurrency: - group: ${GITHUB_REF#refs/heads/} + group: ${{ github.event_name == 'pull_request' && github.head_ref || github.ref }}-lint-and-specs cancel-in-progress: true jobs: @@ -20,18 +20,83 @@ jobs: ruby: [ '2.5', '2.6', '2.7', '3.0', 'head' ] steps: - - uses: actions/checkout@v2 + - name: Checkout + uses: actions/checkout@v2 - name: Setup Ruby uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby }} + - name: Setup Code Climate test-reporter + run: | + pip3 install awscli --user + curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter + chmod +x ./cc-test-reporter + ./cc-test-reporter before-build + - name: Install Dependencies run: bundle install --jobs 3 --retry 3 - - name: Run Rubocop - run: bundle exec rake rubocop + - name: Run Tests + run: bundle exec rake + + - name: Configure AWS Credentials for Coverage Upload + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-access-key-id: ${{ secrets.CI_AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.CI_AWS_SECRET_ACCESS_KEY }} + aws-region: us-east-1 + + - name: Upload Job Coverage + env: + GIT_BRANCH: ${{ github.event_name == 'pull_request' && github.head_ref || 'main' }} + GIT_COMMIT_SHA: ${{ github.sha }} + run: | + ./cc-test-reporter format-coverage coverage/coverage.json --output coverage/ruby-${{ matrix.ruby }}.simplecov.json --input-type simplecov + aws s3 cp coverage/ruby-${{ matrix.ruby }}.simplecov.json ${{ secrets.CI_ARTIFACTS_S3_URI }}/${{ github.repository }}/${{ github.run_number }}/ruby-${{ matrix.ruby }}.simplecov.json + + coverage: + needs: [ 'main' ] + name: coverage + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Setup Python + uses: actions/setup-python@v2 + with: + python-version: '3.9' + architecture: 'x64' + + - name: Setup Code Climate test-reporter + run: | + pip3 install awscli --user + curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter + chmod +x ./cc-test-reporter + ./cc-test-reporter before-build + + - name: Configure AWS Credentials for Coverage Upload + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-access-key-id: ${{ secrets.CI_AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.CI_AWS_SECRET_ACCESS_KEY }} + aws-region: us-east-1 + + - name: Download Jobs Coverage + run: | + mkdir coverage + aws s3 cp --recursive ${{ secrets.CI_ARTIFACTS_S3_URI }}/${{ github.repository }}/${{ github.run_number }}/ coverage/ - - name: Run Specs - run: bundle exec rake spec + - name: Upload Coverage + env: + GIT_BRANCH: ${{ github.event_name == 'pull_request' && github.head_ref || 'main' }} + GIT_COMMIT_SHA: ${{ github.sha }} + CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }} + run: | + ./cc-test-reporter sum-coverage coverage/ruby-*.simplecov.json --parts 5 --output coverage/coverage.json + ./cc-test-reporter upload-coverage --input coverage/coverage.json diff --git a/.github/workflows/rails-5-project.yml b/.github/workflows/rails-5-project.yml index 39c7075..6f0fdfa 100644 --- a/.github/workflows/rails-5-project.yml +++ b/.github/workflows/rails-5-project.yml @@ -6,7 +6,7 @@ on: pull_request: concurrency: - group: ${GITHUB_REF#refs/heads/}-rails-1 + group: ${{ github.event_name == 'pull_request' && github.head_ref || github.ref }}-rails-5 cancel-in-progress: true jobs: @@ -23,7 +23,8 @@ jobs: simplecov: [ 12, 13, 14, 15, 16, 17, 18, 19, 20, 21 ] steps: - - uses: actions/checkout@v2 + - name: Checkout + uses: actions/checkout@v2 - name: Setup Ruby uses: ruby/setup-ruby@v1 @@ -39,9 +40,4 @@ jobs: RSPEC_RAILS_VERSION: "~> ${{ matrix.rspec-rails }}" SIMPLECOV_VERSION: "~> 0.${{ matrix.simplecov }}.0" BRANCH_COVERAGE: "${{ matrix.simplecov >= 18 && 'true' || 'false' }}" - run: | - echo RAILS_VERSION=$RAILS_VERSION - echo RSPEC_RAILS_VERSION=$RSPEC_RAILS_VERSION - echo SIMPLECOV_VERSION=$SIMPLECOV_VERSION - echo BRANCH_COVERAGE=$BRANCH_COVERAGE - bundle exec cucumber --tags @rails_app + run: bundle exec cucumber --tags @rails-app diff --git a/.github/workflows/rails-6-project.yml b/.github/workflows/rails-6-project.yml index 234bc86..83b717b 100644 --- a/.github/workflows/rails-6-project.yml +++ b/.github/workflows/rails-6-project.yml @@ -6,7 +6,7 @@ on: pull_request: concurrency: - group: ${GITHUB_REF#refs/heads/}-rails-2 + group: ${{ github.event_name == 'pull_request' && github.head_ref || github.ref }}-rails-6 cancel-in-progress: true jobs: @@ -23,7 +23,8 @@ jobs: simplecov: [ 12, 13, 14, 15, 16, 17, 18, 19, 20, 21 ] steps: - - uses: actions/checkout@v2 + - name: Checkout + uses: actions/checkout@v2 - name: Setup Ruby uses: ruby/setup-ruby@v1 @@ -39,9 +40,4 @@ jobs: RSPEC_RAILS_VERSION: "~> ${{ matrix.rspec-rails }}" SIMPLECOV_VERSION: "~> 0.${{ matrix.simplecov }}.0" BRANCH_COVERAGE: "${{ matrix.simplecov >= 18 && 'true' || 'false' }}" - run: | - echo RAILS_VERSION=$RAILS_VERSION - echo RSPEC_RAILS_VERSION=$RSPEC_RAILS_VERSION - echo SIMPLECOV_VERSION=$SIMPLECOV_VERSION - echo BRANCH_COVERAGE=$BRANCH_COVERAGE - bundle exec cucumber --tags @rails_app + run: bundle exec cucumber --tags @rails-app diff --git a/.github/workflows/ruby-project-part-1.yml b/.github/workflows/ruby-project-part-1.yml index ebbd7a1..dbde681 100644 --- a/.github/workflows/ruby-project-part-1.yml +++ b/.github/workflows/ruby-project-part-1.yml @@ -6,7 +6,7 @@ on: pull_request: concurrency: - group: ${GITHUB_REF#refs/heads/}-ruby-1 + group: ${{ github.event_name == 'pull_request' && github.head_ref || github.ref }}-ruby-1 cancel-in-progress: true jobs: @@ -22,7 +22,8 @@ jobs: simplecov: [ '0.12.0', '0.13.0', '0.14.0', '0.15.0', '0.16.0', '0.17.0' ] steps: - - uses: actions/checkout@v2 + - name: Checkout + uses: actions/checkout@v2 - name: Setup Ruby uses: ruby/setup-ruby@v1 @@ -36,8 +37,4 @@ jobs: env: RSPEC_VERSION: "~> ${{ matrix.rspec }}" SIMPLECOV_VERSION: "~> ${{ matrix.simplecov }}" - run: | - echo RSPEC_VERSION=$RSPEC_VERSION - echo SIMPLECOV_VERSION=$SIMPLECOV_VERSION - echo BRANCH_COVERAGE=$BRANCH_COVERAGE - bundle exec cucumber --tags @ruby_app + run: bundle exec cucumber --tags @ruby-app diff --git a/.github/workflows/ruby-project-part-2.yml b/.github/workflows/ruby-project-part-2.yml index 999f7ae..d2b5d86 100644 --- a/.github/workflows/ruby-project-part-2.yml +++ b/.github/workflows/ruby-project-part-2.yml @@ -6,7 +6,7 @@ on: pull_request: concurrency: - group: ${GITHUB_REF#refs/heads/}-ruby-2 + group: ${{ github.event_name == 'pull_request' && github.head_ref || github.ref }}-ruby-2 cancel-in-progress: true jobs: @@ -22,7 +22,8 @@ jobs: simplecov: [ '0.18.0', '0.19.0', '0.20.0', '0.21.0' ] steps: - - uses: actions/checkout@v2 + - name: Checkout + uses: actions/checkout@v2 - name: Setup Ruby uses: ruby/setup-ruby@v1 @@ -37,8 +38,4 @@ jobs: RSPEC_VERSION: "~> ${{ matrix.rspec }}" SIMPLECOV_VERSION: "~> ${{ matrix.simplecov }}" BRANCH_COVERAGE: true - run: | - echo RSPEC_VERSION=$RSPEC_VERSION - echo SIMPLECOV_VERSION=$SIMPLECOV_VERSION - echo BRANCH_COVERAGE=$BRANCH_COVERAGE - bundle exec cucumber --tags @ruby_app + run: bundle exec cucumber --tags @ruby-app diff --git a/.rubocop.yml b/.rubocop.yml index 3aea0b2..9456c06 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -37,6 +37,7 @@ Layout/MultilineOperationIndentation: Metrics/BlockLength: Exclude: + - "tasks/**/*" - "spec/**/*" Metrics/ClassLength: diff --git a/Gemfile.lock b/Gemfile.lock index 3b3d256..c810cae 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -123,7 +123,9 @@ GEM yui-compressor (0.12.0) PLATFORMS + ruby x86_64-darwin-19 + x86_64-linux DEPENDENCIES aruba (~> 2.0) diff --git a/Rakefile b/Rakefile index d34dbbe..e4d4fd5 100644 --- a/Rakefile +++ b/Rakefile @@ -4,37 +4,17 @@ require 'rubocop/rake_task' RuboCop::RakeTask.new require 'rspec/core/rake_task' -RSpec::Core::RakeTask.new(:spec) - -namespace :features do - desc 'Run feature specs on sample ruby project' - task :ruby do - puts "\nRunning feature specs on sample Ruby project..." - - command = <<-COMMAND.strip.gsub(/\s+/, ' ') - RSPEC_VERSION="~> 3.10.0" - SIMPLECOV_VERSION="~> 0.21.0" - BRANCH_COVERAGE="true" - bundle exec cucumber features/ruby_app_*.feature - COMMAND - - exit(1) unless system(command) - end - - desc 'Run feature specs on sample rails project' - task :rails do - puts "\nRunning feature specs on sample Rails project..." - - command = <<-COMMAND.strip.gsub(/\s+/, ' ') - RAILS_VERSION="~> 6.1.0" - RSPEC_RAILS_VERSION="~> 5.0.0" - SIMPLECOV_VERSION="~> 0.21.0" - BRANCH_COVERAGE="true" - bundle exec cucumber features/rails_app_*.feature - COMMAND - - exit(1) unless system(command) - end -end - -task default: %i[rubocop spec features:ruby features:rails] +RSpec::Core::RakeTask.new(:rspec) + +Dir.glob('tasks/features/**/*.rake') { |task| load task } + +task default: %i[ + rubocop + rspec + features:coverage:rspec_tracer:measure_line_coverage + features:coverage:simplecov:measure_branch_coverage + features:coverage:simplecov:measure_line_coverage + features:validation:rspec_tracer:validate_line_coverage + features:validation:simplecov:validate_branch_coverage + features:validation:simplecov:validate_line_coverage +] diff --git a/features/rails_app_with_explicit_run.feature b/features/rails_app_with_explicit_run.feature index d088c2d..04c4255 100644 --- a/features/rails_app_with_explicit_run.feature +++ b/features/rails_app_with_explicit_run.feature @@ -1,4 +1,4 @@ -@rails_app @simplecov @explicit_run @disable-bundler +@rails-app @simplecov @explicit-run @disable-bundler Feature: Rails App with Explicit Run Adding rspec-tracer with simplecov should generate tracer reports and the @@ -53,7 +53,7 @@ Feature: Rails App with Explicit Run And The dependency report should have correct details And The reverse dependency report should have correct details And The JSON coverage report should have been generated for "RSpec" - And the output should contain "71 / 72 LOC (98.61%) covered" + And The coverage percent stat is "71 / 72 LOC (98.61%) covered" And The JSON coverage report should have correct coverage for "RSpec" Given I want to explicitly run all the tests When I run `bundle exec rspec spec` @@ -101,7 +101,7 @@ Feature: Rails App with Explicit Run And The dependency report should have correct details And The reverse dependency report should have correct details And The JSON coverage report should have been generated for "RSpec" - And the output should contain "71 / 72 LOC (98.61%) covered" + And The coverage percent stat is "71 / 72 LOC (98.61%) covered" And The JSON coverage report should have correct coverage for "RSpec" Given I reset explicit run When I run `bundle exec rspec spec` @@ -141,5 +141,5 @@ Feature: Rails App with Explicit Run And The dependency report should have correct details And The reverse dependency report should have correct details And The JSON coverage report should have been generated for "RSpec" - And the output should contain "71 / 72 LOC (98.61%) covered" + And The coverage percent stat is "71 / 72 LOC (98.61%) covered" And The JSON coverage report should have correct coverage for "RSpec" diff --git a/features/rails_app_with_simplecov.feature b/features/rails_app_with_simplecov.feature index 2763c84..edc546f 100644 --- a/features/rails_app_with_simplecov.feature +++ b/features/rails_app_with_simplecov.feature @@ -1,4 +1,4 @@ -@rails_app @simplecov @disable-bundler +@rails-app @simplecov @disable-bundler Feature: Rails App with SimpleCov Adding rspec-tracer with simplecov should generate tracer reports and the @@ -53,7 +53,7 @@ Feature: Rails App with SimpleCov And The dependency report should have correct details And The reverse dependency report should have correct details And The JSON coverage report should have been generated for "RSpec" - And the output should contain "71 / 72 LOC (98.61%) covered" + And The coverage percent stat is "71 / 72 LOC (98.61%) covered" And The JSON coverage report should have correct coverage for "RSpec" When I run `bundle exec rspec spec` Then The RSpecTracer should print the information @@ -92,7 +92,7 @@ Feature: Rails App with SimpleCov And The dependency report should have correct details And The reverse dependency report should have correct details And The JSON coverage report should have been generated for "RSpec" - And the output should contain "71 / 72 LOC (98.61%) covered" + And The coverage percent stat is "71 / 72 LOC (98.61%) covered" And The JSON coverage report should have correct coverage for "RSpec" Given I replace spec helper with "with_simplecov_updated.rb" When I run `bundle exec rspec spec` @@ -140,7 +140,7 @@ Feature: Rails App with SimpleCov And The dependency report should have correct details And The reverse dependency report should have correct details And The JSON coverage report should have been generated for "RSpec" - And the output should contain "71 / 72 LOC (98.61%) covered" + And The coverage percent stat is "71 / 72 LOC (98.61%) covered" And The JSON coverage report should have correct coverage for "RSpec" When I run `bundle exec rspec spec` Then The RSpecTracer should print the information @@ -179,7 +179,7 @@ Feature: Rails App with SimpleCov And The dependency report should have correct details And The reverse dependency report should have correct details And The JSON coverage report should have been generated for "RSpec" - And the output should contain "71 / 72 LOC (98.61%) covered" + And The coverage percent stat is "71 / 72 LOC (98.61%) covered" And The JSON coverage report should have correct coverage for "RSpec" When I run `bundle exec rspec spec/course_spec.rb` Then The RSpecTracer should print the information @@ -217,7 +217,7 @@ Feature: Rails App with SimpleCov And The dependency report should have correct details And The reverse dependency report should have correct details And The JSON coverage report should have been generated for "RSpec" - And the output should contain "57 / 72 LOC (79.17%) covered" + And The coverage percent stat is "57 / 72 LOC (79.17%) covered" When I run `bundle exec rspec spec/student_spec.rb` Then The RSpecTracer should print the information """ @@ -254,7 +254,7 @@ Feature: Rails App with SimpleCov And The dependency report should have correct details And The reverse dependency report should have correct details And The JSON coverage report should have been generated for "RSpec" - And the output should contain "57 / 72 LOC (79.17%) covered" + And The coverage percent stat is "64 / 72 LOC (88.89%) covered" When I run `bundle exec rspec spec` Then The RSpecTracer should print the information """ @@ -292,5 +292,5 @@ Feature: Rails App with SimpleCov And The dependency report should have correct details And The reverse dependency report should have correct details And The JSON coverage report should have been generated for "RSpec" - And the output should contain "71 / 72 LOC (98.61%) covered" + And The coverage percent stat is "71 / 72 LOC (98.61%) covered" And The JSON coverage report should have correct coverage for "RSpec" diff --git a/features/rails_app_with_simplecov_branch_coverage.feature b/features/rails_app_with_simplecov_branch_coverage.feature index 8fd6a71..9f24d07 100644 --- a/features/rails_app_with_simplecov_branch_coverage.feature +++ b/features/rails_app_with_simplecov_branch_coverage.feature @@ -1,4 +1,4 @@ -@rails_app @simplecov @branch_coverage @disable-bundler +@rails-app @simplecov @branch-coverage @disable-bundler Feature: Rails App with SimpleCov Branch Coverage Adding rspec-tracer with simplecov branch coverage should generate tracer @@ -53,7 +53,7 @@ Feature: Rails App with SimpleCov Branch Coverage And The dependency report should have correct details And The reverse dependency report should have correct details And The JSON coverage report should have been generated for "RSpec" - And the output should contain "71 / 72 LOC (98.61%) covered" + And The coverage percent stat is "71 / 72 LOC (98.61%) covered" And The JSON coverage report should have correct coverage for "RSpec" When I run `bundle exec rspec spec` Then The RSpecTracer should print the information @@ -92,7 +92,7 @@ Feature: Rails App with SimpleCov Branch Coverage And The dependency report should have correct details And The reverse dependency report should have correct details And The JSON coverage report should have been generated for "RSpec" - And the output should contain "71 / 72 LOC (98.61%) covered" + And The coverage percent stat is "71 / 72 LOC (98.61%) covered" And The JSON coverage report should have correct coverage for "RSpec" Given I replace spec helper with "with_simplecov_with_branch_coverage_updated.rb" When I run `bundle exec rspec spec` @@ -140,7 +140,7 @@ Feature: Rails App with SimpleCov Branch Coverage And The dependency report should have correct details And The reverse dependency report should have correct details And The JSON coverage report should have been generated for "RSpec" - And the output should contain "71 / 72 LOC (98.61%) covered" + And The coverage percent stat is "71 / 72 LOC (98.61%) covered" And The JSON coverage report should have correct coverage for "RSpec" When I run `bundle exec rspec spec` Then The RSpecTracer should print the information @@ -179,7 +179,7 @@ Feature: Rails App with SimpleCov Branch Coverage And The dependency report should have correct details And The reverse dependency report should have correct details And The JSON coverage report should have been generated for "RSpec" - And the output should contain "71 / 72 LOC (98.61%) covered" + And The coverage percent stat is "71 / 72 LOC (98.61%) covered" And The JSON coverage report should have correct coverage for "RSpec" When I run `bundle exec rspec spec/course_spec.rb` Then The RSpecTracer should print the information @@ -217,7 +217,7 @@ Feature: Rails App with SimpleCov Branch Coverage And The dependency report should have correct details And The reverse dependency report should have correct details And The JSON coverage report should have been generated for "RSpec" - And the output should contain "57 / 72 LOC (79.17%) covered" + And The coverage percent stat is "57 / 72 LOC (79.17%) covered" When I run `bundle exec rspec spec/student_spec.rb` Then The RSpecTracer should print the information """ @@ -254,7 +254,7 @@ Feature: Rails App with SimpleCov Branch Coverage And The dependency report should have correct details And The reverse dependency report should have correct details And The JSON coverage report should have been generated for "RSpec" - And the output should contain "57 / 72 LOC (79.17%) covered" + And The coverage percent stat is "64 / 72 LOC (88.89%) covered" When I run `bundle exec rspec spec` Then The RSpecTracer should print the information """ @@ -292,5 +292,5 @@ Feature: Rails App with SimpleCov Branch Coverage And The dependency report should have correct details And The reverse dependency report should have correct details And The JSON coverage report should have been generated for "RSpec" - And the output should contain "71 / 72 LOC (98.61%) covered" + And The coverage percent stat is "71 / 72 LOC (98.61%) covered" And The JSON coverage report should have correct coverage for "RSpec" diff --git a/features/rails_app_with_test_suite_id.feature b/features/rails_app_with_test_suite_id.feature index 920d89c..671d3a0 100644 --- a/features/rails_app_with_test_suite_id.feature +++ b/features/rails_app_with_test_suite_id.feature @@ -1,4 +1,4 @@ -@rails_app @no_simplecov @test_suite @disable-bundler +@rails-app @no-simplecov @test-suite @disable-bundler Feature: Rails App with Test Suite ID Adding rspec-tracer without simplecov should generate tracer reports and the @@ -42,7 +42,7 @@ Feature: Rails App with Test Suite ID And The dependency report should have correct details And The reverse dependency report should have correct details And The JSON coverage report should have been generated for "RSpecTracer" - And the output should contain "66 / 84 LOC (78.57%) covered" + And The coverage percent stat is "66 / 84 LOC (78.57%) covered" And The JSON coverage report should have correct coverage for "RSpecTracer" Given I use test suite id 2 When I run `bundle exec rspec spec/student_spec.rb` @@ -84,7 +84,7 @@ Feature: Rails App with Test Suite ID And The dependency report should have correct details And The reverse dependency report should have correct details And The JSON coverage report should have been generated for "RSpecTracer" - And the output should contain "71 / 84 LOC (84.52%) covered" + And The coverage percent stat is "71 / 84 LOC (84.52%) covered" And The JSON coverage report should have correct coverage for "RSpecTracer" Given I use test suite id 1 When I run specs using "rspec spec/course_spec.rb" @@ -119,7 +119,7 @@ Feature: Rails App with Test Suite ID And The dependency report should have correct details And The reverse dependency report should have correct details And The JSON coverage report should have been generated for "RSpecTracer" - And the output should contain "66 / 84 LOC (78.57%) covered" + And The coverage percent stat is "66 / 84 LOC (78.57%) covered" And The JSON coverage report should have correct coverage for "RSpecTracer" Given I use test suite id 2 When I run `bundle exec rspec spec/student_spec.rb` @@ -154,7 +154,7 @@ Feature: Rails App with Test Suite ID And The dependency report should have correct details And The reverse dependency report should have correct details And The JSON coverage report should have been generated for "RSpecTracer" - And the output should contain "71 / 84 LOC (84.52%) covered" + And The coverage percent stat is "71 / 84 LOC (84.52%) covered" And The JSON coverage report should have correct coverage for "RSpecTracer" Given I reset test suite id When I run `bundle exec rspec spec` @@ -201,5 +201,5 @@ Feature: Rails App with Test Suite ID And The dependency report should have correct details And The reverse dependency report should have correct details And The JSON coverage report should have been generated for "RSpecTracer" - And the output should contain "71 / 84 LOC (84.52%) covered" + And The coverage percent stat is "71 / 84 LOC (84.52%) covered" And The JSON coverage report should have correct coverage for "RSpecTracer" diff --git a/features/rails_app_without_simplecov.feature b/features/rails_app_without_simplecov.feature index 99e1695..1214a0c 100644 --- a/features/rails_app_without_simplecov.feature +++ b/features/rails_app_without_simplecov.feature @@ -1,4 +1,4 @@ -@rails_app @no_simplecov @disable-bundler +@rails-app @no-simplecov @disable-bundler Feature: Rails App without SimpleCov Adding rspec-tracer without simplecov should generate tracer reports and the @@ -52,7 +52,7 @@ Feature: Rails App without SimpleCov And The dependency report should have correct details And The reverse dependency report should have correct details And The JSON coverage report should have been generated for "RSpecTracer" - And the output should contain "71 / 84 LOC (84.52%) covered" + And The coverage percent stat is "71 / 84 LOC (84.52%) covered" And The JSON coverage report should have correct coverage for "RSpecTracer" When I run `bundle exec rspec spec` Then The RSpecTracer should print the information @@ -90,7 +90,7 @@ Feature: Rails App without SimpleCov And The dependency report should have correct details And The reverse dependency report should have correct details And The JSON coverage report should have been generated for "RSpecTracer" - And the output should contain "71 / 84 LOC (84.52%) covered" + And The coverage percent stat is "71 / 84 LOC (84.52%) covered" And The JSON coverage report should have correct coverage for "RSpecTracer" Given I replace spec helper with "without_simplecov_updated.rb" When I run `bundle exec rspec spec` @@ -137,7 +137,7 @@ Feature: Rails App without SimpleCov And The dependency report should have correct details And The reverse dependency report should have correct details And The JSON coverage report should have been generated for "RSpecTracer" - And the output should contain "71 / 84 LOC (84.52%) covered" + And The coverage percent stat is "71 / 84 LOC (84.52%) covered" And The JSON coverage report should have correct coverage for "RSpecTracer" When I run `bundle exec rspec spec` Then The RSpecTracer should print the information @@ -175,7 +175,7 @@ Feature: Rails App without SimpleCov And The dependency report should have correct details And The reverse dependency report should have correct details And The JSON coverage report should have been generated for "RSpecTracer" - And the output should contain "71 / 84 LOC (84.52%) covered" + And The coverage percent stat is "71 / 84 LOC (84.52%) covered" And The JSON coverage report should have correct coverage for "RSpecTracer" When I run `bundle exec rspec spec/course_spec.rb` Then The RSpecTracer should print the information @@ -212,7 +212,7 @@ Feature: Rails App without SimpleCov And The dependency report should have correct details And The reverse dependency report should have correct details And The JSON coverage report should have been generated for "RSpecTracer" - And the output should contain "71 / 84 LOC (84.52%) covered" + And The coverage percent stat is "57 / 84 LOC (67.86%) covered" When I run `bundle exec rspec spec/student_spec.rb` Then The RSpecTracer should print the information """ @@ -248,7 +248,7 @@ Feature: Rails App without SimpleCov And The dependency report should have correct details And The reverse dependency report should have correct details And The JSON coverage report should have been generated for "RSpecTracer" - And the output should contain "71 / 84 LOC (84.52%) covered" + And The coverage percent stat is "64 / 84 LOC (76.19%) covered" When I run `bundle exec rspec spec` Then The RSpecTracer should print the information """ @@ -285,5 +285,5 @@ Feature: Rails App without SimpleCov And The dependency report should have correct details And The reverse dependency report should have correct details And The JSON coverage report should have been generated for "RSpecTracer" - And the output should contain "71 / 84 LOC (84.52%) covered" + And The coverage percent stat is "71 / 84 LOC (84.52%) covered" And The JSON coverage report should have correct coverage for "RSpecTracer" diff --git a/features/ruby_app_with_explicit_run.feature b/features/ruby_app_with_explicit_run.feature index 8a14b99..9551bb3 100644 --- a/features/ruby_app_with_explicit_run.feature +++ b/features/ruby_app_with_explicit_run.feature @@ -1,4 +1,4 @@ -@ruby_app @simplecov @explicit_run @disable-bundler +@ruby-app @simplecov @explicit-run @disable-bundler Feature: Ruby App Explicit Run Adding rspec-tracer with simplecov should generate tracer reports and the @@ -52,7 +52,7 @@ Feature: Ruby App Explicit Run And The dependency report should have correct details And The reverse dependency report should have correct details And The JSON coverage report should have been generated for "RSpec" - And the output should contain "32 / 33 LOC (96.97%) covered" + And The coverage percent stat is "32 / 33 LOC (96.97%) covered" And The JSON coverage report should have correct coverage for "RSpec" Given I want to explicitly run all the tests When I run `bundle exec rspec spec` @@ -99,7 +99,7 @@ Feature: Ruby App Explicit Run And The dependency report should have correct details And The reverse dependency report should have correct details And The JSON coverage report should have been generated for "RSpec" - And the output should contain "32 / 33 LOC (96.97%) covered" + And The coverage percent stat is "32 / 33 LOC (96.97%) covered" And The JSON coverage report should have correct coverage for "RSpec" Given I reset explicit run When I run `bundle exec rspec spec` @@ -138,5 +138,5 @@ Feature: Ruby App Explicit Run And The dependency report should have correct details And The reverse dependency report should have correct details And The JSON coverage report should have been generated for "RSpec" - And the output should contain "32 / 33 LOC (96.97%) covered" + And The coverage percent stat is "32 / 33 LOC (96.97%) covered" And The JSON coverage report should have correct coverage for "RSpec" diff --git a/features/ruby_app_with_flaky_examples.feature b/features/ruby_app_with_flaky_examples.feature index 571fce3..589a879 100644 --- a/features/ruby_app_with_flaky_examples.feature +++ b/features/ruby_app_with_flaky_examples.feature @@ -1,4 +1,4 @@ -@ruby_app @simplecov @flaky_examples @force_fail @disable-bundler +@ruby-app @simplecov @flaky-examples @force-fail @disable-bundler Feature: Ruby App With Flaky Examples Adding rspec-tracer with simplecov should generate tracer reports and the @@ -54,7 +54,7 @@ Feature: Ruby App With Flaky Examples And The dependency report should have correct details And The reverse dependency report should have correct details And The JSON coverage report should have been generated for "RSpec" - And the output should contain "31 / 33 LOC (93.94%) covered" + And The coverage percent stat is "31 / 33 LOC (93.94%) covered" And The JSON coverage report should have correct coverage for "RSpec" When I run `bundle exec rspec spec` Then The RSpecTracer should print the information @@ -95,7 +95,7 @@ Feature: Ruby App With Flaky Examples And The dependency report should have correct details And The reverse dependency report should have correct details And The JSON coverage report should have been generated for "RSpec" - And the output should contain "31 / 33 LOC (93.94%) covered" + And The coverage percent stat is "31 / 33 LOC (93.94%) covered" And The JSON coverage report should have correct coverage for "RSpec" Given I reset force fail When I run `bundle exec rspec spec` @@ -137,7 +137,7 @@ Feature: Ruby App With Flaky Examples And The dependency report should have correct details And The reverse dependency report should have correct details And The JSON coverage report should have been generated for "RSpec" - And the output should contain "32 / 33 LOC (96.97%) covered" + And The coverage percent stat is "32 / 33 LOC (96.97%) covered" And The JSON coverage report should have correct coverage for "RSpec" When I run `bundle exec rspec spec` Then The RSpecTracer should print the information @@ -178,7 +178,7 @@ Feature: Ruby App With Flaky Examples And The dependency report should have correct details And The reverse dependency report should have correct details And The JSON coverage report should have been generated for "RSpec" - And the output should contain "32 / 33 LOC (96.97%) covered" + And The coverage percent stat is "32 / 33 LOC (96.97%) covered" And The JSON coverage report should have correct coverage for "RSpec" When I run `bundle exec rspec spec` Then The RSpecTracer should print the information @@ -219,7 +219,7 @@ Feature: Ruby App With Flaky Examples And The dependency report should have correct details And The reverse dependency report should have correct details And The JSON coverage report should have been generated for "RSpec" - And the output should contain "32 / 33 LOC (96.97%) covered" + And The coverage percent stat is "32 / 33 LOC (96.97%) covered" And The JSON coverage report should have correct coverage for "RSpec" Given I want to force fail some of the tests When I run `bundle exec rspec spec` @@ -261,7 +261,7 @@ Feature: Ruby App With Flaky Examples And The dependency report should have correct details And The reverse dependency report should have correct details And The JSON coverage report should have been generated for "RSpec" - And the output should contain "32 / 33 LOC (96.97%) covered" + And The coverage percent stat is "31 / 33 LOC (93.94%) covered" And The JSON coverage report should have correct coverage for "RSpec" Given I reset force fail When I run `bundle exec rspec spec` @@ -303,7 +303,7 @@ Feature: Ruby App With Flaky Examples And The dependency report should have correct details And The reverse dependency report should have correct details And The JSON coverage report should have been generated for "RSpec" - And the output should contain "32 / 33 LOC (96.97%) covered" + And The coverage percent stat is "32 / 33 LOC (96.97%) covered" And The JSON coverage report should have correct coverage for "RSpec" Given I reset force fail When I update the spec file "student_spec" @@ -351,7 +351,7 @@ Feature: Ruby App With Flaky Examples And The dependency report should have correct details And The reverse dependency report should have correct details And The JSON coverage report should have been generated for "RSpec" - And the output should contain "32 / 33 LOC (96.97%) covered" + And The coverage percent stat is "32 / 33 LOC (96.97%) covered" And The JSON coverage report should have correct coverage for "RSpec" When I run `bundle exec rspec spec` Then The RSpecTracer should print the information @@ -390,5 +390,5 @@ Feature: Ruby App With Flaky Examples And The dependency report should have correct details And The reverse dependency report should have correct details And The JSON coverage report should have been generated for "RSpec" - And the output should contain "32 / 33 LOC (96.97%) covered" + And The coverage percent stat is "32 / 33 LOC (96.97%) covered" And The JSON coverage report should have correct coverage for "RSpec" diff --git a/features/ruby_app_with_simplecov.feature b/features/ruby_app_with_simplecov.feature index 430476b..96c84b9 100644 --- a/features/ruby_app_with_simplecov.feature +++ b/features/ruby_app_with_simplecov.feature @@ -1,4 +1,4 @@ -@ruby_app @simplecov @disable-bundler +@ruby-app @simplecov @disable-bundler Feature: Ruby App with SimpleCov Adding rspec-tracer with simplecov should generate tracer reports and the @@ -52,7 +52,7 @@ Feature: Ruby App with SimpleCov And The dependency report should have correct details And The reverse dependency report should have correct details And The JSON coverage report should have been generated for "RSpec" - And the output should contain "32 / 33 LOC (96.97%) covered" + And The coverage percent stat is "32 / 33 LOC (96.97%) covered" And The JSON coverage report should have correct coverage for "RSpec" When I run `bundle exec rspec spec` Then The RSpecTracer should print the information @@ -90,7 +90,7 @@ Feature: Ruby App with SimpleCov And The dependency report should have correct details And The reverse dependency report should have correct details And The JSON coverage report should have been generated for "RSpec" - And the output should contain "32 / 33 LOC (96.97%) covered" + And The coverage percent stat is "32 / 33 LOC (96.97%) covered" And The JSON coverage report should have correct coverage for "RSpec" Given I replace spec helper with "with_simplecov_updated.rb" When I run `bundle exec rspec spec` @@ -137,7 +137,7 @@ Feature: Ruby App with SimpleCov And The dependency report should have correct details And The reverse dependency report should have correct details And The JSON coverage report should have been generated for "RSpec" - And the output should contain "32 / 33 LOC (96.97%) covered" + And The coverage percent stat is "32 / 33 LOC (96.97%) covered" And The JSON coverage report should have correct coverage for "RSpec" When I run `bundle exec rspec spec` Then The RSpecTracer should print the information @@ -175,7 +175,7 @@ Feature: Ruby App with SimpleCov And The dependency report should have correct details And The reverse dependency report should have correct details And The JSON coverage report should have been generated for "RSpec" - And the output should contain "32 / 33 LOC (96.97%) covered" + And The coverage percent stat is "32 / 33 LOC (96.97%) covered" And The JSON coverage report should have correct coverage for "RSpec" When I run `bundle exec rspec spec/course_spec.rb` Then The RSpecTracer should print the information @@ -211,7 +211,7 @@ Feature: Ruby App with SimpleCov And The dependency report should have correct details And The reverse dependency report should have correct details And The JSON coverage report should have been generated for "RSpec" - And the output should contain "27 / 33 LOC (81.82%) covered" + And The coverage percent stat is "27 / 33 LOC (81.82%) covered" When I run `bundle exec rspec spec/student_spec.rb` Then The RSpecTracer should print the information """ @@ -246,7 +246,7 @@ Feature: Ruby App with SimpleCov And The dependency report should have correct details And The reverse dependency report should have correct details And The JSON coverage report should have been generated for "RSpec" - And the output should contain "32 / 33 LOC (96.97%) covered" + And The coverage percent stat is "25 / 33 LOC (75.76%) covered" When I run `bundle exec rspec spec` Then The RSpecTracer should print the information """ @@ -282,5 +282,5 @@ Feature: Ruby App with SimpleCov And The dependency report should have correct details And The reverse dependency report should have correct details And The JSON coverage report should have been generated for "RSpec" - And the output should contain "32 / 33 LOC (96.97%) covered" + And The coverage percent stat is "32 / 33 LOC (96.97%) covered" And The JSON coverage report should have correct coverage for "RSpec" diff --git a/features/ruby_app_with_simplecov_branch_coverage.feature b/features/ruby_app_with_simplecov_branch_coverage.feature index 51f5897..fff9e2e 100644 --- a/features/ruby_app_with_simplecov_branch_coverage.feature +++ b/features/ruby_app_with_simplecov_branch_coverage.feature @@ -1,4 +1,4 @@ -@ruby_app @simplecov @branch_coverage @disable-bundler +@ruby-app @simplecov @branch-coverage @disable-bundler Feature: Ruby App with SimpleCov Branch Coverage Adding rspec-tracer with simplecov branch coverage should generate tracer @@ -52,7 +52,7 @@ Feature: Ruby App with SimpleCov Branch Coverage And The dependency report should have correct details And The reverse dependency report should have correct details And The JSON coverage report should have been generated for "RSpec" - And the output should contain "32 / 33 LOC (96.97%) covered" + And The coverage percent stat is "32 / 33 LOC (96.97%) covered" And The JSON coverage report should have correct coverage for "RSpec" When I run `bundle exec rspec spec` Then The RSpecTracer should print the information @@ -90,7 +90,7 @@ Feature: Ruby App with SimpleCov Branch Coverage And The dependency report should have correct details And The reverse dependency report should have correct details And The JSON coverage report should have been generated for "RSpec" - And the output should contain "32 / 33 LOC (96.97%) covered" + And The coverage percent stat is "32 / 33 LOC (96.97%) covered" And The JSON coverage report should have correct coverage for "RSpec" Given I replace spec helper with "with_simplecov_with_branch_coverage_updated.rb" When I run `bundle exec rspec spec` @@ -137,7 +137,7 @@ Feature: Ruby App with SimpleCov Branch Coverage And The dependency report should have correct details And The reverse dependency report should have correct details And The JSON coverage report should have been generated for "RSpec" - And the output should contain "32 / 33 LOC (96.97%) covered" + And The coverage percent stat is "32 / 33 LOC (96.97%) covered" And The JSON coverage report should have correct coverage for "RSpec" When I run `bundle exec rspec spec` Then The RSpecTracer should print the information @@ -175,7 +175,7 @@ Feature: Ruby App with SimpleCov Branch Coverage And The dependency report should have correct details And The reverse dependency report should have correct details And The JSON coverage report should have been generated for "RSpec" - And the output should contain "32 / 33 LOC (96.97%) covered" + And The coverage percent stat is "32 / 33 LOC (96.97%) covered" And The JSON coverage report should have correct coverage for "RSpec" When I run `bundle exec rspec spec/course_spec.rb` Then The RSpecTracer should print the information @@ -211,7 +211,7 @@ Feature: Ruby App with SimpleCov Branch Coverage And The dependency report should have correct details And The reverse dependency report should have correct details And The JSON coverage report should have been generated for "RSpec" - And the output should contain "27 / 33 LOC (81.82%) covered" + And The coverage percent stat is "27 / 33 LOC (81.82%) covered" When I run `bundle exec rspec spec/student_spec.rb` Then The RSpecTracer should print the information """ @@ -246,7 +246,7 @@ Feature: Ruby App with SimpleCov Branch Coverage And The dependency report should have correct details And The reverse dependency report should have correct details And The JSON coverage report should have been generated for "RSpec" - And the output should contain "32 / 33 LOC (96.97%) covered" + And The coverage percent stat is "25 / 33 LOC (75.76%) covered" When I run `bundle exec rspec spec` Then The RSpecTracer should print the information """ @@ -282,5 +282,5 @@ Feature: Ruby App with SimpleCov Branch Coverage And The dependency report should have correct details And The reverse dependency report should have correct details And The JSON coverage report should have been generated for "RSpec" - And the output should contain "32 / 33 LOC (96.97%) covered" + And The coverage percent stat is "32 / 33 LOC (96.97%) covered" And The JSON coverage report should have correct coverage for "RSpec" diff --git a/features/ruby_app_with_test_suite_id.feature b/features/ruby_app_with_test_suite_id.feature index 3fd0376..ec098ea 100644 --- a/features/ruby_app_with_test_suite_id.feature +++ b/features/ruby_app_with_test_suite_id.feature @@ -1,4 +1,4 @@ -@ruby_app @no_simplecov @test_suite @disable-bundler +@ruby-app @no-simplecov @test-suite @disable-bundler Feature: Ruby App with Test Suite ID Adding rspec-tracer without simplecov should generate tracer reports and the @@ -41,7 +41,7 @@ Feature: Ruby App with Test Suite ID And The dependency report should have correct details And The reverse dependency report should have correct details And The JSON coverage report should have been generated for "RSpecTracer" - And the output should contain "27 / 41 LOC (65.85%) covered" + And The coverage percent stat is "27 / 41 LOC (65.85%) covered" And The JSON coverage report should have correct coverage for "RSpecTracer" Given I use test suite id 2 When I run `bundle exec rspec spec/student_spec.rb` @@ -81,7 +81,7 @@ Feature: Ruby App with Test Suite ID And The dependency report should have correct details And The reverse dependency report should have correct details And The JSON coverage report should have been generated for "RSpecTracer" - And the output should contain "17 / 41 LOC (41.46%) covered" + And The coverage percent stat is "17 / 41 LOC (41.46%) covered" And The JSON coverage report should have correct coverage for "RSpecTracer" Given I use test suite id 1 When I run `bundle exec rspec spec/course_spec.rb` @@ -115,7 +115,7 @@ Feature: Ruby App with Test Suite ID And The dependency report should have correct details And The reverse dependency report should have correct details And The JSON coverage report should have been generated for "RSpecTracer" - And the output should contain "27 / 41 LOC (65.85%) covered" + And The coverage percent stat is "27 / 41 LOC (65.85%) covered" And The JSON coverage report should have correct coverage for "RSpecTracer" Given I use test suite id 2 When I run `bundle exec rspec spec/student_spec.rb` @@ -149,7 +149,7 @@ Feature: Ruby App with Test Suite ID And The dependency report should have correct details And The reverse dependency report should have correct details And The JSON coverage report should have been generated for "RSpecTracer" - And the output should contain "17 / 41 LOC (41.46%) covered" + And The coverage percent stat is "17 / 41 LOC (41.46%) covered" And The JSON coverage report should have correct coverage for "RSpecTracer" Given I reset test suite id When I run `bundle exec rspec spec` @@ -195,5 +195,5 @@ Feature: Ruby App with Test Suite ID And The dependency report should have correct details And The reverse dependency report should have correct details And The JSON coverage report should have been generated for "RSpecTracer" - And the output should contain "32 / 41 LOC (78.05%) covered" + And The coverage percent stat is "32 / 41 LOC (78.05%) covered" And The JSON coverage report should have correct coverage for "RSpecTracer" diff --git a/features/ruby_app_without_simplecov.feature b/features/ruby_app_without_simplecov.feature index 5424c69..d556b2e 100644 --- a/features/ruby_app_without_simplecov.feature +++ b/features/ruby_app_without_simplecov.feature @@ -1,4 +1,4 @@ -@ruby_app @no_simplecov @disable-bundler +@ruby-app @no-simplecov @disable-bundler Feature: Ruby App without SimpleCov Adding rspec-tracer without simplecov should generate tracer reports and the @@ -51,7 +51,7 @@ Feature: Ruby App without SimpleCov And The dependency report should have correct details And The reverse dependency report should have correct details And The JSON coverage report should have been generated for "RSpecTracer" - And the output should contain "32 / 41 LOC (78.05%) covered" + And The coverage percent stat is "32 / 41 LOC (78.05%) covered" And The JSON coverage report should have correct coverage for "RSpecTracer" When I run `bundle exec rspec spec` Then The RSpecTracer should print the information @@ -88,7 +88,7 @@ Feature: Ruby App without SimpleCov And The dependency report should have correct details And The reverse dependency report should have correct details And The JSON coverage report should have been generated for "RSpecTracer" - And the output should contain "32 / 41 LOC (78.05%) covered" + And The coverage percent stat is "32 / 41 LOC (78.05%) covered" And The JSON coverage report should have correct coverage for "RSpecTracer" Given I replace spec helper with "without_simplecov_updated.rb" When I run `bundle exec rspec spec` @@ -134,7 +134,7 @@ Feature: Ruby App without SimpleCov And The dependency report should have correct details And The reverse dependency report should have correct details And The JSON coverage report should have been generated for "RSpecTracer" - And the output should contain "32 / 41 LOC (78.05%) covered" + And The coverage percent stat is "32 / 41 LOC (78.05%) covered" And The JSON coverage report should have correct coverage for "RSpecTracer" When I run `bundle exec rspec spec` Then The RSpecTracer should print the information @@ -171,7 +171,7 @@ Feature: Ruby App without SimpleCov And The dependency report should have correct details And The reverse dependency report should have correct details And The JSON coverage report should have been generated for "RSpecTracer" - And the output should contain "32 / 41 LOC (78.05%) covered" + And The coverage percent stat is "32 / 41 LOC (78.05%) covered" And The JSON coverage report should have correct coverage for "RSpecTracer" When I run `bundle exec rspec spec/course_spec.rb` Then The RSpecTracer should print the information @@ -207,7 +207,7 @@ Feature: Ruby App without SimpleCov And The dependency report should have correct details And The reverse dependency report should have correct details And The JSON coverage report should have been generated for "RSpecTracer" - And the output should contain "27 / 41 LOC (65.85%) covered" + And The coverage percent stat is "27 / 41 LOC (65.85%) covered" When I run `bundle exec rspec spec/student_spec.rb` Then The RSpecTracer should print the information """ @@ -242,7 +242,7 @@ Feature: Ruby App without SimpleCov And The dependency report should have correct details And The reverse dependency report should have correct details And The JSON coverage report should have been generated for "RSpecTracer" - And the output should contain "25 / 41 LOC (60.98%) covered" + And The coverage percent stat is "25 / 41 LOC (60.98%) covered" When I run `bundle exec rspec spec` Then The RSpecTracer should print the information """ @@ -278,5 +278,5 @@ Feature: Ruby App without SimpleCov And The dependency report should have correct details And The reverse dependency report should have correct details And The JSON coverage report should have been generated for "RSpecTracer" - And the output should contain "32 / 41 LOC (78.05%) covered" + And The coverage percent stat is "32 / 41 LOC (78.05%) covered" And The JSON coverage report should have correct coverage for "RSpecTracer" diff --git a/features/step_definitions/coverage_steps.rb b/features/step_definitions/coverage_steps.rb index b3ea778..cf8e3c7 100644 --- a/features/step_definitions/coverage_steps.rb +++ b/features/step_definitions/coverage_steps.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true Then('The JSON coverage report should have been generated for {string}') do |type| + next if ENV.fetch('SKIP_COVERAGE_VALIDATION', 'false') == 'true' + steps %( Then the output should contain "Coverage report generated for #{type}" ) @@ -23,6 +25,8 @@ # rubocop:disable Metrics/BlockLength Then('The JSON coverage report should have correct coverage for {string}') do |type| + next if ENV.fetch('SKIP_COVERAGE_VALIDATION', 'false') == 'true' + project_dir = File.dirname(__FILE__) data_file = File.join(project_dir, "../#{@data_dir}/coverage.json") data = JSON.parse(File.read(data_file)) @@ -65,3 +69,9 @@ end end # rubocop:enable Metrics/BlockLength + +Then('The coverage percent stat is {string}') do |coverage_stat| + next if ENV.fetch('SKIP_COVERAGE_VALIDATION', 'false') == 'true' + + expect(last_command_started.output).to include(coverage_stat) +end diff --git a/features/step_definitions/project_steps.rb b/features/step_definitions/project_steps.rb index 8236004..6999297 100644 --- a/features/step_definitions/project_steps.rb +++ b/features/step_definitions/project_steps.rb @@ -128,7 +128,7 @@ When I successfully run `bundle install --jobs 3 --retry 3` for up to 120 seconds Then I validate simplecov version And I validate rspec or rspec rails version - When I run `bundle exec #{command}` + And I run `bundle exec #{command}` ) end @@ -137,7 +137,7 @@ expected = Gem::Dependency.new('simplecov', ENV['SIMPLECOV_VERSION']) actual = Gem::Dependency.new( 'simplecov', - `bundle show simplecov`.chomp.split('/').last.split('-').last + `bundle show simplecov`.chomp.split("\n").first.split('/').last.split('-').last ) expect(expected =~ actual).to eq(true) @@ -157,7 +157,7 @@ actual = Gem::Dependency.new( rspec_gem, - `bundle show #{rspec_gem}`.chomp.split('/').last.split('-').last + `bundle show #{rspec_gem}`.chomp.split("\n").first.split('/').last.split('-').last ) expect(expected =~ actual).to eq(true) diff --git a/features/support/env.rb b/features/support/env.rb index c080680..bf55498 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -3,9 +3,31 @@ require 'bundler' Bundler.setup +require 'simplecov' +require 'simplecov_json_formatter' + +SimpleCov.formatters = [ + SimpleCov::Formatter::HTMLFormatter, + SimpleCov::Formatter::JSONFormatter +].freeze + +SimpleCov.start do + enable_coverage :branch if ENV.fetch('BRANCH_COVERAGE', 'false') == 'true' + + add_filter %w[/features/ /spec/ /tmp/] +end + require 'aruba/cucumber' require 'pry' -Before('@branch_coverage') do +Before do + if ENV.fetch('SKIP_COVERAGE_VALIDATION', 'false') == 'true' + setup_file = File.join(File.expand_path('../..', __dir__), 'support', 'coverage_setup') + + set_environment_variable('RUBYOPT', "-r#{setup_file} #{ENV['RUBYOPT']}") + end +end + +Before('@branch-coverage') do skip_this_scenario unless ENV.fetch('BRANCH_COVERAGE', 'false') == 'true' end diff --git a/sample_projects/rails_app/config/application.rb b/sample_projects/rails_app/config/application.rb index 0983acb..d83fcca 100644 --- a/sample_projects/rails_app/config/application.rb +++ b/sample_projects/rails_app/config/application.rb @@ -22,7 +22,7 @@ module RailsApp class Application < Rails::Application # Initialize configuration defaults for originally generated Rails version. - config.load_defaults `bundle show rails`.chomp.split('/').last.split('-').last.split('.').first(2).join('.').to_f + config.load_defaults ENV['RAILS_VERSION'].sub(/[^\d]*/, '').split('.').first(2).join('.').to_f # Configuration for the application, engines, and railties goes here. # diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 4a196f7..a4c79c0 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,13 +1,19 @@ # frozen_string_literal: true require 'simplecov' +require 'simplecov_json_formatter' + +SimpleCov.formatters = [ + SimpleCov::Formatter::HTMLFormatter, + SimpleCov::Formatter::JSONFormatter +].freeze + SimpleCov.start do - add_filter '/spec/' - add_filter '/vendor/bundle/' track_files 'lib/**/*.rb' end require 'rspec_tracer' + RSpecTracer.start RSpec.configure do |config| diff --git a/support/coverage_setup.rb b/support/coverage_setup.rb new file mode 100644 index 0000000..274143f --- /dev/null +++ b/support/coverage_setup.rb @@ -0,0 +1,54 @@ +# frozen_string_literal: true + +def setup_simplecov + return unless ENV.fetch('SKIP_COVERAGE_VALIDATION', 'false') == 'true' + + require 'simplecov' + + SimpleCov.command_name "#{ENV['SIMPLECOV_COMMAND_NAME']}:#{Process.pid}" + SimpleCov.root File.expand_path('..', __dir__) + + SimpleCov.start do + enable_coverage :branch if ENV.fetch('BRANCH_COVERAGE', 'false') == 'true' + + add_filter %w[/features/ /spec/ /tmp/] + end +end + +def setup_rspec_tracer + return unless ENV.fetch('SKIP_COVERAGE_VALIDATION', 'false') == 'true' + + require File.join(File.expand_path('..', __dir__), 'lib', 'rspec_tracer') + + RSpecTracer.configure do + add_filter %w[ + /.rubies/ruby-head/ /.rvm/gems/ /.rvm/rubies/ /bundler/gems/ + /opt/hostedtoolcache/ /rspec-tracer/ /ruby/gems/ /vendor/bundle/ + ] + + add_coverage_filter %w[ + /.rubies/ruby-head/ /.rvm/gems/ /.rvm/rubies/ /bundler/gems/ /autotest/ + /features/ /opt/hostedtoolcache/ /ruby/gems/ /spec/ /test/ /vendor/bundle/ + ] + end +end + +if ENV.fetch('SKIP_COVERAGE_VALIDATION', 'false') == 'true' && File.file?('Gemfile.lock') + setup_simplecov + setup_rspec_tracer + + module RSpecTracerCoverageReporter + def peek_coverage + data = ::Coverage.peek_result + + return data if data.first.last.is_a?(Array) + + data.transform_values { |stats| stats[:lines] } + end + end + + main_clazz = RSpecTracer::CoverageReporter + clazz = RSpecTracerCoverageReporter + + main_clazz.prepend(clazz) unless main_clazz.ancestors.include?(clazz) +end diff --git a/tasks/features/coverage/rspec_tracer.rake b/tasks/features/coverage/rspec_tracer.rake new file mode 100644 index 0000000..21075e9 --- /dev/null +++ b/tasks/features/coverage/rspec_tracer.rake @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +namespace :features do + namespace :coverage do + namespace :rspec_tracer do + desc 'Run ruby app feature specs for rspec tracer line coverage scenario to measure coverage' + task :measure_line_coverage do + puts "\nRunning features:coverage:rspec_tracer:measure_line_coverage\n" + + command = <<-COMMAND.strip.gsub(/\s+/, ' ') + SKIP_COVERAGE_VALIDATION="true" + SIMPLECOV_COMMAND_NAME="features:coverage:rspec_tracer" + RSPEC_VERSION="~> 3.10" + SIMPLECOV_VERSION="~> 0.21" + bundle exec cucumber --tags "@ruby-app and @no-simplecov" + COMMAND + + exit(1) unless system(command) + end + end + end +end diff --git a/tasks/features/coverage/simplecov.rake b/tasks/features/coverage/simplecov.rake new file mode 100644 index 0000000..56d7513 --- /dev/null +++ b/tasks/features/coverage/simplecov.rake @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +namespace :features do + namespace :coverage do + namespace :simplecov do + desc 'Run ruby app feature specs for simplecov branch coverage scenario to measure coverage' + task :measure_branch_coverage do + puts "\nRunning features:coverage:simplecov:measure_branch_coverage\n" + + command = <<-COMMAND.strip.gsub(/\s+/, ' ') + SKIP_COVERAGE_VALIDATION="true" + SIMPLECOV_COMMAND_NAME="features:coverage:simplecov:branch_coverage" + RSPEC_VERSION="~> 3.10" + SIMPLECOV_VERSION="~> 0.21" + BRANCH_COVERAGE="true" + bundle exec cucumber --tags "@ruby-app and @simplecov and @branch-coverage" + COMMAND + + exit(1) unless system(command) + end + + desc 'Run ruby app feature specs for simplecov line coverage scenario to measure coverage' + task :measure_line_coverage do + puts "\nRunning features:coverage:simplecov:measure_line_coverage\n" + + command = <<-COMMAND.strip.gsub(/\s+/, ' ') + SKIP_COVERAGE_VALIDATION="true" + SIMPLECOV_COMMAND_NAME="features:coverage:simplecov:line_coverage" + RSPEC_VERSION="~> 3.10" + SIMPLECOV_VERSION="~> 0.21" + BRANCH_COVERAGE="false" + bundle exec cucumber --tags "@ruby-app and @simplecov and not @branch-coverage" + COMMAND + + exit(1) unless system(command) + end + end + end +end diff --git a/tasks/features/validation/rspec_tracer.rake b/tasks/features/validation/rspec_tracer.rake new file mode 100644 index 0000000..b22ed52 --- /dev/null +++ b/tasks/features/validation/rspec_tracer.rake @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +namespace :features do + namespace :validation do + namespace :rspec_tracer do + desc 'Run ruby app feature specs for rspec tracer line coverage scenario to validate' + task :validate_line_coverage do + puts "\nRunning features:validation:rspec_tracer:validate_line_coverage\n" + + command = <<-COMMAND.strip.gsub(/\s+/, ' ') + SKIP_COVERAGE_VALIDATION="false" + RSPEC_VERSION="~> 3.10" + SIMPLECOV_VERSION="~> 0.21" + bundle exec cucumber --tags "@ruby-app and @no-simplecov" + COMMAND + + exit(1) unless system(command) + end + end + end +end diff --git a/tasks/features/validation/simplecov.rake b/tasks/features/validation/simplecov.rake new file mode 100644 index 0000000..8d3be56 --- /dev/null +++ b/tasks/features/validation/simplecov.rake @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +namespace :features do + namespace :validation do + namespace :simplecov do + desc 'Run ruby app feature specs for simplecov branch coverage scenario to validate' + task :validate_branch_coverage do + puts "\nRunning features:validation:simplecov:validate_branch_coverage\n" + + command = <<-COMMAND.strip.gsub(/\s+/, ' ') + SKIP_COVERAGE_VALIDATION="false" + RSPEC_VERSION="~> 3.10" + SIMPLECOV_VERSION="~> 0.21" + BRANCH_COVERAGE="true" + bundle exec cucumber --tags "@ruby-app and @simplecov and @branch-coverage" + COMMAND + + exit(1) unless system(command) + end + + desc 'Run ruby app feature specs for simplecov line coverage scenario to validate' + task :validate_line_coverage do + puts "\nRunning features:validation:simplecov:validate_line_coverage\n" + + command = <<-COMMAND.strip.gsub(/\s+/, ' ') + SKIP_COVERAGE_VALIDATION="false" + RSPEC_VERSION="~> 3.10" + SIMPLECOV_VERSION="~> 0.21" + BRANCH_COVERAGE="false" + bundle exec cucumber --tags "@ruby-app and @simplecov and not @branch-coverage" + COMMAND + + exit(1) unless system(command) + end + end + end +end