From 691dbe08421f62a0c062ead57bf36692fbca91a0 Mon Sep 17 00:00:00 2001 From: "Daniel (dB.) Doubrovkine" Date: Fri, 2 Jan 2026 14:55:45 -0500 Subject: [PATCH] Migrate to danger-pr-comment workflow. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 --- .github/workflows/ci.yml | 28 ++++ .github/workflows/danger-comment.yml | 11 ++ .github/workflows/danger.yml | 13 ++ .github/workflows/rubocop.yml | 20 +++ .rubocop.yml | 11 +- .rubocop_todo.yml | 152 +++++++++++++----- .travis.yml | 14 -- CHANGELOG.md | 3 + Dangerfile | 4 +- Gemfile | 16 +- README.md | 2 +- danger-toc.gemspec | 6 +- lib/toc/config.rb | 2 +- lib/toc/constructors/kramdown_constructor.rb | 2 +- lib/toc/markdown_file.rb | 23 ++- lib/toc/plugin.rb | 12 +- spec/config_spec.rb | 5 +- spec/constructors_spec.rb | 6 +- spec/markdown_file/danger_toc_readme_spec.rb | 6 +- spec/markdown_file/one_section_spec.rb | 11 +- .../one_section_with_toc_level_spec.rb | 9 +- .../one_section_with_toc_spec.rb | 9 +- .../markdown_file/with_quoted_example_spec.rb | 9 +- .../with_underscore_in_section_name_spec.rb | 13 +- spec/toc_spec.rb | 37 +++-- 25 files changed, 302 insertions(+), 122 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/danger-comment.yml create mode 100644 .github/workflows/danger.yml create mode 100644 .github/workflows/rubocop.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..ce98e6b --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,28 @@ +name: CI + +on: + push: + branches: + - master + pull_request: + +jobs: + test: + runs-on: ubuntu-latest + strategy: + matrix: + ruby-version: + - '2.7' + - '3.0' + - '3.1' + - '3.2' + - '3.3' + steps: + - uses: actions/checkout@v4 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby-version }} + bundler-cache: true + - name: Run tests + run: bundle exec rake spec diff --git a/.github/workflows/danger-comment.yml b/.github/workflows/danger-comment.yml new file mode 100644 index 0000000..8e15cb6 --- /dev/null +++ b/.github/workflows/danger-comment.yml @@ -0,0 +1,11 @@ +name: Danger Comment + +on: + workflow_run: + workflows: [Danger] + types: [completed] + +jobs: + comment: + uses: numbata/danger-pr-comment/.github/workflows/danger-comment.yml@v0.1.0 + secrets: inherit diff --git a/.github/workflows/danger.yml b/.github/workflows/danger.yml new file mode 100644 index 0000000..bd89a88 --- /dev/null +++ b/.github/workflows/danger.yml @@ -0,0 +1,13 @@ +name: Danger + +on: + pull_request: + types: [opened, reopened, edited, synchronize] + +jobs: + danger: + uses: numbata/danger-pr-comment/.github/workflows/danger-run.yml@v0.1.0 + secrets: inherit + with: + ruby-version: '3.4' + bundler-cache: true diff --git a/.github/workflows/rubocop.yml b/.github/workflows/rubocop.yml new file mode 100644 index 0000000..9241817 --- /dev/null +++ b/.github/workflows/rubocop.yml @@ -0,0 +1,20 @@ +name: Rubocop + +on: + push: + branches: + - master + pull_request: + +jobs: + rubocop: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: '3.3' + bundler-cache: true + - name: Run rubocop + run: bundle exec rubocop diff --git a/.rubocop.yml b/.rubocop.yml index c34218a..6235237 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,12 +1,13 @@ AllCops: + NewCops: enable Exclude: - vendor/**/* Metrics/BlockLength: - Enabled: fale + Enabled: false -Metrics/LineLength: - Enabled: fale +Layout/LineLength: + Enabled: false Style/ModuleFunction: Enabled: false @@ -15,3 +16,7 @@ Style/FrozenStringLiteralComment: Enabled: false inherit_from: .rubocop_todo.yml + +plugins: + - rubocop-rspec + - rubocop-rake \ No newline at end of file diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index df41c5a..e1d3826 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,56 +1,133 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2019-07-28 16:56:29 -0400 using RuboCop version 0.73.0. +# on 2026-01-02 20:08:28 UTC using RuboCop version 1.82.0. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 3 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: squiggly, active_support, powerpack, unindent -Layout/IndentHeredoc: +# Offense count: 1 +Gemspec/RequiredRubyVersion: Exclude: - - 'lib/toc/plugin.rb' - - 'spec/toc_spec.rb' + - 'danger-toc.gemspec' -# Offense count: 4 +# Offense count: 2 +# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes. Metrics/AbcSize: - Max: 19 - -# Offense count: 8 -# Configuration parameters: CountComments, ExcludedMethods. -# ExcludedMethods: refine -Metrics/BlockLength: - Max: 107 + Max: 20 # Offense count: 3 -# Configuration parameters: CountComments, ExcludedMethods. +# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns. Metrics/MethodLength: - Max: 21 + Max: 20 + +# Offense count: 3 +# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames. +# AllowedNames: as, at, by, cc, db, id, if, in, io, ip, of, on, os, pp, to +Naming/MethodParameterName: + Exclude: + - 'lib/toc/constructors/kramdown_constructor.rb' + - 'lib/toc/extractor.rb' + +# Offense count: 1 +# Configuration parameters: Mode, AllowedMethods, AllowedPatterns, AllowBangMethods, WaywardPredicates. +# AllowedMethods: call +# WaywardPredicates: nonzero? +Naming/PredicateMethod: + Exclude: + - 'lib/toc/plugin.rb' # Offense count: 2 -# Configuration parameters: NamePrefix, NamePrefixBlacklist, NameWhitelist, MethodDefinitionMacros. -# NamePrefix: is_, has_, have_ -# NamePrefixBlacklist: is_, has_, have_ -# NameWhitelist: is_a? +# Configuration parameters: NamePrefix, ForbiddenPrefixes, AllowedMethods, MethodDefinitionMacros, UseSorbetSigs. +# NamePrefix: is_, has_, have_, does_ +# ForbiddenPrefixes: is_, has_, have_, does_ +# AllowedMethods: is_a? # MethodDefinitionMacros: define_method, define_singleton_method -Naming/PredicateName: +Naming/PredicatePrefix: Exclude: - 'spec/**/*' - 'lib/toc/markdown_file.rb' - 'lib/toc/plugin.rb' +# Offense count: 8 +# Configuration parameters: Prefixes, AllowedPatterns. +# Prefixes: when, with, without +RSpec/ContextWording: + Exclude: + - 'spec/config_spec.rb' + - 'spec/toc_spec.rb' + +# Offense count: 7 +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: SkipBlocks, EnforcedStyle, OnlyStaticConstants. +# SupportedStyles: described_class, explicit +RSpec/DescribedClass: + Exclude: + - 'spec/markdown_file/danger_toc_readme_spec.rb' + - 'spec/markdown_file/one_section_spec.rb' + - 'spec/markdown_file/one_section_with_toc_level_spec.rb' + - 'spec/markdown_file/one_section_with_toc_spec.rb' + - 'spec/markdown_file/with_quoted_example_spec.rb' + - 'spec/markdown_file/with_underscore_in_section_name_spec.rb' + - 'spec/toc_spec.rb' + # Offense count: 3 -# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames. -# AllowedNames: io, id, to, by, on, in, at, ip, db -Naming/UncommunicativeMethodParamName: +# Configuration parameters: CountAsOne. +RSpec/ExampleLength: + Max: 10 + +# Offense count: 6 +RSpec/MultipleExpectations: + Max: 4 + +# Offense count: 39 +# Configuration parameters: EnforcedStyle, IgnoreSharedExamples. +# SupportedStyles: always, named_only +RSpec/NamedSubject: Exclude: - - 'lib/toc/constructors/kramdown_constructor.rb' - - 'lib/toc/extractor.rb' + - 'spec/markdown_file/danger_toc_readme_spec.rb' + - 'spec/markdown_file/one_section_spec.rb' + - 'spec/markdown_file/one_section_with_toc_level_spec.rb' + - 'spec/markdown_file/one_section_with_toc_spec.rb' + - 'spec/markdown_file/with_quoted_example_spec.rb' + - 'spec/markdown_file/with_underscore_in_section_name_spec.rb' + - 'spec/toc_spec.rb' + +# Offense count: 13 +# Configuration parameters: AllowedGroups. +RSpec/NestedGroups: + Max: 5 + +# Offense count: 8 +# This cop supports unsafe autocorrection (--autocorrect-all). +RSpec/ReceiveMessages: + Exclude: + - 'spec/toc_spec.rb' + +# Offense count: 9 +# Configuration parameters: CustomTransform, IgnoreMethods, IgnoreMetadata, InflectorPath, EnforcedInflector. +# SupportedInflectors: default, active_support +RSpec/SpecFilePathFormat: + Exclude: + - '**/spec/routing/**/*' + - 'spec/config_spec.rb' + - 'spec/constructors_spec.rb' + - 'spec/markdown_file/danger_toc_readme_spec.rb' + - 'spec/markdown_file/one_section_spec.rb' + - 'spec/markdown_file/one_section_with_toc_level_spec.rb' + - 'spec/markdown_file/one_section_with_toc_spec.rb' + - 'spec/markdown_file/with_quoted_example_spec.rb' + - 'spec/markdown_file/with_underscore_in_section_name_spec.rb' + - 'spec/toc_spec.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +Rake/Desc: + Exclude: + - 'Rakefile' # Offense count: 8 +# Configuration parameters: AllowedConstants. Style/Documentation: Exclude: - 'spec/**/*' @@ -63,20 +140,9 @@ Style/Documentation: - 'lib/toc/markdown_file.rb' - 'lib/toc/plugin.rb' -# Offense count: 3 -Style/DoubleNegation: - Exclude: - - 'lib/toc/markdown_file.rb' - # Offense count: 2 -# Configuration parameters: MinBodyLength. -Style/GuardClause: +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: Mode. +Style/StringConcatenation: Exclude: - - 'lib/toc/markdown_file.rb' - -# Offense count: 26 -# Cop supports --auto-correct. -# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. -# URISchemes: http, https -Metrics/LineLength: - Max: 123 + - 'spec/spec_helper.rb' diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 48d47fc..0000000 --- a/.travis.yml +++ /dev/null @@ -1,14 +0,0 @@ -language: ruby - -cache: - directories: - - bundle - -rvm: - - 2.6.2 - -before_script: - - bundle exec danger - -script: - - bundle exec rake spec diff --git a/CHANGELOG.md b/CHANGELOG.md index 22c0b68..2b9f310 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ### 0.2.1 (Next) +* [#18](https://github.com/dblock/danger-toc/pull/18): Migrate to danger-pr-comment workflow - [@dblock](https://github.com/dblock). +* [#18](https://github.com/dblock/danger-toc/pull/18): Migrate from Travis CI to GitHub Actions - [@dblock](https://github.com/dblock). +* [#18](https://github.com/dblock/danger-toc/pull/18): Upgrade rubocop to 1.82.0 - [@dblock](https://github.com/dblock). * Your contribution here. ### 0.2.0 (2019/07/28) diff --git a/Dangerfile b/Dangerfile index 3c2985e..b4bc366 100644 --- a/Dangerfile +++ b/Dangerfile @@ -1,4 +1,6 @@ -# danger.systems +# frozen_string_literal: true + +danger.import_dangerfile(gem: 'danger-pr-comment') changelog.check! toc.check! diff --git a/Gemfile b/Gemfile index c12214a..0005e21 100644 --- a/Gemfile +++ b/Gemfile @@ -4,13 +4,17 @@ gemspec group :development, :test do gem 'bundler' - gem 'danger-changelog', '~> 0.6.0' - gem 'guard', '~> 2.14' - gem 'guard-rspec', '~> 4.7' + gem 'danger' + gem 'danger-changelog' + gem 'danger-pr-comment' + gem 'guard' + gem 'guard-rspec' gem 'listen' gem 'pry' - gem 'rake', '~> 10.0' - gem 'rspec', '~> 3.4' - gem 'rubocop', '0.73.0' + gem 'rake' + gem 'rspec' + gem 'rubocop', '1.82.0' + gem 'rubocop-rake' + gem 'rubocop-rspec' gem 'yard' end diff --git a/README.md b/README.md index d95fc9e..e1b2c22 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ A plugin for [danger.systems](http://danger.systems) that makes sure your project’s `README.md` has a TOC. [![Gem Version](https://badge.fury.io/rb/danger-toc.svg)](https://badge.fury.io/rb/danger-toc) -[![Build Status](https://travis-ci.org/dblock/danger-toc.svg?branch=master)](https://travis-ci.org/dblock/danger-toc) +[![CI](https://github.com/dblock/danger-toc/actions/workflows/ci.yml/badge.svg)](https://github.com/dblock/danger-toc/actions/workflows/ci.yml) ## Table of Contents diff --git a/danger-toc.gemspec b/danger-toc.gemspec index 295cb4d..b92f7c3 100644 --- a/danger-toc.gemspec +++ b/danger-toc.gemspec @@ -1,6 +1,6 @@ lib = File.expand_path('lib', __dir__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) -require 'toc/gem_version.rb' +require 'toc/gem_version' Gem::Specification.new do |spec| spec.name = 'danger-toc' @@ -14,10 +14,10 @@ Gem::Specification.new do |spec| 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_dependency 'activesupport' + spec.add_dependency 'danger-plugin-api', '~> 1.0' spec.add_dependency 'kramdown' - spec.add_runtime_dependency 'danger-plugin-api', '~> 1.0' + spec.metadata['rubygems_mfa_required'] = 'true' end diff --git a/lib/toc/config.rb b/lib/toc/config.rb index 05097b5..e684060 100644 --- a/lib/toc/config.rb +++ b/lib/toc/config.rb @@ -8,7 +8,7 @@ module Config header ].freeze - ACCESSORS = ATTRIBUTES.map { |name| "#{name}=".to_sym } + ACCESSORS = ATTRIBUTES.map { |name| :"#{name}=" } DELEGATORS = ATTRIBUTES + ACCESSORS diff --git a/lib/toc/constructors/kramdown_constructor.rb b/lib/toc/constructors/kramdown_constructor.rb index c89fd19..2574add 100644 --- a/lib/toc/constructors/kramdown_constructor.rb +++ b/lib/toc/constructors/kramdown_constructor.rb @@ -22,7 +22,7 @@ def flatten(el) end def convert(el) - toc = flatten(super(el)) + toc = flatten(super) has_toc = false headers = [] toc.each do |line| diff --git a/lib/toc/markdown_file.rb b/lib/toc/markdown_file.rb index 3b6990a..53a47b2 100644 --- a/lib/toc/markdown_file.rb +++ b/lib/toc/markdown_file.rb @@ -6,19 +6,16 @@ module Danger module Toc class MarkdownFile - attr_reader :filename - attr_reader :exists - attr_reader :toc - attr_reader :headers + attr_reader :filename, :exists, :toc, :headers def initialize(filename = 'README.md') @filename = filename @exists = File.exist?(filename) - if @exists - parse! - reduce! - validate! - end + return unless @exists + + parse! + reduce! + validate! end def exists? @@ -68,10 +65,10 @@ def reduce! headers.each do |header| min_depth = header[:depth] unless min_depth && min_depth < header[:depth] end - if min_depth - headers.each do |header| - header[:depth] -= min_depth - end + return unless min_depth + + headers.each do |header| + header[:depth] -= min_depth end end diff --git a/lib/toc/plugin.rb b/lib/toc/plugin.rb index 3f47707..2e55e32 100644 --- a/lib/toc/plugin.rb +++ b/lib/toc/plugin.rb @@ -48,14 +48,14 @@ def is_toc_correct? elsif toc_file.good? true else - markdown <<-MARKDOWN -Here's the expected TOC for #{filename}: + markdown <<~MARKDOWN + Here's the expected TOC for #{filename}: -```markdown -# #{Danger::Toc.config.header} + ```markdown + # #{Danger::Toc.config.header} -#{toc_file.toc_from_headers.join("\n")} -``` + #{toc_file.toc_from_headers.join("\n")} + ``` MARKDOWN if toc_file.has_toc? messaging.fail("The TOC found in #{filename} doesn't match the sections of the file.", sticky: false) diff --git a/spec/config_spec.rb b/spec/config_spec.rb index 5679c6a..26e2f83 100644 --- a/spec/config_spec.rb +++ b/spec/config_spec.rb @@ -1,7 +1,7 @@ require File.expand_path('spec_helper', __dir__) describe Danger::Toc::Config do - after(:each) do + after do described_class.reset end @@ -12,6 +12,7 @@ expect(Danger::Toc.config.files).to eq ['README.md'] end end + context 'custom value' do before do Danger::Toc.config.files = ['README.md', 'SOMETHING.md'] @@ -22,12 +23,14 @@ end end end + describe 'header' do context 'default' do it 'assumes Table of Contents' do expect(Danger::Toc.config.header).to eq 'Table of Contents' end end + context 'custom value' do before do Danger::Toc.config.header = 'Custom TOC' diff --git a/spec/constructors_spec.rb b/spec/constructors_spec.rb index 75cd481..1c1427b 100644 --- a/spec/constructors_spec.rb +++ b/spec/constructors_spec.rb @@ -2,19 +2,19 @@ describe Danger::Toc::Constructors do describe '.get' do - it 'should return constructor for kramdown' do + it 'returns constructor for kramdown' do expect( described_class.get(:kramdown) ).to eq(Danger::Toc::Constructors::KramdownConstructor) end - it 'should return constructor for github' do + it 'returns constructor for github' do expect( described_class.get(:github) ).to eq(Danger::Toc::Constructors::GithubConstructor) end - it 'should return error if not found constructor' do + it 'returns error if not found constructor' do expect do described_class.get :unknown end.to raise_error(NameError) diff --git a/spec/markdown_file/danger_toc_readme_spec.rb b/spec/markdown_file/danger_toc_readme_spec.rb index 4a31a60..f69534d 100644 --- a/spec/markdown_file/danger_toc_readme_spec.rb +++ b/spec/markdown_file/danger_toc_readme_spec.rb @@ -2,16 +2,20 @@ describe Danger::Toc::MarkdownFile do describe 'danger-toc README' do - let(:filename) { File.expand_path('../../README.md', __dir__) } subject do Danger::Toc::MarkdownFile.new(filename) end + + let(:filename) { File.expand_path('../../README.md', __dir__) } + it 'exists?' do expect(subject.exists?).to be true end + it 'has_toc?' do expect(subject.has_toc?).to be true end + it 'good?' do expect(subject.good?).to be true end diff --git a/spec/markdown_file/one_section_spec.rb b/spec/markdown_file/one_section_spec.rb index 93fa819..d724539 100644 --- a/spec/markdown_file/one_section_spec.rb +++ b/spec/markdown_file/one_section_spec.rb @@ -2,25 +2,32 @@ describe Danger::Toc::MarkdownFile do describe 'with a single section' do - let(:filename) { File.expand_path('../fixtures/markdown_file/one_section.md', __dir__) } subject do Danger::Toc::MarkdownFile.new(filename) end + + let(:filename) { File.expand_path('../fixtures/markdown_file/one_section.md', __dir__) } + it 'exists?' do expect(subject.exists?).to be true end + it 'has_toc?' do expect(subject.has_toc?).to be false end + it 'toc' do - expect(subject.toc).to be nil + expect(subject.toc).to be_nil end + it 'headers' do expect(subject.headers).to eq([{ depth: 0, id: 'what-is-this', text: 'What is This?' }]) end + it 'good?' do expect(subject.good?).to be false end + it 'bad?' do expect(subject.bad?).to be true end diff --git a/spec/markdown_file/one_section_with_toc_level_spec.rb b/spec/markdown_file/one_section_with_toc_level_spec.rb index e786402..9b0a3df 100644 --- a/spec/markdown_file/one_section_with_toc_level_spec.rb +++ b/spec/markdown_file/one_section_with_toc_level_spec.rb @@ -2,25 +2,32 @@ describe Danger::Toc::MarkdownFile do describe 'one section that is not at the root level' do - let(:filename) { File.expand_path('../fixtures/markdown_file/one_section_with_toc_level.md', __dir__) } subject do Danger::Toc::MarkdownFile.new(filename) end + + let(:filename) { File.expand_path('../fixtures/markdown_file/one_section_with_toc_level.md', __dir__) } + it 'exists?' do expect(subject.exists?).to be true end + it 'has_toc?' do expect(subject.has_toc?).to be true end + it 'toc' do expect(subject.toc).to eq(['- [What is This?](#what-is-this)']) end + it 'headers' do expect(subject.headers).to eq([{ depth: 0, id: 'what-is-this', text: 'What is This?' }]) end + it 'good?' do expect(subject.good?).to be true end + it 'bad?' do expect(subject.bad?).to be false end diff --git a/spec/markdown_file/one_section_with_toc_spec.rb b/spec/markdown_file/one_section_with_toc_spec.rb index f48a89e..a24ecc6 100644 --- a/spec/markdown_file/one_section_with_toc_spec.rb +++ b/spec/markdown_file/one_section_with_toc_spec.rb @@ -2,25 +2,32 @@ describe Danger::Toc::MarkdownFile do describe 'one section with TOC' do - let(:filename) { File.expand_path('../fixtures/markdown_file/one_section_with_toc.md', __dir__) } subject do Danger::Toc::MarkdownFile.new(filename) end + + let(:filename) { File.expand_path('../fixtures/markdown_file/one_section_with_toc.md', __dir__) } + it 'exists?' do expect(subject.exists?).to be true end + it 'has_toc?' do expect(subject.has_toc?).to be true end + it 'toc' do expect(subject.toc).to eq(['- [What is This?](#what-is-this)']) end + it 'headers' do expect(subject.headers).to eq([{ depth: 0, id: 'what-is-this', text: 'What is This?' }]) end + it 'good?' do expect(subject.good?).to be true end + it 'bad?' do expect(subject.bad?).to be false end diff --git a/spec/markdown_file/with_quoted_example_spec.rb b/spec/markdown_file/with_quoted_example_spec.rb index 196d7da..329edff 100644 --- a/spec/markdown_file/with_quoted_example_spec.rb +++ b/spec/markdown_file/with_quoted_example_spec.rb @@ -2,19 +2,24 @@ describe Danger::Toc::MarkdownFile do describe 'with a code example' do - let(:filename) { File.expand_path('../fixtures/markdown_file/with_quoted_example.md', __dir__) } subject do Danger::Toc::MarkdownFile.new(filename) end + + let(:filename) { File.expand_path('../fixtures/markdown_file/with_quoted_example.md', __dir__) } + it 'exists?' do expect(subject.exists?).to be true end + it 'has_toc?' do expect(subject.has_toc?).to be true end + it 'toc' do expect(subject.toc).to eq(['- [Example](#example)', '- [Conclusion](#conclusion)']) end + it 'headers' do expect(subject.headers).to eq( [ @@ -23,9 +28,11 @@ ] ) end + it 'good?' do expect(subject.good?).to be true end + it 'bad?' do expect(subject.bad?).to be false end diff --git a/spec/markdown_file/with_underscore_in_section_name_spec.rb b/spec/markdown_file/with_underscore_in_section_name_spec.rb index d6a671a..208b73d 100644 --- a/spec/markdown_file/with_underscore_in_section_name_spec.rb +++ b/spec/markdown_file/with_underscore_in_section_name_spec.rb @@ -2,29 +2,34 @@ describe Danger::Toc::MarkdownFile do describe 'with a underscore in section name' do - let(:filename) do - File.expand_path('../fixtures/markdown_file/one_section_with_underscore_in_name.md', __dir__) - end - subject do Danger::Toc::MarkdownFile.new(filename) end + let(:filename) do + File.expand_path('../fixtures/markdown_file/one_section_with_underscore_in_name.md', __dir__) + end + it 'exists?' do expect(subject.exists?).to be true end + it 'has_toc?' do expect(subject.has_toc?).to be true end + it 'toc' do expect(subject.toc).to eq(['- [What_is_this?](#what_is_this)']) end + it 'headers' do expect(subject.headers).to eq([{ depth: 0, id: 'what_is_this', text: 'What_is_this?' }]) end + it 'good?' do expect(subject.good?).to be true end + it 'bad?' do expect(subject.bad?).to be false end diff --git a/spec/toc_spec.rb b/spec/toc_spec.rb index 6680b06..94c5210 100644 --- a/spec/toc_spec.rb +++ b/spec/toc_spec.rb @@ -1,7 +1,7 @@ require File.expand_path('spec_helper', __dir__) describe Danger::Toc do - after(:each) do + after do Danger::Toc::Config.reset end @@ -19,21 +19,21 @@ let(:status_report) { toc.status_report } context 'toc_changes?' do - it 'should find modified files' do + it 'finds modified files' do allow(toc.git).to receive(:modified_files).and_return([filename]) allow(toc.git).to receive(:added_files).and_return([]) expect(toc).to be_toc_changes end - it 'should find added files' do + it 'finds added files' do allow(toc.git).to receive(:modified_files).and_return([]) allow(toc.git).to receive(:added_files).and_return([filename]) expect(toc).to be_toc_changes end - it 'should not found changed files' do + it 'does not found changed files' do allow(toc.git).to receive(:modified_files).and_return([]) allow(toc.git).to receive(:added_files).and_return([]) @@ -48,6 +48,7 @@ context 'without a file' do let(:filename) { 'does-not-exist' } + it 'complains' do expect(subject).to be false expect(status_report[:errors]).to eq ['The does-not-exist file does not exist.'] @@ -70,18 +71,19 @@ context 'with missing TOC' do let(:filename) { File.expand_path('fixtures/markdown_file/one_section.md', __dir__) } + it 'reports errors' do expect(subject).to be false expect(status_report[:errors]).to eq ["The #{filename} file is missing a TOC."] expect(status_report[:warnings]).to eq [] - expect(status_report[:markdowns].map(&:message)).to eq [<<-MARKDOWN -Here's the expected TOC for #{filename}: + expect(status_report[:markdowns].map(&:message)).to eq [<<~MARKDOWN + Here's the expected TOC for #{filename}: -```markdown -# Table of Contents + ```markdown + # Table of Contents -- [What is This?](#what-is-this) -``` + - [What is This?](#what-is-this) + ``` MARKDOWN ] end @@ -89,18 +91,19 @@ context 'with invalid TOC' do let(:filename) { File.expand_path('fixtures/markdown_file/one_section_with_invalid_toc.md', __dir__) } + it 'reports errors' do expect(subject).to be false expect(status_report[:errors]).to eq ["The TOC found in #{filename} doesn't match the sections of the file."] expect(status_report[:warnings]).to eq [] - expect(status_report[:markdowns].map(&:message)).to eq [<<-MARKDOWN -Here's the expected TOC for #{filename}: + expect(status_report[:markdowns].map(&:message)).to eq [<<~MARKDOWN + Here's the expected TOC for #{filename}: -```markdown -# Table of Contents + ```markdown + # Table of Contents -- [What is This?](#what-is-this) -``` + - [What is This?](#what-is-this) + ``` MARKDOWN ] end @@ -113,6 +116,7 @@ context 'with missing TOC' do let(:filename) { File.expand_path('fixtures/markdown_file/one_section.md', __dir__) } + it 'reports errors' do expect(subject).to be false expect(status_report[:markdowns].first.message).to include "\n# Custom TOC\n" @@ -121,6 +125,7 @@ context 'with a custom TOC' do let(:filename) { File.expand_path('fixtures/markdown_file/one_section_with_custom_toc.md', __dir__) } + it 'has no complaints' do expect(subject).to be true expect(status_report[:errors]).to eq []