nxt_vcr_harness 0.1.4 → 0.2.0

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: 32922bec1636e50f2f5e1493bb2b339a7b9f071a17f514afe5cae0ac37ed2889
4
- data.tar.gz: 38defb9a3f01355347395709dff2cbc2e23d06126a43c03806d7aa20c93f4ce5
3
+ metadata.gz: 299a23a4cea677b8985726471cfb9fbcc28b48d2ce70c78de1a90748fa768bc3
4
+ data.tar.gz: 2db4abfd09dffc697204cbb3881bda70a15ad72ce5fdf59cf1a92ba44a5e53d8
5
5
  SHA512:
6
- metadata.gz: d91532d74bb9a2ca0ef9c9ad680bdd7fe1cc73ad9a896f3a0b8f144fdf167f48a96d7aef98ebece806e77e45682a795eb332eabd18ba3b91a2e9ecacf456465a
7
- data.tar.gz: dd5e99a7d29f9aee781fae2d3be7a3a7bd65023785547d44d0845fb9acf500cee23208d6fe9f28fd2505d1d02fc3a618155db6efb4c221676c2220632c06d468
6
+ metadata.gz: 47ec2fe863122f365fd32e1226bb9fe020c3bea55237b394242ef062940c73563e0d5c7c1adf312754e2aea7ee505c0b780b57e98cbc7e878564e8a3d4599395
7
+ data.tar.gz: f81055d1d0e94684e8c3063f301e5175300769669d321e2de43191f4780b83e0f9b40c27c591273759f33d7990675facdbf5985100c05b3e9d0b8b28fdad4915
data/.circleci/config.yml CHANGED
@@ -1,56 +1,37 @@
1
- version: 2
1
+ # See https://circleci.com/docs/2.0/language-ruby/ for more details
2
+
3
+ version: 2.1
4
+
5
+ orbs:
6
+ ruby: circleci/ruby@2.0.1
2
7
 
3
8
  jobs:
4
- build:
5
- working_directory: /home/circleci/app
9
+ checks:
10
+ parallelism: 1
11
+ resource_class: small
6
12
  docker:
7
- - image: circleci/ruby:2.7.2-node
8
- environment:
9
- RACK_ENV: test
10
- RAILS_ENV: test
11
- COVERAGE: true
12
- BUNDLER_VERSION: 2.1.4
13
- # CC_TEST_REPORTER_ID: YOUR_REPO_CC_TEST_REPORTER_ID # ENV var set in CircleCI user interface
13
+ - image: cimg/ruby:3.2.2
14
14
  steps:
15
15
  - checkout
16
- # libpq-dev: required for compiling the `pg` gem
17
- # nodejs: required for asset compilation (see https://github.com/rails/execjs)
18
- - run:
19
- name: Install apt dependencies
20
- command: |
21
- sudo apt update -q \
22
- && sudo apt upgrade -q
23
- - restore_cache:
24
- key: v3-bundler-{{ checksum "Gemfile.lock" }}-{{ arch }}
25
- - run: gem install bundler --version $BUNDLER_VERSION
26
- - run: bundle config build.nokogiri --use-system-libraries
27
- - run: bundle install --without staging:production --path=vendor/bundle --jobs=4 --retry=3
28
- - save_cache:
29
- key: v3-bundler-{{ checksum "Gemfile.lock" }}-{{ arch }}
30
- paths:
31
- - vendor/bundle
16
+ - ruby/install-deps:
17
+ key: gems-v2
18
+ include-branch-in-cache-key: false
19
+ # - ruby/rubocop-check
32
20
  - run:
33
- name: Collect and filter specs
34
- command: |
35
- mkdir -p tmp/circleci
36
- circleci tests glob "spec/**/*_spec.rb" > tmp/circleci/all_tests.txt
37
- circleci tests split --split-by=timings < tmp/circleci/all_tests.txt > tmp/circleci/tests_to_run.txt
38
- echo "These specs will be run:"
39
- cat tmp/circleci/tests_to_run.txt
40
- - run:
41
- name: Parallel RSpec
42
- command: |
43
- bundle exec rspec \
44
- --color \
45
- --format progress \
46
- --require spec_helper \
47
- --format RspecJunitFormatter --out /tmp/rspec/junit.xml \
48
- $(cat tmp/circleci/tests_to_run.txt)
21
+ name: RSpec Tests
22
+ command: |-
23
+ bundle exec rspec --format RspecJunitFormatter \
24
+ --out /tmp/test-results/rspec/results.xml --format progress
49
25
  # actually not necessary for test results to be collected, but these files
50
26
  # won't show up in the web UI otherwise
51
27
  - store_artifacts:
52
28
  path: /tmp/rspec/
53
29
  destination: rspec
54
-
55
30
  - store_test_results:
56
31
  path: /tmp/rspec/
32
+
33
+ workflows:
34
+ version: 2
35
+ checks:
36
+ jobs:
37
+ - checks
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.7.2
1
+ 3.2.2
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # v0.2.0 2024-02-17
2
+ ## Added
3
+ - Added `strip_unneeded_headers_before_save` method to keep cassette size down
4
+
1
5
  # v0.1.4 2020-12-03
2
6
 
3
7
  ### Updated
data/Gemfile.lock CHANGED
@@ -1,47 +1,47 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- nxt_vcr_harness (0.1.4)
4
+ nxt_vcr_harness (0.2.0)
5
5
  rspec (~> 3.0)
6
6
  vcr (~> 6.0)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- coderay (1.1.2)
12
- diff-lcs (1.4.4)
11
+ coderay (1.1.3)
12
+ diff-lcs (1.5.0)
13
13
  method_source (1.0.0)
14
- pry (0.13.1)
14
+ pry (0.14.2)
15
15
  coderay (~> 1.1)
16
16
  method_source (~> 1.0)
17
- rake (13.0.1)
18
- rspec (3.10.0)
19
- rspec-core (~> 3.10.0)
20
- rspec-expectations (~> 3.10.0)
21
- rspec-mocks (~> 3.10.0)
22
- rspec-core (3.10.0)
23
- rspec-support (~> 3.10.0)
24
- rspec-expectations (3.10.0)
17
+ rake (13.0.6)
18
+ rspec (3.12.0)
19
+ rspec-core (~> 3.12.0)
20
+ rspec-expectations (~> 3.12.0)
21
+ rspec-mocks (~> 3.12.0)
22
+ rspec-core (3.12.3)
23
+ rspec-support (~> 3.12.0)
24
+ rspec-expectations (3.12.3)
25
25
  diff-lcs (>= 1.2.0, < 2.0)
26
- rspec-support (~> 3.10.0)
27
- rspec-mocks (3.10.0)
26
+ rspec-support (~> 3.12.0)
27
+ rspec-mocks (3.12.6)
28
28
  diff-lcs (>= 1.2.0, < 2.0)
29
- rspec-support (~> 3.10.0)
30
- rspec-support (3.10.0)
31
- rspec_junit_formatter (0.4.1)
29
+ rspec-support (~> 3.12.0)
30
+ rspec-support (3.12.2)
31
+ rspec_junit_formatter (0.6.0)
32
32
  rspec-core (>= 2, < 4, != 2.12.0)
33
- vcr (6.0.0)
33
+ vcr (6.2.0)
34
34
 
35
35
  PLATFORMS
36
36
  ruby
37
37
 
38
38
  DEPENDENCIES
39
- bundler (~> 2.1)
39
+ bundler
40
40
  nxt_vcr_harness!
41
41
  pry
42
- rake (~> 13.0)
43
- rspec (~> 3.0)
44
- rspec_junit_formatter (~> 0.4.1)
42
+ rake
43
+ rspec
44
+ rspec_junit_formatter
45
45
 
46
46
  BUNDLED WITH
47
47
  2.1.4
data/README.md CHANGED
@@ -22,12 +22,16 @@ Or install it yourself as:
22
22
 
23
23
  ## Usage
24
24
 
25
- NxtVcrHarness currently has two features. You can use it to find vcr cassettes that are not being used when you
25
+ NxtVcrHarness provides three features.
26
+
27
+ ### 1. List unused cassettes after each test run.
28
+ You can use it to find vcr cassettes that are not being used when you
26
29
  run your test suite. Enable it by calling `NxtVcrHarness.track_cassettes_if(...your condition in here...)`.
27
30
  Note that the output only makes sense when you run your complete test suite.
28
31
  If you run only a subset all cassettes that are used by your other test will be included too.
29
32
 
30
- The second feature is that you can enable your custom :vcr tag by calling `NxtVcrHarness.enable_vcr_tag`. This will
33
+ ### 2. Use custom VCR tag
34
+ You can enable your custom :vcr tag by calling `NxtVcrHarness.enable_vcr_tag`. This will
31
35
  automatically name your vcr cassettes based on the your rspec example and the surrounding contexts. You can also
32
36
  setup default cassette options for your vcr tag.
33
37
 
@@ -35,6 +39,56 @@ setup default cassette options for your vcr tag.
35
39
  NxtVcrHarness.enable_vcr_tag(tag_name: :my_vcr_tag, default_cassette_options: { ... })
36
40
  ```
37
41
 
42
+ ### 3. Keep cassettes small by removing unneeded headers
43
+ API responses typically contain useful headers, such as information about rate limits and pagination,
44
+ but also many more unnecessary headers.
45
+ You can drastically reduce the size of your cassettes by stripping unnecessary headers before saving.
46
+
47
+ ```ruby
48
+ # After VCR.configure:
49
+ NxtVcrHarness.strip_unneeded_headers_before_save
50
+ ```
51
+
52
+ By default, nxt_vcr_harness will remove the following kinds of headers (case-insensitive) from responses:
53
+ - CORS headers (`Access-Control-*`)
54
+ - Headers for browsers (`X-Frame-Options`, `Content-Security-Policy`, `Strict-Transport-Security`, `X-Xss-Protection`, `Expect-Ct`...)
55
+ - Headers for browsers/proxies/CDNs (`Cache-Control`, `Etag`, `Vary`...)
56
+ - Common cloud provider headers (CloudFlare, AWS)
57
+ - Server details (`Server-Timing`, `X-Powered-By`, `X-Runtime`, `Via`, `Date`)
58
+
59
+ From requests, `Accept-Encoding` and `Expect` headers will be removed.
60
+
61
+ See `NxtVcrHarness::UnneededHeaders.default_headers_to_strip` for the full list of removed headers.
62
+
63
+ You can add or override headers to be removed (regexes or strings):
64
+
65
+ ```ruby
66
+ NxtVcrHarness.strip_unneeded_headers_before_save do |headers_to_strip|
67
+ headers_to_strip[:response] << /X-Dixa-.+/i
68
+ end
69
+ ```
70
+
71
+ To run this slimming on existing cassettes, you can create a simple Ruby script or Rake task, for example::
72
+
73
+ ```rb
74
+ require 'vcr'
75
+ require 'nxt_vcr_harness'
76
+
77
+ headers_to_strip = NxtVcrHarness::UnneededHeaders.default_headers_to_strip
78
+ headers_to_strip[:responses] << /X-Dixa-.+/i
79
+
80
+ task slim_cassettes: :environment do
81
+ Dir[Rails.root.join('spec/fixtures/vcr_cassettes/**/**.yml')].each do |file_path|
82
+ cassette = ::YAML.load(File.read(file_path))
83
+ cassette['http_interactions'].each do |interaction|
84
+ NxtVcrHarness::UnneededHeaders.strip(interaction['request']['headers'], headers_to_strip[:requests])
85
+ NxtVcrHarness::UnneededHeaders.strip(interaction['response']['headers'], headers_to_strip[:responses])
86
+ end
87
+ File.write(file_path, VCR.cassette_serializers[:yaml].serialize(cassette))
88
+ end
89
+ end
90
+ ```
91
+
38
92
  ## Development
39
93
 
40
94
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -0,0 +1,74 @@
1
+ module NxtVcrHarness
2
+ module UnneededHeaders
3
+ REQUEST_HEADERS = %w[
4
+ Accept-Encoding
5
+ Expect
6
+ ].freeze
7
+
8
+ BROWSER_HEADERS = [
9
+ /Access-Control-.+/i,
10
+ 'Alt-Svc',
11
+ /(X-)?Content-Security-Policy.*/i,
12
+ 'Cache-Control',
13
+ 'Etag',
14
+ 'Expect-Ct',
15
+ 'NEL',
16
+ 'Referrer-Policy',
17
+ 'Report-To',
18
+ 'Reporting-Endpoints',
19
+ 'Set-Cookie',
20
+ 'Strict-Transport-Security',
21
+ 'Vary',
22
+ /X-(Content-Type-Options|Download-Options|Frame-Options|Permitted-Cross-Domain-Policies|Webkit-Csp|Xss-Protection)/i,
23
+ ].freeze
24
+
25
+ SERVER_DETAILS = [
26
+ 'Date',
27
+ 'Server',
28
+ 'Server-Timing',
29
+ /X-(Powered-By|Runtime|Served-By|Server-Elapsed)/i,
30
+ /X-Envoy-(Decorator-Operation|Upstream-Service-Time)/i,
31
+ 'Via',
32
+ ].freeze
33
+
34
+ AMAZON_HEADERS = [
35
+ /X-Amzn?-.+/i,
36
+ 'X-Cache',
37
+ ].freeze
38
+
39
+ CLOUDFLARE_HEADERS = [
40
+ /Cf-.+/i,
41
+ ].freeze
42
+
43
+ RESPONSE_HEADERS = [
44
+ *BROWSER_HEADERS,
45
+ *SERVER_DETAILS,
46
+ *AMAZON_HEADERS,
47
+ *CLOUDFLARE_HEADERS,
48
+ ].freeze
49
+
50
+ def default_headers_to_strip
51
+ {
52
+ requests: UnneededHeaders::REQUEST_HEADERS.dup,
53
+ responses: UnneededHeaders::RESPONSE_HEADERS.dup,
54
+ }
55
+ end
56
+
57
+ def strip(headers_hash, headers_to_strip)
58
+ headers_hash.delete_if do |k, v|
59
+ headers_to_strip.any? do |header|
60
+ case header
61
+ when String
62
+ k == header || k == header.downcase
63
+ when Regexp
64
+ k.match?(header)
65
+ else
66
+ raise ArgumentError, "Unexpected key type in headers_to_strip hash: #{header}"
67
+ end
68
+ end
69
+ end
70
+ end
71
+
72
+ module_function :default_headers_to_strip, :strip
73
+ end
74
+ end
@@ -1,3 +1,3 @@
1
1
  module NxtVcrHarness
2
- VERSION = "0.1.4"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -1,6 +1,7 @@
1
1
  require "nxt_vcr_harness/version"
2
2
  require 'nxt_vcr_harness/cassette_name_by_example'
3
3
  require 'nxt_vcr_harness/cassette_tracker'
4
+ require 'nxt_vcr_harness/unneeded_headers'
4
5
  require 'digest'
5
6
 
6
7
  module NxtVcrHarness
@@ -66,5 +67,19 @@ module NxtVcrHarness
66
67
  end
67
68
  end
68
69
 
69
- module_function :enable_vcr_tag, :track_cassettes, :enable_vcr_cassette_helper, :track_cassettes_if
70
+ def strip_unneeded_headers_before_save
71
+ headers_to_strip = UnneededHeaders.default_headers_to_strip
72
+
73
+ yield headers_to_strip if block_given?
74
+
75
+ ::VCR.configure do |config|
76
+ config.before_record do |interaction, _cassette|
77
+ UnneededHeaders.strip(interaction.request.headers, headers_to_strip[:requests])
78
+ UnneededHeaders.strip(interaction.response.headers, headers_to_strip[:responses])
79
+ end
80
+ end
81
+ end
82
+
83
+ module_function :enable_vcr_tag, :track_cassettes, :enable_vcr_cassette_helper, :track_cassettes_if,
84
+ :strip_unneeded_headers_before_save
70
85
  end
@@ -39,9 +39,9 @@ Gem::Specification.new do |spec|
39
39
  spec.add_dependency "rspec", "~> 3.0"
40
40
  spec.add_dependency "vcr", "~> 6.0"
41
41
 
42
- spec.add_development_dependency "bundler", "~> 2.1"
43
- spec.add_development_dependency "rake", "~> 13.0"
44
- spec.add_development_dependency "rspec", "~> 3.0"
42
+ spec.add_development_dependency "bundler"
43
+ spec.add_development_dependency "rake"
44
+ spec.add_development_dependency "rspec"
45
45
  spec.add_development_dependency "pry"
46
- spec.add_development_dependency "rspec_junit_formatter", "~> 0.4.1"
46
+ spec.add_development_dependency "rspec_junit_formatter"
47
47
  end
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nxt_vcr_harness
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andreas Robecke
8
8
  - Nils Sommer
9
9
  - Raphael Kallensee
10
- autorequire:
10
+ autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2020-12-04 00:00:00.000000000 Z
13
+ date: 2024-02-22 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec
@@ -44,44 +44,44 @@ dependencies:
44
44
  name: bundler
45
45
  requirement: !ruby/object:Gem::Requirement
46
46
  requirements:
47
- - - "~>"
47
+ - - ">="
48
48
  - !ruby/object:Gem::Version
49
- version: '2.1'
49
+ version: '0'
50
50
  type: :development
51
51
  prerelease: false
52
52
  version_requirements: !ruby/object:Gem::Requirement
53
53
  requirements:
54
- - - "~>"
54
+ - - ">="
55
55
  - !ruby/object:Gem::Version
56
- version: '2.1'
56
+ version: '0'
57
57
  - !ruby/object:Gem::Dependency
58
58
  name: rake
59
59
  requirement: !ruby/object:Gem::Requirement
60
60
  requirements:
61
- - - "~>"
61
+ - - ">="
62
62
  - !ruby/object:Gem::Version
63
- version: '13.0'
63
+ version: '0'
64
64
  type: :development
65
65
  prerelease: false
66
66
  version_requirements: !ruby/object:Gem::Requirement
67
67
  requirements:
68
- - - "~>"
68
+ - - ">="
69
69
  - !ruby/object:Gem::Version
70
- version: '13.0'
70
+ version: '0'
71
71
  - !ruby/object:Gem::Dependency
72
72
  name: rspec
73
73
  requirement: !ruby/object:Gem::Requirement
74
74
  requirements:
75
- - - "~>"
75
+ - - ">="
76
76
  - !ruby/object:Gem::Version
77
- version: '3.0'
77
+ version: '0'
78
78
  type: :development
79
79
  prerelease: false
80
80
  version_requirements: !ruby/object:Gem::Requirement
81
81
  requirements:
82
- - - "~>"
82
+ - - ">="
83
83
  - !ruby/object:Gem::Version
84
- version: '3.0'
84
+ version: '0'
85
85
  - !ruby/object:Gem::Dependency
86
86
  name: pry
87
87
  requirement: !ruby/object:Gem::Requirement
@@ -100,16 +100,16 @@ dependencies:
100
100
  name: rspec_junit_formatter
101
101
  requirement: !ruby/object:Gem::Requirement
102
102
  requirements:
103
- - - "~>"
103
+ - - ">="
104
104
  - !ruby/object:Gem::Version
105
- version: 0.4.1
105
+ version: '0'
106
106
  type: :development
107
107
  prerelease: false
108
108
  version_requirements: !ruby/object:Gem::Requirement
109
109
  requirements:
110
- - - "~>"
110
+ - - ">="
111
111
  - !ruby/object:Gem::Version
112
- version: 0.4.1
112
+ version: '0'
113
113
  description: Names your vcr cassettes based on your rspec examples and let's you pass
114
114
  in options on the fly
115
115
  email:
@@ -122,7 +122,6 @@ files:
122
122
  - ".gitignore"
123
123
  - ".rspec"
124
124
  - ".ruby-version"
125
- - ".travis.yml"
126
125
  - CHANGELOG.md
127
126
  - Gemfile
128
127
  - Gemfile.lock
@@ -134,6 +133,7 @@ files:
134
133
  - lib/nxt_vcr_harness.rb
135
134
  - lib/nxt_vcr_harness/cassette_name_by_example.rb
136
135
  - lib/nxt_vcr_harness/cassette_tracker.rb
136
+ - lib/nxt_vcr_harness/unneeded_headers.rb
137
137
  - lib/nxt_vcr_harness/version.rb
138
138
  - nxt_vcr_harness.gemspec
139
139
  homepage: https://github.com/nxt-insurance
@@ -144,7 +144,7 @@ metadata:
144
144
  homepage_uri: https://github.com/nxt-insurance
145
145
  source_code_uri: https://github.com/nxt-insurance/nxt_vcr_harness
146
146
  changelog_uri: https://github.com/nxt-insurance/nxt_vcr_harness/CHANGELOG.md
147
- post_install_message:
147
+ post_install_message:
148
148
  rdoc_options: []
149
149
  require_paths:
150
150
  - lib
@@ -159,8 +159,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
159
159
  - !ruby/object:Gem::Version
160
160
  version: '0'
161
161
  requirements: []
162
- rubygems_version: 3.1.4
163
- signing_key:
162
+ rubygems_version: 3.4.10
163
+ signing_key:
164
164
  specification_version: 4
165
165
  summary: Intuitive VCR cassette naming
166
166
  test_files: []
data/.travis.yml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- sudo: false
3
- language: ruby
4
- cache: bundler
5
- rvm:
6
- - 2.6.1
7
- before_install: gem install bundler -v 1.17.2