Repository navigation
Expand file tree
/
Copy pathguide_documents_test.rb
More file actions
93 lines (80 loc) · 3.49 KB
/
Copy pathguide_documents_test.rb
File metadata and controls
93 lines (80 loc) · 3.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# frozen_string_literal: true
require "test_helper"
class GuideDocumentsTest < ActiveSupport::TestCase
ROOT = File.expand_path("../..", __dir__)
GUIDES = {
"docs/guides/race-conditions.md" => [
"examples/guides/race_conditions/event.rb",
"examples/guides/race_conditions/event_tickets.rb"
],
"docs/guides/ordered-jobs.md" => [
"examples/guides/ordered_jobs/account.rb",
"examples/guides/ordered_jobs/apply_entry_unordered_job.rb",
"examples/guides/ordered_jobs/apply_entry_job.rb",
"examples/guides/ordered_jobs/create_ledger_entries.rb",
"examples/guides/ordered_jobs/solid_objects.rb",
"examples/guides/ordered_jobs/ledger_account.rb"
],
"docs/guides/expiring-reservations.md" => [
"examples/guides/expiring_reservations/seat_inventory.rb"
],
"docs/guides/transactional-outbox.md" => [
"examples/guides/transactional_outbox/order.rb",
"examples/guides/transactional_outbox/shipment_job.rb",
"examples/guides/transactional_outbox/outbox_message.rb",
"examples/guides/transactional_outbox/checkout.rb",
"examples/guides/transactional_outbox/solid_objects.rb"
]
}.freeze
BILLING_SYNC_EXAMPLES = [
"examples/compare/customer_billing_sync/customer_billing_sync.rb",
"examples/compare/customer_billing_sync/solid_objects.rb"
].freeze
COMPARISONS = {
"docs/compare/solid-queue.md" => BILLING_SYNC_EXAMPLES,
"docs/compare/good-job.md" => BILLING_SYNC_EXAMPLES,
"docs/compare/temporal.md" => BILLING_SYNC_EXAMPLES + [ "examples/compare/game_room/game_room.rb" ]
}.freeze
DOCUMENTS = GUIDES.merge(COMPARISONS).merge("docs/comparisons.md" => []).freeze
DASHES = [ "–", "—" ].freeze
LINK = /(?<!!)\[[^\]]*\]\(([^)\s]+)\)/
DOCUMENTS.each do |guide, examples|
test "#{guide} embeds each tested example file verbatim" do
source = File.read(File.join(ROOT, guide))
examples.each do |example|
code = File.read(File.join(ROOT, example)).delete_prefix("# rbs_inline: enabled\n\n")
assert_includes source, "```ruby\n#{code}```", "#{guide} does not embed the current #{example}"
end
end
test "#{guide} uses no em dash or en dash" do
source = File.read(File.join(ROOT, guide))
DASHES.each do |dash|
refute_includes source, dash, "#{guide} contains #{dash.unpack1("U").to_s(16)}"
end
end
test "#{guide} links only to files that exist" do
prose = File.read(File.join(ROOT, guide)).gsub(/^```.*?^```$/m, "")
prose.scan(LINK).flatten.each do |link|
next if link.start_with?("http://", "https://", "mailto:", "#")
target = File.expand_path(link.split("#").first, File.dirname(File.join(ROOT, guide)))
assert File.exist?(target), "#{guide} links to missing #{link}"
end
end
end
test "the comparisons page lists every comparison and the README links to it" do
comparisons = File.read(File.join(ROOT, "docs/comparisons.md"))
readme = File.read(File.join(ROOT, "README.md"))
COMPARISONS.each_key do |comparison|
assert_includes comparisons, "(#{comparison.delete_prefix("docs/")})"
end
assert_includes readme, "(docs/comparisons.md)"
end
test "the README and the agent guide list every guide" do
readme = File.read(File.join(ROOT, "README.md"))
agents = File.read(File.join(ROOT, "docs/agents.md"))
GUIDES.each_key do |guide|
assert_includes readme, "(#{guide})"
assert_includes agents, "(#{guide.delete_prefix("docs/")})"
end
end
end