Skip to content

Commit 6843880

Browse files
committed
Add ReadmeTestHelper
This helper provides utilities for extracting code snippets from `README.md`.
1 parent 7b1f50c commit 6843880

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

test/readme_test_helper.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# frozen_string_literal: true
2+
3+
module ReadmeTestHelper
4+
private
5+
6+
# Extracts a code snippet from the README.md file by its "SNIPPET ID" comment and language
7+
def extract_readme_code_snippet(id, language: "ruby")
8+
snippet = readme_content[/<!-- SNIPPET ID: #{id} -->\n```#{language}\n(.*?)\n```/m, 1]
9+
assert_not_nil(snippet, "Could not find code snippet with ID #{id}")
10+
snippet
11+
end
12+
13+
def readme_content = File.read(File.join(project_root, "README.md"))
14+
def project_root = File.expand_path("..", __dir__)
15+
end

0 commit comments

Comments
 (0)