nxt_vcr_harness 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3aca026840674f9396cfd43479e3ed694a5269d5aeb7e60e18454477fbd88e11
4
- data.tar.gz: 21c4b9e33c2fee21820d4d528deb6875816cc633ae7111dd8f8f64ad43b696c2
3
+ metadata.gz: 4e3d32919f7a43d96067c3b626e25de172e17fe0c20f2643987adb0525fc48e0
4
+ data.tar.gz: 28e91dcf436cf091dc9a8bfe32a3216ce130dba4890451b9cdcb71f7884c5262
5
5
  SHA512:
6
- metadata.gz: 246948e4309eba51c83d40e0d83c9606192821ed44b77d0b3d601de785a0bcaed87118634dd10b9961eff63985a394cfac6a85f6f7af64172b0255ff2702b7a3
7
- data.tar.gz: 8a78e3940884d2efc47f726241b7aff5d58d0b7bd117dd72c7713756b4d1348f2088d94467b0b168af808c7927207eeee2d5cdb977c671fd87e4855e704be8ee
6
+ metadata.gz: 8eddddeaffe85e35f469bf1ce5065fb30eda3d18bd6e0c690546eb1c8c3729159f313b1e47f5e26ee168a0c7f9911bb78f223ebd3c44fa07b51491b1b82f69f6
7
+ data.tar.gz: 662f6273ae0c845395d020b7eaf0f3deb5fc71e8dbb03cd9c7eed40227c47a318476ad409022dc4f84fc4d8bcd4019de3a68ad2b0f6dc23f87e0d6d7ef7412ce
@@ -0,0 +1,37 @@
1
+ class CassetteTracker
2
+ include Singleton
3
+
4
+ def initialize
5
+ @cassettes = []
6
+ end
7
+
8
+ def stats
9
+ puts '.'
10
+ puts "Stubbed #{playback_count} HTTP requests using #{cassette_file_names_from_used_cassettes.count} cassettes"
11
+ end
12
+
13
+ def reveal_unused_cassettes(library_dir)
14
+ all_cassette_paths = Dir.glob("#{library_dir}/**/*.yml")
15
+ unused_cassettes = (all_cassette_paths - cassette_file_names_from_used_cassettes)
16
+ if unused_cassettes.any?
17
+ puts "The following cassettes are unused: "
18
+ puts unused_cassettes.join(' ')
19
+ else
20
+ puts "There are no unused cassettes"
21
+ end
22
+ end
23
+
24
+ def cassette_file_names_from_used_cassettes
25
+ cassettes.map(&:file).uniq
26
+ end
27
+
28
+ def playback_count
29
+ cassettes.count
30
+ end
31
+
32
+ def track(cassette)
33
+ cassettes << cassette
34
+ end
35
+
36
+ attr_accessor :cassettes
37
+ end
@@ -1,3 +1,3 @@
1
1
  module NxtVcrHarness
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -1,19 +1,39 @@
1
1
  require "nxt_vcr_harness/version"
2
2
  require 'nxt_vcr_harness/cassette_name_by_example'
3
+ require 'nxt_vcr_harness/cassette_tracker'
3
4
 
4
5
  module NxtVcrHarness
5
- def configure(tag_name = :vcr_cassette)
6
+ def enable_vcr_tag(options = {})
7
+ tag_name = options.fetch(:tag_name, :vcr_cassette)
8
+ default_cassette_options = options.fetch(:default_cassette_options, {})
9
+
6
10
  RSpec.configure do |config|
7
11
  config.around(:each, tag_name) do |example|
8
12
  cassette_path = CassetteNameByExample.new(example).call
9
- vcr_options = example.metadata[tag_name].is_a?(TrueClass) ? { } : example.metadata[tag_name]
13
+ cassette_options = example.metadata[tag_name].is_a?(TrueClass) ? {} : example.metadata[tag_name]
14
+ cassette_options = default_cassette_options.merge(cassette_options)
10
15
 
11
- VCR.use_cassette(cassette_path, **vcr_options) do
16
+ VCR.use_cassette(cassette_path, **cassette_options) do
12
17
  example.call
13
18
  end
14
19
  end
15
20
  end
16
21
  end
17
22
 
18
- module_function :configure
23
+ def track_cassettes
24
+ RSpec.configure do |config|
25
+ config.after(:suite) do
26
+ CassetteTracker.instance.stats
27
+ CassetteTracker.instance.reveal_unused_cassettes(VCR.configuration.cassette_library_dir)
28
+ end
29
+ end
30
+
31
+ VCR.configure do |config|
32
+ config.before_playback do |_, cassette|
33
+ CassetteTracker.instance.track(cassette)
34
+ end
35
+ end
36
+ end
37
+
38
+ module_function :enable_vcr_tag, :track_cassettes
19
39
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nxt_vcr_harness
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andreas Robecke
@@ -102,6 +102,7 @@ files:
102
102
  - bin/setup
103
103
  - lib/nxt_vcr_harness.rb
104
104
  - lib/nxt_vcr_harness/cassette_name_by_example.rb
105
+ - lib/nxt_vcr_harness/cassette_tracker.rb
105
106
  - lib/nxt_vcr_harness/version.rb
106
107
  - nxt_vcr_harness.gemspec
107
108
  homepage: https://github.com/nxt-insurance