Class: GraphWeaver::Testing::Recorder
- Inherits:
-
Object
- Object
- GraphWeaver::Testing::Recorder
- Defined in:
- lib/graph_weaver/testing/cassette.rb
Overview
Tees requests through a live client and records every response. With Testing.config.anonymize (or anonymize: true), responses are anonymized as they're recorded — and the anonymized version is what the caller sees too, so assertions written now hold on replay.
Instance Method Summary collapse
- #execute(query, variables: {}) ⇒ Object
-
#initialize(client, cassette, anonymize: nil) ⇒ Recorder
constructor
A new instance of Recorder.
Constructor Details
#initialize(client, cassette, anonymize: nil) ⇒ Recorder
Returns a new instance of Recorder.
111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/graph_weaver/testing/cassette.rb', line 111 def initialize(client, cassette, anonymize: nil) @client = client @cassette = cassette.is_a?(Cassette) ? cassette : Cassette.new(cassette) config = Testing.config if anonymize.nil? ? config.anonymize : anonymize unless config.schema raise ArgumentError, "anonymizing recordings needs GraphWeaver::Testing.config.schema" end @anonymizer = Anonymizer.new(schema: config.schema, seed: config.seed) end end |
Instance Method Details
#execute(query, variables: {}) ⇒ Object
125 126 127 128 129 130 131 132 133 |
# File 'lib/graph_weaver/testing/cassette.rb', line 125 def execute(query, variables: {}) response = @client.execute(query, variables:).to_h if @anonymizer && (data = response["data"]) response = response.merge("data" => @anonymizer.anonymize(query, data)) end @cassette.record(query, variables, response) response end |