Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 66 additions & 24 deletions spec/diataxis_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@
require 'json'

RSpec.describe Diataxis do
let(:project_root) { File.expand_path('..', File.dirname(__FILE__)) }
let(:test_dir) { File.join(project_root, 'tmp', 'test') }
let(:docs_dir) { File.join(test_dir, 'docs') }
let(:howto_dir) { File.join(docs_dir, 'how-to') }
let(:tutorial_dir) { File.join(docs_dir, 'tutorials') }
let(:adr_dir) { File.join(docs_dir, 'exp/adr') }
let(:readme_path) { File.join(docs_dir, 'README.md') }
let(:test_dir) { File.join(File.expand_path('..', File.dirname(__FILE__)), 'tmp', 'test') }
let(:docs_paths) do
{
docs: File.join(test_dir, 'docs'),
howto: File.join(test_dir, 'docs/how-to'),
tutorial: File.join(test_dir, 'docs/tutorials'),
adr: File.join(test_dir, 'docs/exp/adr'),
explanation: File.join(test_dir, 'docs/explanations'),
readme: File.join(test_dir, 'docs/README.md')
}
end
let(:config_path) { File.join(test_dir, '.diataxis') }

before do
Expand All @@ -24,6 +28,7 @@
'readme' => 'docs/README.md',
'howtos' => 'docs/how-to',
'tutorials' => 'docs/tutorials',
'explanations' => 'docs/explanations',
'adr' => 'docs/exp/adr'
}
FileUtils.mkdir_p(File.dirname(config_path))
Expand All @@ -46,8 +51,8 @@
Diataxis::CLI.run(['howto', 'new', 'Test Document'])
end

expect(File).to exist(File.join(howto_dir, 'how_to_test_document.md'))
expect(File).to exist(readme_path)
expect(File).to exist(File.join(docs_paths[:howto], 'how_to_test_document.md'))
expect(File).to exist(docs_paths[:readme])
end
end

Expand Down Expand Up @@ -96,13 +101,13 @@
Diataxis::CLI.run(['howto', 'new', 'Configure System'])
end

howto_path = File.join(howto_dir, 'how_to_configure_system.md')
howto_path = File.join(docs_paths[:howto], 'how_to_configure_system.md')
expect(File).to exist(howto_path)

content = File.read(howto_path)
expect(content.downcase).to include('# how to configure system')

readme_content = File.read(readme_path)
readme_content = File.read(docs_paths[:readme])
expect(readme_content.downcase).to include('[how to configure system]')
end
end
Expand All @@ -113,13 +118,13 @@
Diataxis::CLI.run(['tutorial', 'new', 'Getting Started'])
end

tutorial_path = File.join(tutorial_dir, 'tutorial_getting_started.md')
tutorial_path = File.join(docs_paths[:tutorial], 'tutorial_getting_started.md')
expect(File).to exist(tutorial_path)

content = File.read(tutorial_path)
expect(content).to include('# Getting Started')

readme_content = File.read(readme_path)
readme_content = File.read(docs_paths[:readme])
expect(readme_content).to include('[Getting Started]')
end
end
Expand All @@ -130,24 +135,61 @@
Diataxis::CLI.run(['adr', 'new', 'Use PostgreSQL Database'])
end

adr_path = File.join(adr_dir, '0001-use-postgresql-database.md')
adr_path = File.join(docs_paths[:adr], '0001-use-postgresql-database.md')
expect(File).to exist(adr_path)

content = File.read(adr_path)
expect(content).to include('# 1. Use PostgreSQL Database')

readme_content = File.read(readme_path)
readme_content = File.read(docs_paths[:readme])
expect(readme_content).to include('[ADR-0001]')
end
end

context 'creating explanation' do
let(:explanation_path) { File.join(docs_paths[:explanation], 'explanation_system_architecture.md') }

before do
Dir.chdir(test_dir) do
Diataxis::CLI.run(['explanation', 'new', 'System Architecture'])
end
end

it 'creates explanation file in correct location' do
expect(File).to exist(explanation_path)
end

it 'creates explanation with correct template sections' do
content = File.read(explanation_path)
expected_sections = [
'# System Architecture',
'## Overview',
'## Background',
'## Key Concepts',
'## Technical Context',
'## Rationale',
'## Related Concepts'
]

expected_sections.each do |section|
expect(content).to include(section)
end
end

it 'updates README with explanation section and link' do
readme_content = File.read(docs_paths[:readme])
expect(readme_content).to include('[System Architecture]')
expect(readme_content).to include('### Explanations')
end
end
end

describe 'document title changes' do
it 'renames file and updates README when title changes' do
Dir.chdir(test_dir) do
# Create initial document
Diataxis::CLI.run(['howto', 'new', 'Original Title'])
original_path = File.join(howto_dir, 'how_to_original_title.md')
original_path = File.join(docs_paths[:howto], 'how_to_original_title.md')

# Update title
content = File.read(original_path)
Expand All @@ -158,12 +200,12 @@
Diataxis::CLI.run(['update', '.'])

# Check results
new_path = File.join(howto_dir, 'how_to_updated_title.md')
new_path = File.join(docs_paths[:howto], 'how_to_updated_title.md')
expect(File).not_to exist(original_path)
expect(File).to exist(new_path)

# Check README update
readme_content = File.read(readme_path)
readme_content = File.read(docs_paths[:readme])
expect(readme_content.downcase).not_to include('original title')
expect(readme_content.downcase).to include('updated title')
end
Expand All @@ -173,16 +215,16 @@
describe 'README management' do
context 'with existing README' do
before do
FileUtils.mkdir_p(File.dirname(readme_path))
File.write(readme_path, "Custom project description\n")
FileUtils.mkdir_p(File.dirname(docs_paths[:readme]))
File.write(docs_paths[:readme], "Custom project description\n")
end

it 'preserves custom content while updating document links' do
Dir.chdir(test_dir) do
Diataxis::CLI.run(['howto', 'new', 'Test Document'])
end

readme_content = File.read(readme_path)
readme_content = File.read(docs_paths[:readme])
expect(readme_content).to include('Custom project description')
expect(readme_content.downcase).to include('[how to test document]')
end
Expand All @@ -194,7 +236,7 @@
Diataxis::CLI.run(['howto', 'new', 'Test Document'])
end

readme_content = File.read(readme_path)
readme_content = File.read(docs_paths[:readme])
expect(readme_content).to include('# ')
expect(readme_content).to include('### HowTos')
expect(readme_content).to include('<!-- howtolog -->')
Expand All @@ -208,8 +250,8 @@
Diataxis::CLI.run(['howto', 'new', 'Test Document'])
end

expect(Dir).to exist(docs_dir)
expect(Dir).to exist(howto_dir)
expect(Dir).to exist(docs_paths[:docs])
expect(Dir).to exist(docs_paths[:howto])
end
end
end