Module: NxtVcrHarness::VcrCassetteHelper

Defined in:
lib/nxt_vcr_harness.rb

Instance Method Summary collapse

Instance Method Details

#hash_from_example(example, **options) ⇒ Object



20
21
22
23
24
# File 'lib/nxt_vcr_harness.rb', line 20

def hash_from_example(example, **options)
  cassette_by_example_options = %i[prefix suffix]
  name = CassetteNameByExample.new(example).call(**options.slice(*cassette_by_example_options))
  Digest::MD5.hexdigest(name)
end

#with_vcr_cassette(example, **options, &block) ⇒ Object



9
10
11
12
13
14
15
16
17
18
# File 'lib/nxt_vcr_harness.rb', line 9

def with_vcr_cassette(example, **options, &block)
  cassette_by_example_options = %i[prefix suffix]
  cassette_path = CassetteNameByExample.new(example).call(**options.slice(*cassette_by_example_options))

  vcr_options = options.reject { |k,_| k.in?(cassette_by_example_options) }

  ::VCR.use_cassette(cassette_path, **vcr_options) do
    block.call
  end
end