Skip to content

Commit de0e722

Browse files
committed
Add integration tests for server page routing
These tests exercise the full pipeline: parsing source files, then resolving page URLs through the server's route method. They verify that text pages (.md, .rdoc), class pages, the index, and 404s all work correctly. The text page tests would have caught the update_parser_of_file key mismatch bug.
1 parent cb021d1 commit de0e722

1 file changed

Lines changed: 74 additions & 0 deletions

File tree

test/rdoc/rdoc_server_test.rb

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# frozen_string_literal: true
2+
require_relative 'support/test_case'
3+
4+
class RDocServerTest < RDoc::TestCase
5+
6+
def setup
7+
super
8+
9+
@dir = Dir.mktmpdir("test_rdoc_server_")
10+
11+
File.write File.join(@dir, "PAGE.md"), "# A Page\n\nSome content.\n"
12+
File.write File.join(@dir, "NOTES.rdoc"), "= Notes\n\nSome notes.\n"
13+
File.write File.join(@dir, "example.rb"), "# A class\nclass Example; end\n"
14+
15+
@options.files = [@dir]
16+
@options.op_dir = File.join(@dir, "_site")
17+
@options.root = Pathname(@dir)
18+
@options.verbosity = 0
19+
@options.finish
20+
21+
@rdoc.options = @options
22+
@rdoc.store = RDoc::Store.new(@options)
23+
24+
capture_output do
25+
@rdoc.parse_files @options.files
26+
end
27+
@rdoc.store.complete @options.visibility
28+
29+
@server = RDoc::Server.new(@rdoc, 0)
30+
end
31+
32+
def teardown
33+
FileUtils.rm_rf @dir
34+
super
35+
end
36+
37+
def test_route_serves_text_page
38+
status, content_type, body = @server.send(:route, '/PAGE_md.html')
39+
40+
assert_equal 200, status
41+
assert_equal 'text/html', content_type
42+
assert_include body, 'A Page'
43+
end
44+
45+
def test_route_serves_rdoc_text_page
46+
status, content_type, body = @server.send(:route, '/NOTES_rdoc.html')
47+
48+
assert_equal 200, status
49+
assert_equal 'text/html', content_type
50+
assert_include body, 'Notes'
51+
end
52+
53+
def test_route_serves_class_page
54+
status, content_type, body = @server.send(:route, '/Example.html')
55+
56+
assert_equal 200, status
57+
assert_equal 'text/html', content_type
58+
assert_include body, 'Example'
59+
end
60+
61+
def test_route_serves_index
62+
status, content_type, _body = @server.send(:route, '/')
63+
64+
assert_equal 200, status
65+
assert_equal 'text/html', content_type
66+
end
67+
68+
def test_route_returns_404_for_missing_page
69+
status, content_type, _body = @server.send(:route, '/nonexistent.html')
70+
71+
assert_equal 404, status
72+
assert_equal 'text/html', content_type
73+
end
74+
end

0 commit comments

Comments
 (0)