Class: SchemaTest::FingerprintRewriter
- Inherits:
-
Object
- Object
- SchemaTest::FingerprintRewriter
- Defined in:
- lib/schema_test/fingerprint_rewriter.rb
Overview
Rewrites ‘assert_valid_json_for_schema` calls in test files so that they carry an up-to-date `fingerprint:` argument matching the compiled schema. This means a schema change shows up as a diff in the test files themselves, pointing at exactly which API endpoints changed, and lets the assertion verify the fingerprint at runtime.
The call site reported at runtime is the line the call starts on, which for a multi-line call is the line with the opening paren. The rewriter therefore scans forward to find the matching closing paren before inserting or replacing the argument.
Constant Summary collapse
- FINGERPRINT_ARGUMENT =
/fingerprint:\s*("(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|[^\s,)]+)/
Instance Method Summary collapse
-
#initialize(contents, line_indexes_with_fingerprints) ⇒ FingerprintRewriter
constructor
A new instance of FingerprintRewriter.
- #output ⇒ Object
Constructor Details
#initialize(contents, line_indexes_with_fingerprints) ⇒ FingerprintRewriter
Returns a new instance of FingerprintRewriter.
15 16 17 18 |
# File 'lib/schema_test/fingerprint_rewriter.rb', line 15 def initialize(contents, line_indexes_with_fingerprints) @lines = contents.split("\n") @line_indexes_with_fingerprints = line_indexes_with_fingerprints end |
Instance Method Details
#output ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/schema_test/fingerprint_rewriter.rb', line 20 def output @line_indexes_with_fingerprints.each do |start_index, fingerprint| next unless @lines[start_index] annotate_call(start_index, fingerprint) end @lines.join("\n") + "\n" end |