diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..a277b1b --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,44 @@ +name: Test + +on: + pull_request: + push: + branches: + - master + - development + +jobs: + build-and-test: + runs-on: ubuntu-latest + + strategy: + matrix: + ruby: [ '2.5', '2.6', '2.7.1' ] + + name: Ruby ${{ matrix.ruby }} + + steps: + - uses: actions/checkout@v2 + + - uses: actions/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + + - name: Cache gems + uses: actions/cache@v1 + with: + path: vendor/bundle + key: bundle-use-ruby-${{ runner.os }}-${{ matrix.ruby }}-${{ hashFiles('**/Gemfile.lock') }} + restore-keys: | + bundle-use-ruby-${{ runner.os }}-${{ matrix.ruby }}- + + - name: Install bundler + run: gem install bundler + + - name: Bundle install + run: | + bundle config path vendor/bundle + bundle install --jobs 4 --retry 3 + + - name: Run specs + run: bundle exec rake spec diff --git a/.rubocop.yml b/.rubocop.yml index a33d523..52e6200 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,151 +1,6 @@ -# Defaults can be found here: https://github.com/bbatsov/rubocop/blob/master/config/default.yml - -# If you don't like these settings, just delete this file :) - AllCops: - TargetRubyVersion: 2.0 - -Style/StringLiterals: - EnforcedStyle: double_quotes - Enabled: true - -# kind_of? is a good way to check a type -Style/ClassCheck: - EnforcedStyle: kind_of? - -# It's better to be more explicit about the type -Style/BracesAroundHashParameters: - Enabled: false - -# specs sometimes have useless assignments, which is fine -Lint/UselessAssignment: - Exclude: - - '**/spec/**/*' - -# We could potentially enable the 2 below: -Layout/IndentHash: - Enabled: false - -Layout/AlignHash: - Enabled: false - -# HoundCI doesn't like this rule -Layout/DotPosition: - Enabled: false - -# We allow !! as it's an easy way to convert ot boolean -Style/DoubleNegation: - Enabled: false - -# Cop supports --auto-correct. -Lint/UnusedBlockArgument: - Enabled: false - -# We want to allow class Fastlane::Class -Style/ClassAndModuleChildren: - Enabled: false - -Metrics/AbcSize: - Max: 60 - -# The %w might be confusing for new users -Style/WordArray: - MinSize: 19 + NewCops: enable # raise and fail are both okay Style/SignalException: Enabled: false - -# Better too much 'return' than one missing -Style/RedundantReturn: - Enabled: false - -# Having if in the same line might not always be good -Style/IfUnlessModifier: - Enabled: false - -# and and or is okay -Style/AndOr: - Enabled: false - -# Configuration parameters: CountComments. -Metrics/ClassLength: - Max: 350 - -Metrics/CyclomaticComplexity: - Max: 17 - -# Configuration parameters: AllowURI, URISchemes. -Metrics/LineLength: - Max: 370 - -# Configuration parameters: CountKeywordArgs. -Metrics/ParameterLists: - Max: 10 - -Metrics/PerceivedComplexity: - Max: 18 - -# Sometimes it's easier to read without guards -Style/GuardClause: - Enabled: false - -# something = if something_else -# that's confusing -Style/ConditionalAssignment: - Enabled: false - -# Better to have too much self than missing a self -Style/RedundantSelf: - Enabled: false - -Metrics/MethodLength: - Max: 60 - -# We're not there yet -Style/Documentation: - Enabled: false - -# Adds complexity -Style/IfInsideElse: - Enabled: false - -# danger specific - -Style/BlockComments: - Enabled: false - -Layout/MultilineMethodCallIndentation: - EnforcedStyle: indented - -Metrics/BlockLength: - Max: 345 - Exclude: - - "**/*_spec.rb" - -Style/MixinGrouping: - Enabled: false - -Style/FileName: - Enabled: false - -Layout/IndentHeredoc: - Enabled: false - -Style/SpecialGlobalVars: - Enabled: false - -PercentLiteralDelimiters: - PreferredDelimiters: - "%": () - "%i": () - "%q": () - "%Q": () - "%r": "{}" - "%s": () - "%w": () - "%W": () - "%x": () - -Security/YAMLLoad: - Enabled: false diff --git a/Gemfile b/Gemfile index 07ae8d3..fb72cb6 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + source 'https://rubygems.org' # Specify your gem's dependencies in danger-undercover.gemspec diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..dd26c32 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,146 @@ +PATH + remote: . + specs: + danger-undercover (1.0.0) + danger-plugin-api (~> 1.0) + +GEM + remote: https://rubygems.org/ + specs: + addressable (2.7.0) + public_suffix (>= 2.0.2, < 5.0) + ast (2.4.1) + claide (1.0.3) + claide-plugins (0.9.2) + cork + nap + open4 (~> 1.3) + coderay (1.1.3) + colored2 (3.1.2) + cork (0.3.0) + colored2 (~> 3.1) + danger (8.0.6) + claide (~> 1.0) + claide-plugins (>= 0.9.2) + colored2 (~> 3.1) + cork (~> 0.1) + faraday (>= 0.9.0, < 2.0) + faraday-http-cache (~> 2.0) + git (~> 1.7) + kramdown (~> 2.3) + kramdown-parser-gfm (~> 1.0) + no_proxy_fix + octokit (~> 4.7) + terminal-table (~> 1) + danger-plugin-api (1.0.0) + danger (> 2.0) + diff-lcs (1.4.4) + faraday (1.0.1) + multipart-post (>= 1.2, < 3) + faraday-http-cache (2.2.0) + faraday (>= 0.8) + ffi (1.13.1) + formatador (0.2.5) + git (1.7.0) + rchardet (~> 1.8) + guard (2.16.2) + formatador (>= 0.2.4) + listen (>= 2.7, < 4.0) + lumberjack (>= 1.0.12, < 2.0) + nenv (~> 0.1) + notiffany (~> 0.0) + pry (>= 0.9.12) + shellany (~> 0.0) + thor (>= 0.18.1) + guard-compat (1.2.1) + guard-rspec (4.7.3) + guard (~> 2.1) + guard-compat (~> 1.1) + rspec (>= 2.99.0, < 4.0) + kramdown (2.3.0) + rexml + kramdown-parser-gfm (1.1.0) + kramdown (~> 2.0) + listen (3.2.1) + rb-fsevent (~> 0.10, >= 0.10.3) + rb-inotify (~> 0.9, >= 0.9.10) + lumberjack (1.2.8) + method_source (1.0.0) + multipart-post (2.1.1) + nap (1.1.0) + nenv (0.3.0) + no_proxy_fix (0.1.2) + notiffany (0.1.3) + nenv (~> 0.1) + shellany (~> 0.0) + octokit (4.18.0) + faraday (>= 0.9) + sawyer (~> 0.8.0, >= 0.5.3) + open4 (1.3.4) + parallel (1.19.2) + parser (2.7.2.0) + ast (~> 2.4.1) + pry (0.13.1) + coderay (~> 1.1) + method_source (~> 1.0) + public_suffix (4.0.6) + rainbow (3.0.0) + rake (13.0.1) + rb-fsevent (0.10.4) + rb-inotify (0.10.1) + ffi (~> 1.0) + rchardet (1.8.0) + regexp_parser (1.8.2) + rexml (3.2.4) + rspec (3.9.0) + rspec-core (~> 3.9.0) + rspec-expectations (~> 3.9.0) + rspec-mocks (~> 3.9.0) + rspec-core (3.9.3) + rspec-support (~> 3.9.3) + rspec-expectations (3.9.2) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.9.0) + rspec-mocks (3.9.1) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.9.0) + rspec-support (3.9.3) + rubocop (0.93.1) + parallel (~> 1.10) + parser (>= 2.7.1.5) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 1.8) + rexml + rubocop-ast (>= 0.6.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 1.4.0, < 2.0) + rubocop-ast (0.7.1) + parser (>= 2.7.1.5) + ruby-progressbar (1.10.1) + sawyer (0.8.2) + addressable (>= 2.3.5) + faraday (> 0.8, < 2.0) + shellany (0.0.1) + terminal-table (1.8.0) + unicode-display_width (~> 1.1, >= 1.1.1) + thor (1.0.1) + unicode-display_width (1.7.0) + yard (0.9.25) + +PLATFORMS + ruby + +DEPENDENCIES + bundler + danger-undercover! + guard + guard-rspec + listen + pry + rake + rspec + rubocop + yard + +BUNDLED WITH + 2.1.4 diff --git a/Guardfile b/Guardfile index 95b91ae..8b488d9 100644 --- a/Guardfile +++ b/Guardfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # A guardfile for making Danger Plugins # For more info see https://github.com/guard/guard#readme diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..7a807f4 --- /dev/null +++ b/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2014-2020 Nimble. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/LICENSE.txt b/LICENSE.txt deleted file mode 100644 index a6edce6..0000000 --- a/LICENSE.txt +++ /dev/null @@ -1,22 +0,0 @@ -Copyright (c) 2020 rafayet-monon - -MIT License - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md index d0f5853..319e9aa 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # danger-undercover -A Danger plugin to use with Undercover gem. +A [Danger](https://github.com/danger/danger) plugin to show [Undercover](https://github.com/grodowski/undercover) report. ## Installation @@ -8,8 +8,27 @@ A Danger plugin to use with Undercover gem. ## Usage - Methods and attributes from this plugin are available in - your `Dangerfile` under the `undercover` namespace. +To use this gem all the instruction provided in [Undercover](https://github.com/grodowski/undercover) must be followed. + +To know more about running undercover [visit here](https://github.com/grodowski/undercover#usage) + +> Use the `-c --compare ref` flag to specify a git ref (commit hash, branch name, tag) to compare against. +**This is a recommended usage for CI/CD build environments**, as `undercover` will `exit 1` if there are any warnings. + +Run the below command to output undercover report to a `txt` file which this plugin will use to geneate PR comments. +To use it on a CI server, run this command before running `Danger` so that the file is created beforehand. + + $ undercover -c $compare_git_ref > coverage/undercover.txt + +>Here $compare_git_ref as per undercover documentation, can be a commit hash, branch name, or tag. i.e. origin/master +, origin/development + + +Then in your `Dangerfile` add the following line with the output file + +```ruby +undercover.report 'coverage/undercover.txt' +``` ## Development @@ -18,3 +37,21 @@ A Danger plugin to use with Undercover gem. 3. Run `bundle exec rake spec` to run the tests. 4. Use `bundle exec guard` to automatically have tests run as you make changes. 5. Make your changes. + +## License + +It is free software, and may be redistributed under the terms specified in the [LICENSE] file. + +[LICENSE]: /LICENSE + +## About + +![Nimble](https://assets.nimblehq.co/logo/dark/logo-dark-text-160.png) + +This project is maintained and funded by Nimble. + +We love open source and do our part in sharing our work with the community! +See [our other projects][community] or [hire our team][hire] to help build your product. + +[community]: https://github.com/nimblehq +[hire]: https://nimblehq.co/ diff --git a/Rakefile b/Rakefile index af16989..7346ec6 100644 --- a/Rakefile +++ b/Rakefile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'bundler/gem_tasks' require 'rspec/core/rake_task' require 'rubocop/rake_task' diff --git a/danger-undercover.gemspec b/danger-undercover.gemspec index e42eb45..145065d 100644 --- a/danger-undercover.gemspec +++ b/danger-undercover.gemspec @@ -1,42 +1,44 @@ -# coding: utf-8 -lib = File.expand_path('../lib', __FILE__) +# frozen_string_literal: true + +lib = File.expand_path('lib', __dir__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'undercover/gem_version.rb' Gem::Specification.new do |spec| spec.name = 'danger-undercover' spec.version = Undercover::VERSION - spec.authors = ['rafayet-monon'] - spec.email = ['rafayet.monon@gmail.com'] - spec.description = %q{Show undercover report to PRs} - spec.summary = %q{A Danger plugin for Undercover gem} + spec.authors = %w[Nimble rafayet-monon] + spec.email = %w[dev@nimblehq.co rafayet@nimblehq.co] + spec.description = 'Show undercover report to PRs' + spec.summary = 'A Danger plugin for Undercover gem' spec.homepage = 'https://github.com/nimblehq/danger-undercover' spec.license = 'MIT' - spec.files = `git ls-files`.split($/) - spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } - spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) - spec.require_paths = ['lib'] + spec.required_ruby_version = '~> 2.4' + spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR) + spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } + spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) + spec.require_paths = ['lib'] spec.add_runtime_dependency 'danger-plugin-api', '~> 1.0' # General ruby development - spec.add_development_dependency 'bundler', '~> 1.3' - spec.add_development_dependency 'rake', '~> 10.0' + spec.add_development_dependency 'bundler' + spec.add_development_dependency 'rake' # Testing support - spec.add_development_dependency 'rspec', '~> 3.4' + spec.add_development_dependency 'rspec' # Linting code and docs - spec.add_development_dependency "rubocop" - spec.add_development_dependency "yard" + spec.add_development_dependency 'rubocop' + spec.add_development_dependency 'yard' # Makes testing easy via `bundle exec guard` - spec.add_development_dependency 'guard', '~> 2.14' - spec.add_development_dependency 'guard-rspec', '~> 4.7' + spec.add_development_dependency 'guard' + spec.add_development_dependency 'guard-rspec' # If you want to work on older builds of ruby - spec.add_development_dependency 'listen', '3.0.7' + spec.add_development_dependency 'listen' # This gives you the chance to run a REPL inside your tests # via: diff --git a/lib/danger_plugin.rb b/lib/danger_plugin.rb index 5d1a508..e5f926f 100644 --- a/lib/danger_plugin.rb +++ b/lib/danger_plugin.rb @@ -1 +1,3 @@ -require "undercover/plugin" +# frozen_string_literal: true + +require 'undercover/plugin' diff --git a/lib/danger_undercover.rb b/lib/danger_undercover.rb index 00a0a5d..4ad3af6 100644 --- a/lib/danger_undercover.rb +++ b/lib/danger_undercover.rb @@ -1 +1,3 @@ -require "undercover/gem_version" +# frozen_string_literal: true + +require 'undercover/gem_version' diff --git a/lib/undercover/gem_version.rb b/lib/undercover/gem_version.rb index 7b07c11..de3d654 100644 --- a/lib/undercover/gem_version.rb +++ b/lib/undercover/gem_version.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Undercover - VERSION = "0.0.1".freeze + VERSION = '1.0.0' end diff --git a/lib/undercover/plugin.rb b/lib/undercover/plugin.rb index 7ce9b51..436c64b 100644 --- a/lib/undercover/plugin.rb +++ b/lib/undercover/plugin.rb @@ -1,33 +1,47 @@ +# frozen_string_literal: true + module Danger - # This is your plugin class. Any attributes or methods you expose here will - # be available from within your Dangerfile. - # - # To be published on the Danger plugins site, you will need to have - # the public interface documented. Danger uses [YARD](http://yardoc.org/) - # for generating documentation from your plugin source, and you can verify - # by running `danger plugins lint` or `bundle exec rake spec`. + # Report missing coverage report using undercover and danger-undercover # - # You should replace these comments with a public description of your library. + # You have to use [undercover](https://github.com/grodowski/undercover) to gather + # undercover report and send the report to this plugin so that danger-undercover + # can use it. # - # @example Ensure people are well warned about merging on Mondays + # @example Report missing coverage report # - # my_plugin.warn_on_mondays + # undercover.report('coverage/undercover.txt') # - # @see rafayet-monon/danger-undercover - # @tags monday, weekends, time, rattata + # @see nimblehq/danger-undercover + # @tags ruby, code-coverage, simplecov, undercover, danger, simplecov-lcov # class DangerUndercover < Plugin + VALID_FILE_FORMAT = '.txt' - # An attribute that you can read/write from your Dangerfile + # Checks the file validity and warns if no file is found + # if a valid file is found then if there are no changes, + # shows the report as a message in Danger. + # If there are reports then it shows the report as a warning in danger. + # @return [void] # - # @return [Array] - attr_accessor :my_attribute + def report(undercover_path, sticky: true) + return fail('Undercover: coverage report cannot be found.') unless valid_file? undercover_path + + report = File.open(undercover_path).read + + if report.match(/No coverage is missing in latest changes/) + message(report, sticky: sticky) + else + warn(report, sticky: sticky) + end + end + + private - # A method that you can call from your Dangerfile - # @return [Array] + # Checks if the file exists and the file is valid + # @return [Boolean] File validity # - def warn_on_mondays - warn 'Trying to merge code on a Monday' if Date.today.wday == 1 + def valid_file?(undercover_path) + File.exist?(undercover_path) && (File.extname(undercover_path) == VALID_FILE_FORMAT) end end end diff --git a/spec/fixtures/undercover_failed.txt b/spec/fixtures/undercover_failed.txt new file mode 100644 index 0000000..517b7cc --- /dev/null +++ b/spec/fixtures/undercover_failed.txt @@ -0,0 +1,17 @@ +undercover: 👮‍♂️ some methods have no test coverage! Please add specs for methods listed below +🚨 1) node `index3` type: instance method, + loc: app/controllers/v2/provinces_controller.rb:9:11, coverage: 0.0% + 9: def index3 hits: n/a +10: render json: V2::ProvinceSerializer.new(provinces) hits: 0 +11: end hits: n/a +🚨 2) node `index2` type: instance method, + loc: app/controllers/v2/sub_districts_controller.rb:9:11, coverage: 0.0% + 9: def index2 hits: n/a +10: render json: V2::SubDistrictSerializer.new(sub_districts) hits: 0 +11: end hits: n/a +🚨 3) node `index3` type: instance method, + loc: app/controllers/v2/sub_districts_controller.rb:13:15, coverage: 0.0% +13: def index3 hits: n/a +14: render json: V2::SubDistrictSerializer.new(sub_districts) hits: 0 +15: end hits: n/a +Undercover finished in 0.9006s diff --git a/spec/fixtures/undercover_passed.txt b/spec/fixtures/undercover_passed.txt new file mode 100644 index 0000000..4da4c9c --- /dev/null +++ b/spec/fixtures/undercover_passed.txt @@ -0,0 +1,2 @@ +undercover: ✅ No coverage is missing in latest changes +Undercover finished in 0.9931s diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 0a50001..232e1cf 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,28 +1,30 @@ -require "pathname" -ROOT = Pathname.new(File.expand_path("../../", __FILE__)) -$:.unshift((ROOT + "lib").to_s) -$:.unshift((ROOT + "spec").to_s) +# frozen_string_literal: true -require "bundler/setup" -require "pry" +require 'pathname' +ROOT = Pathname.new(File.expand_path('..', __dir__)) +$LOAD_PATH.unshift("#{ROOT}lib") +$LOAD_PATH.unshift("#{ROOT}spec") -require "rspec" -require "danger" +require 'bundler/setup' +require 'pry' + +require 'rspec' +require 'danger' if `git remote -v` == '' - puts "You cannot run tests without setting a local git remote on this repo" + puts 'You cannot run tests without setting a local git remote on this repo' puts "It's a weird side-effect of Danger's internals." exit(0) end # Use coloured output, it's the best. RSpec.configure do |config| - config.filter_gems_from_backtrace "bundler" + config.filter_gems_from_backtrace 'bundler' config.color = true config.tty = true end -require "danger_plugin" +require 'danger_plugin' # These functions are a subset of https://github.com/danger/danger/blob/master/spec/spec_helper.rb # If you are expanding these files, see if it's already been done ^. @@ -40,21 +42,20 @@ def @output.winsize cork = Cork::Board.new(out: @output) def cork.string - out.string.gsub(/\e\[([;\d]+)?m/, "") + out.string.gsub(/\e\[([;\d]+)?m/, '') end cork end # rubocop:enable Lint/NestedMethodDefinition -# Example environment (ENV) that would come from -# running a PR on TravisCI +# Example environment (ENV) that would come from running a PR def testing_env { - "HAS_JOSH_K_SEAL_OF_APPROVAL" => "true", - "TRAVIS_PULL_REQUEST" => "800", - "TRAVIS_REPO_SLUG" => "artsy/eigen", - "TRAVIS_COMMIT_RANGE" => "759adcbd0d8f...13c4dc8bb61d", - "DANGER_GITHUB_API_TOKEN" => "123sbdq54erfsd3422gdfio" + 'HAS_JOSH_K_SEAL_OF_APPROVAL' => 'true', + 'PULL_REQUEST' => '800', + 'REPO_SLUG' => 'artsy/eigen', + 'COMMIT_RANGE' => '759adcbd0d8f...13c4dc8bb61d', + 'DANGER_GITHUB_API_TOKEN' => '123sbdq54erfsd3422gdfio' } end diff --git a/spec/undercover_spec.rb b/spec/undercover_spec.rb index 6d2ba2e..738537e 100644 --- a/spec/undercover_spec.rb +++ b/spec/undercover_spec.rb @@ -1,46 +1,40 @@ -require File.expand_path("../spec_helper", __FILE__) +# frozen_string_literal: true + +require File.expand_path('spec_helper', __dir__) module Danger describe Danger::DangerUndercover do - it "should be a plugin" do + it 'is a Danger plugin' do expect(Danger::DangerUndercover.new(nil)).to be_a Danger::Plugin end - # - # You should test your custom attributes and methods here - # - describe "with Dangerfile" do + describe 'Dangerfile' do before do @dangerfile = testing_dangerfile - @my_plugin = @dangerfile.undercover - - # mock the PR data - # you can then use this, eg. github.pr_author, later in the spec - json = File.read(File.dirname(__FILE__) + '/support/fixtures/github_pr.json') # example json: `curl https://api.github.com/repos/danger/danger-plugin-template/pulls/18 > github_pr.json` - allow(@my_plugin.github).to receive(:pr_json).and_return(json) + @undercover = @dangerfile.undercover end - # Some examples for writing tests - # You should replace these with your own. + it 'fails if file is not found' do + @undercover.report('spec/fixtures/missing_file.txt') - it "Warns on a monday" do - monday_date = Date.parse("2016-07-11") - allow(Date).to receive(:today).and_return monday_date + expect(@dangerfile.status_report[:errors]).to eq(['Undercover: coverage report cannot be found.']) + end - @my_plugin.warn_on_mondays + it 'shows success message if nothing to report' do + report_path = 'spec/fixtures/undercover_passed.txt' + @undercover.report(report_path) + report = File.open(report_path).read - expect(@dangerfile.status_report[:warnings]).to eq(["Trying to merge code on a Monday"]) + expect(@dangerfile.status_report[:messages]).to eq([report]) end - it "Does nothing on a tuesday" do - monday_date = Date.parse("2016-07-12") - allow(Date).to receive(:today).and_return monday_date + it 'shows warnings if undercover has a report' do + report_path = 'spec/fixtures/undercover_failed.txt' + @undercover.report(report_path) + report = File.open(report_path).read - @my_plugin.warn_on_mondays - - expect(@dangerfile.status_report[:warnings]).to eq([]) + expect(@dangerfile.status_report[:warnings]).to eq([report]) end - end end end