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 +4 -4
- data/lib/nxt_vcr_harness/cassette_tracker.rb +37 -0
- data/lib/nxt_vcr_harness/version.rb +1 -1
- data/lib/nxt_vcr_harness.rb +24 -4
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e3d32919f7a43d96067c3b626e25de172e17fe0c20f2643987adb0525fc48e0
|
4
|
+
data.tar.gz: 28e91dcf436cf091dc9a8bfe32a3216ce130dba4890451b9cdcb71f7884c5262
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
data/lib/nxt_vcr_harness.rb
CHANGED
@@ -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
|
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
|
-
|
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, **
|
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
|
-
|
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.
|
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
|