danger-toc 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe Danger::Toc::MarkdownFile do
4
+ describe 'ONE-SECTION.md' do
5
+ let(:filename) { File.expand_path('../../fixtures/markdown_file/ONE-SECTION.md', __FILE__) }
6
+ subject do
7
+ Danger::Toc::MarkdownFile.new(filename)
8
+ end
9
+ it 'exists?' do
10
+ expect(subject.exists?).to be true
11
+ end
12
+ it 'has_toc?' do
13
+ expect(subject.has_toc?).to be false
14
+ end
15
+ it 'toc' do
16
+ expect(subject.toc).to be nil
17
+ end
18
+ it 'headers' do
19
+ expect(subject.headers).to eq([{ depth: 0, id: 'what-is-this', text: 'What is This?' }])
20
+ end
21
+ it 'good?' do
22
+ expect(subject.good?).to be false
23
+ end
24
+ it 'bad?' do
25
+ expect(subject.bad?).to be true
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe Danger::Toc::MarkdownFile do
4
+ describe 'ONE-SECTION-WITH-TOC-LEVEL.md' do
5
+ let(:filename) { File.expand_path('../../fixtures/markdown_file/ONE-SECTION-WITH-TOC-LEVEL.md', __FILE__) }
6
+ subject do
7
+ Danger::Toc::MarkdownFile.new(filename)
8
+ end
9
+ it 'exists?' do
10
+ expect(subject.exists?).to be true
11
+ end
12
+ it 'has_toc?' do
13
+ expect(subject.has_toc?).to be true
14
+ end
15
+ it 'toc' do
16
+ expect(subject.toc).to eq(['- [What is This?](#what-is-this)'])
17
+ end
18
+ it 'headers' do
19
+ expect(subject.headers).to eq([{ depth: 0, id: 'what-is-this', text: 'What is This?' }])
20
+ end
21
+ it 'good?' do
22
+ expect(subject.good?).to be true
23
+ end
24
+ it 'bad?' do
25
+ expect(subject.bad?).to be false
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe Danger::Toc::MarkdownFile do
4
+ describe 'ONE-SECTION-WITH-TOC.md' do
5
+ let(:filename) { File.expand_path('../../fixtures/markdown_file/ONE-SECTION-WITH-TOC.md', __FILE__) }
6
+ subject do
7
+ Danger::Toc::MarkdownFile.new(filename)
8
+ end
9
+ it 'exists?' do
10
+ expect(subject.exists?).to be true
11
+ end
12
+ it 'has_toc?' do
13
+ expect(subject.has_toc?).to be true
14
+ end
15
+ it 'toc' do
16
+ expect(subject.toc).to eq(['- [What is This?](#what-is-this)'])
17
+ end
18
+ it 'headers' do
19
+ expect(subject.headers).to eq([{ depth: 0, id: 'what-is-this', text: 'What is This?' }])
20
+ end
21
+ it 'good?' do
22
+ expect(subject.good?).to be true
23
+ end
24
+ it 'bad?' do
25
+ expect(subject.bad?).to be false
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe Danger::Toc::MarkdownFile do
4
+ describe 'WITH-QUOTED-EXAMPLE.md' do
5
+ let(:filename) { File.expand_path('../../fixtures/markdown_file/WITH-QUOTED-EXAMPLE.md', __FILE__) }
6
+ subject do
7
+ Danger::Toc::MarkdownFile.new(filename)
8
+ end
9
+ it 'exists?' do
10
+ expect(subject.exists?).to be true
11
+ end
12
+ it 'has_toc?' do
13
+ expect(subject.has_toc?).to be true
14
+ end
15
+ it 'toc' do
16
+ expect(subject.toc).to eq(['- [Example](#example)', '- [Conclusion](#conclusion)'])
17
+ end
18
+ it 'headers' do
19
+ expect(subject.headers).to eq(
20
+ [
21
+ { depth: 0, id: 'example', text: 'Example' },
22
+ { depth: 0, id: 'conclusion', text: 'Conclusion' }
23
+ ]
24
+ )
25
+ end
26
+ it 'good?' do
27
+ expect(subject.good?).to be true
28
+ end
29
+ it 'bad?' do
30
+ expect(subject.bad?).to be false
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,38 @@
1
+ require 'pathname'
2
+ ROOT = Pathname.new(File.expand_path('../../', __FILE__))
3
+ $LOAD_PATH.unshift((ROOT + 'lib').to_s)
4
+ $LOAD_PATH.unshift((ROOT + 'spec').to_s)
5
+
6
+ require 'bundler/setup'
7
+ require 'pry'
8
+
9
+ require 'rspec'
10
+ require 'danger'
11
+
12
+ RSpec.configure do |config|
13
+ config.filter_gems_from_backtrace 'bundler'
14
+ config.color = true
15
+ config.tty = true
16
+ end
17
+
18
+ require 'danger_plugin'
19
+
20
+ def testing_ui
21
+ Cork::Board.new(silent: true)
22
+ end
23
+
24
+ def testing_env
25
+ {
26
+ 'HAS_JOSH_K_SEAL_OF_APPROVAL' => 'true',
27
+ 'TRAVIS_PULL_REQUEST' => '800',
28
+ 'TRAVIS_REPO_SLUG' => 'dblock/danger-toc',
29
+ 'TRAVIS_COMMIT_RANGE' => '759adcbd0d8f...13c4dc8bb61d',
30
+ 'DANGER_GITHUB_API_TOKEN' => '123sbdq54erfsd3422gdfio'
31
+ }
32
+ end
33
+
34
+ # A stubbed out Dangerfile for use in tests
35
+ def testing_dangerfile
36
+ env = Danger::EnvironmentManager.new(testing_env)
37
+ Danger::Dangerfile.new(env, testing_ui)
38
+ end
@@ -0,0 +1,87 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+
3
+ describe Danger::Toc do
4
+ after(:each) do
5
+ Danger::Toc::Config.reset
6
+ end
7
+
8
+ it 'is a Danger plugin' do
9
+ expect(Danger::DangerToc.new(nil)).to be_a Danger::Plugin
10
+ end
11
+
12
+ describe 'with Dangerfile' do
13
+ let(:filename) { File.expand_path('../fixtures/markdown_file/ONE-SECTION-WITH-TOC.md', __FILE__) }
14
+ let(:dangerfile) { testing_dangerfile }
15
+ let(:toc) do
16
+ dangerfile.toc.filenames = [filename]
17
+ dangerfile.toc
18
+ end
19
+ let(:status_report) { toc.status_report }
20
+
21
+ context 'is_toc_correct?' do
22
+ subject do
23
+ toc.is_toc_correct?
24
+ end
25
+
26
+ context 'without a file' do
27
+ let(:filename) { 'does-not-exist' }
28
+ it 'complains' do
29
+ expect(subject).to be false
30
+ expect(status_report[:errors]).to eq ['The does-not-exist file does not exist.']
31
+ end
32
+ end
33
+
34
+ context 'with changes' do
35
+ before do
36
+ allow(toc.git).to receive(:modified_files).and_return([filename])
37
+ allow(toc.git).to receive(:added_files).and_return([])
38
+ end
39
+
40
+ it 'has no complaints' do
41
+ expect(subject).to be true
42
+ expect(status_report[:errors]).to eq []
43
+ expect(status_report[:warnings]).to eq []
44
+ expect(status_report[:markdowns]).to eq []
45
+ end
46
+ end
47
+
48
+ context 'with missing TOC' do
49
+ let(:filename) { File.expand_path('../fixtures/markdown_file/ONE-SECTION.md', __FILE__) }
50
+ it 'reports errors' do
51
+ expect(subject).to be false
52
+ expect(status_report[:errors]).to eq ["The #{filename} file is missing a TOC."]
53
+ expect(status_report[:warnings]).to eq []
54
+ expect(status_report[:markdowns].map(&:message)).to eq [<<-MARKDOWN
55
+ Here's the expected TOC for #{filename}:
56
+
57
+ ```markdown
58
+ # Table of Contents
59
+
60
+ - [What is This?](#what-is-this)
61
+ ```
62
+ MARKDOWN
63
+ ]
64
+ end
65
+ end
66
+
67
+ context 'with invalid TOC' do
68
+ let(:filename) { File.expand_path('../fixtures/markdown_file/ONE-SECTION-WITH-INVALID-TOC.md', __FILE__) }
69
+ it 'reports errors' do
70
+ expect(subject).to be false
71
+ expect(status_report[:errors]).to eq ["The TOC found in #{filename} doesn't match the sections of the file."]
72
+ expect(status_report[:warnings]).to eq []
73
+ expect(status_report[:markdowns].map(&:message)).to eq [<<-MARKDOWN
74
+ Here's the expected TOC for #{filename}:
75
+
76
+ ```markdown
77
+ # Table of Contents
78
+
79
+ - [What is This?](#what-is-this)
80
+ ```
81
+ MARKDOWN
82
+ ]
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
metadata ADDED
@@ -0,0 +1,262 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: danger-toc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - dblock
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-11-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: kramdown
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: danger-plugin-api
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: guard
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '2.14'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '2.14'
83
+ - !ruby/object:Gem::Dependency
84
+ name: guard-rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '4.7'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '4.7'
97
+ - !ruby/object:Gem::Dependency
98
+ name: listen
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '='
102
+ - !ruby/object:Gem::Version
103
+ version: 3.0.7
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '='
109
+ - !ruby/object:Gem::Version
110
+ version: 3.0.7
111
+ - !ruby/object:Gem::Dependency
112
+ name: pry
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rake
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '10.0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '10.0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rspec
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '3.4'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '3.4'
153
+ - !ruby/object:Gem::Dependency
154
+ name: rubocop
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '0.41'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '0.41'
167
+ - !ruby/object:Gem::Dependency
168
+ name: yard
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "~>"
172
+ - !ruby/object:Gem::Version
173
+ version: '0.8'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - "~>"
179
+ - !ruby/object:Gem::Version
180
+ version: '0.8'
181
+ description: A danger.systems plugin for your markdown TOC.
182
+ email:
183
+ - dblock@dblock.org
184
+ executables: []
185
+ extensions: []
186
+ extra_rdoc_files: []
187
+ files:
188
+ - ".gitignore"
189
+ - ".rspec"
190
+ - ".rubocop.yml"
191
+ - ".rubocop_todo.yml"
192
+ - ".travis.yml"
193
+ - CHANGELOG.md
194
+ - CONTRIBUTING.md
195
+ - Dangerfile
196
+ - Gemfile
197
+ - Guardfile
198
+ - LICENSE.txt
199
+ - README.md
200
+ - RELEASING.md
201
+ - Rakefile
202
+ - danger-toc.gemspec
203
+ - images/toc-missing.png
204
+ - lib/danger_plugin.rb
205
+ - lib/danger_toc.rb
206
+ - lib/toc/config.rb
207
+ - lib/toc/constructor.rb
208
+ - lib/toc/extractor.rb
209
+ - lib/toc/gem_version.rb
210
+ - lib/toc/markdown_file.rb
211
+ - lib/toc/plugin.rb
212
+ - spec/config_spec.rb
213
+ - spec/fixtures/markdown_file/ONE-SECTION-WITH-INVALID-TOC.md
214
+ - spec/fixtures/markdown_file/ONE-SECTION-WITH-TOC-LEVEL.md
215
+ - spec/fixtures/markdown_file/ONE-SECTION-WITH-TOC.md
216
+ - spec/fixtures/markdown_file/ONE-SECTION.md
217
+ - spec/fixtures/markdown_file/WITH-QUOTED-EXAMPLE.md
218
+ - spec/markdown_file/danger_toc_readme_spec.rb
219
+ - spec/markdown_file/one_section_spec.rb
220
+ - spec/markdown_file/one_section_with_toc_level_spec.rb
221
+ - spec/markdown_file/one_section_with_toc_spec.rb
222
+ - spec/markdown_file/with_quoted_example_spec.rb
223
+ - spec/spec_helper.rb
224
+ - spec/toc_spec.rb
225
+ homepage: https://github.com/dblock/danger-toc
226
+ licenses:
227
+ - MIT
228
+ metadata: {}
229
+ post_install_message:
230
+ rdoc_options: []
231
+ require_paths:
232
+ - lib
233
+ required_ruby_version: !ruby/object:Gem::Requirement
234
+ requirements:
235
+ - - ">="
236
+ - !ruby/object:Gem::Version
237
+ version: '0'
238
+ required_rubygems_version: !ruby/object:Gem::Requirement
239
+ requirements:
240
+ - - ">="
241
+ - !ruby/object:Gem::Version
242
+ version: '0'
243
+ requirements: []
244
+ rubyforge_project:
245
+ rubygems_version: 2.6.12
246
+ signing_key:
247
+ specification_version: 4
248
+ summary: A danger.systems plugin for your markdown TOC.
249
+ test_files:
250
+ - spec/config_spec.rb
251
+ - spec/fixtures/markdown_file/ONE-SECTION-WITH-INVALID-TOC.md
252
+ - spec/fixtures/markdown_file/ONE-SECTION-WITH-TOC-LEVEL.md
253
+ - spec/fixtures/markdown_file/ONE-SECTION-WITH-TOC.md
254
+ - spec/fixtures/markdown_file/ONE-SECTION.md
255
+ - spec/fixtures/markdown_file/WITH-QUOTED-EXAMPLE.md
256
+ - spec/markdown_file/danger_toc_readme_spec.rb
257
+ - spec/markdown_file/one_section_spec.rb
258
+ - spec/markdown_file/one_section_with_toc_level_spec.rb
259
+ - spec/markdown_file/one_section_with_toc_spec.rb
260
+ - spec/markdown_file/with_quoted_example_spec.rb
261
+ - spec/spec_helper.rb
262
+ - spec/toc_spec.rb