Skip to content

Commit 031c914

Browse files
committed
Add task to verify yard docs are up to date
1 parent 2f4ef6f commit 031c914

4 files changed

Lines changed: 59 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99
### Added
1010

1111
- The default data directory in a Rails application can be set with the `config.support_table.data_directory` option in the Rails application configuration.
12-
- Added rake task `support_table_data:add_yard_docs` for Rails applications that will add YARD documentation to support table models for the named instance helpers.
12+
- Added rake task `support_table_data:add_yard_docs` for Rails applications that will add YARD documentation to support table models for the named instance helpers. There is also a task `support_table_data:verify_yard_docs` that can be used in a build pipeline to verify that the documentation is up to date.
1313
- The data synchronization task is now automatically attached to several Rails tasks: `db:seed`, `db:seed:replant`, `db:prepare`, `db:test:prepare`, `db:fixtures:load`. Support tables will be synced after running any of these tasks. This can be disabled by setting `config.support_table.auto_sync = false` in the Rails application configuration.
1414

1515
### Changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ The default behavior is to add the documentation comments at the end of the mode
196196
# End YARD docs for support_table_data
197197
```
198198

199-
A good practice is to add a check to your CI pipeline to ensure the documentation is always up to date.
199+
A good practice is to add a check to your CI pipeline to ensure the documentation is always up to date. You can run the rake task `support_table_data:verify_yard_docs` to do this. It will exit with an error if any models do not have up to date documentation.
200200

201201
### Caching
202202

lib/tasks/support_table_data.rake

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,26 @@ namespace :support_table_data do
3636
puts "Added YARD documentation to #{source_file.klass.name}."
3737
end
3838
end
39+
40+
desc "Verify that all the support table models have up to date YARD documentation for named instance methods."
41+
task verify_yard_docs: :environment do
42+
require_relative "../support_table_data/documentation"
43+
require_relative "utils"
44+
45+
SupportTableData::Tasks::Utils.eager_load!
46+
47+
all_up_to_date = true
48+
SupportTableData::Tasks::Utils.support_table_sources.each do |source_file|
49+
unless source_file.yard_docs_up_to_date?
50+
puts "YARD documentation is not up to date for #{source_file.klass.name}."
51+
all_up_to_date = false
52+
end
53+
end
54+
55+
if all_up_to_date
56+
puts "All support table models have up to date YARD documentation."
57+
else
58+
raise
59+
end
60+
end
3961
end

spec/tasks_spec.rb

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
require_relative "spec_helper"
44
require "rake"
55

6-
RSpec.describe "support_table_data" do
6+
RSpec.describe "support_table_data rake tasks" do
77
let(:out) { StringIO.new }
88

99
before do
@@ -60,4 +60,38 @@
6060
expect(color_write[:content]).to include("@!method self.red")
6161
end
6262
end
63+
64+
describe "verify_yard_docs" do
65+
it "verifies YARD documentation is up to date" do
66+
require_relative "../lib/support_table_data/documentation"
67+
require_relative "../lib/tasks/utils"
68+
69+
allow($stdout).to receive(:puts)
70+
allow_any_instance_of(SupportTableData::Documentation::SourceFile)
71+
.to receive(:yard_docs_up_to_date?).and_return(true)
72+
73+
# Run the task
74+
Rake.application.invoke_task "support_table_data:verify_yard_docs"
75+
76+
# Verify output indicates all docs are up to date
77+
expect($stdout).to have_received(:puts).with("All support table models have up to date YARD documentation.")
78+
end
79+
80+
it "raises an error if any YARD documentation is out of date" do
81+
require_relative "../lib/support_table_data/documentation"
82+
require_relative "../lib/tasks/utils"
83+
84+
allow($stdout).to receive(:puts)
85+
allow_any_instance_of(SupportTableData::Documentation::SourceFile)
86+
.to receive(:yard_docs_up_to_date?).and_return(false)
87+
88+
# Run the task and expect an error
89+
expect {
90+
Rake.application.invoke_task "support_table_data:verify_yard_docs"
91+
}.to raise_error(RuntimeError)
92+
93+
# Verify output indicates which docs are out of date
94+
expect($stdout).to have_received(:puts).at_least(:once)
95+
end
96+
end
6397
end

0 commit comments

Comments
 (0)