Class: RCV::Cassette
- Inherits:
-
Object
- Object
- RCV::Cassette
- Defined in:
- lib/rcv/cassette.rb
Instance Method Summary collapse
-
#initialize(cassette_file) ⇒ Cassette
constructor
A new instance of Cassette.
- #reverse_play ⇒ Object
- #reverse_play_interaction(interaction) ⇒ Object
Constructor Details
#initialize(cassette_file) ⇒ Cassette
Returns a new instance of Cassette.
17 18 19 |
# File 'lib/rcv/cassette.rb', line 17 def initialize(cassette_file) @loaded_cassette = ::YAML.load_file(cassette_file) end |
Instance Method Details
#reverse_play ⇒ Object
21 22 23 24 25 |
# File 'lib/rcv/cassette.rb', line 21 def reverse_play @loaded_cassette['http_interactions'].map do |http_interaction| reverse_play_interaction(http_interaction) end end |
#reverse_play_interaction(interaction) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/rcv/cassette.rb', line 27 def reverse_play_interaction(interaction) request = interaction["request"] response = interaction["response"] req = { method: request["method"].to_sym, url: request["uri"] } req[:payload] = request["body"]["string"] if has_data?(request) req[:headers] = request["headers"] if has_headers?(request) # normalize vcr headers as well res = RestClient::Request.execute(req) vcr_response = { status: response["status"]["code"], headers: HeaderDowncaser.downcase_headers(response["headers"]), body: response["body"]["string"] } backend_response = { status: res.code, headers: slice(HeaderDowncaser.downcase_headers(res.raw_headers), *vcr_response[:headers].keys), body: res.to_str } [req, backend_response, vcr_response] end |