vcr-rcv 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/.rspec +2 -0
- data/.travis.yml +7 -0
- data/Gemfile +3 -0
- data/Rakefile +9 -0
- data/bin/reverse_play_cassette +22 -0
- data/fixtures/sample_cassette.yml +32 -0
- data/lib/rcv/cassette.rb +67 -0
- data/lib/rcv/spec.rb +50 -0
- data/lib/rcv/version.rb +3 -0
- data/lib/rcv.rb +6 -0
- data/lib/vcr-rcv.rb +1 -0
- data/lib/vcr_rcv.rb +1 -0
- data/spec/cassette_minitest_spec.rb +10 -0
- data/spec/cassette_rspec_spec.rb +11 -0
- data/vcr-rcv.gemspec +26 -0
- metadata +135 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f3f773d05ede71d3df622960185d458129db42c3
|
4
|
+
data.tar.gz: ec2ca4b569ef57a397a54ec112efe35b92db6bfb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: efe10034e3354d3bce8f16761f117f03bec17c8042560f7ec434fc69c8e9e09c949d944bf6b4b9029ec84f84ecd96949c202b6e33136c1a296d8f0b0c5010c2b
|
7
|
+
data.tar.gz: c2b78583e305cef6f2900fc68e3532c1614b75dc9430899a5e1c21bfdc03fce0f1430ea303cfa07b2ec74bcac88e778c78952666f5873971a02d85b5ad23345a
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'minitest'
|
5
|
+
require 'rcv'
|
6
|
+
|
7
|
+
cassette = ARGV[0]
|
8
|
+
c = RCV::Cassette.new(cassette)
|
9
|
+
puts "REVERSE PLAY: #{cassette}"
|
10
|
+
failed = false
|
11
|
+
include MiniTest::Assertions
|
12
|
+
c.reverse_play.each_with_index do |(request, actual, expected), i|
|
13
|
+
puts "\t#{i}: #{request[:url]}\n"
|
14
|
+
if actual != expected
|
15
|
+
puts "\t#{i}: FAIL"
|
16
|
+
puts diff(actual, expected)
|
17
|
+
else
|
18
|
+
puts "\t#{i}: PASS"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
exit(1) if failed
|
@@ -0,0 +1,32 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://gist.githubusercontent.com/jondot/fa16c8dc58257c714341/raw/5fb566a7bac94251d4e503620cdd4d71727da54d/foo.json
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: fizz=buzz&foo=bar
|
9
|
+
headers: {}
|
10
|
+
response:
|
11
|
+
status:
|
12
|
+
code: 200
|
13
|
+
message: OK
|
14
|
+
headers:
|
15
|
+
Via:
|
16
|
+
- '1.1 varnish'
|
17
|
+
Cache-Control:
|
18
|
+
- max-age=300
|
19
|
+
ETag:
|
20
|
+
- '"ccffbceabd82468747f7f11eb46a3b798c5a5c68"'
|
21
|
+
Connection:
|
22
|
+
- keep-alive
|
23
|
+
body:
|
24
|
+
encoding: UTF-8
|
25
|
+
string: |-
|
26
|
+
{
|
27
|
+
"foo":1,
|
28
|
+
"bar":2
|
29
|
+
}
|
30
|
+
http_version:
|
31
|
+
recorded_at: Mon, 03 Nov 2014 22:50:08 GMT
|
32
|
+
recorded_with: VCR 2.9.3
|
data/lib/rcv/cassette.rb
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'rest-client'
|
3
|
+
require 'diffy'
|
4
|
+
|
5
|
+
module RCV
|
6
|
+
module HeaderDowncaser
|
7
|
+
def self.downcase_headers(headers)
|
8
|
+
{}.tap do |downcased|
|
9
|
+
headers.each do |k, v|
|
10
|
+
downcased[k.downcase] = v
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class Cassette
|
17
|
+
def initialize(cassette_file)
|
18
|
+
@loaded_cassette = ::YAML.load_file(cassette_file)
|
19
|
+
end
|
20
|
+
|
21
|
+
def reverse_play
|
22
|
+
@loaded_cassette['http_interactions'].map do |http_interaction|
|
23
|
+
reverse_play_interaction(http_interaction)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def reverse_play_interaction(interaction)
|
28
|
+
request = interaction["request"]
|
29
|
+
response = interaction["response"]
|
30
|
+
|
31
|
+
req = {
|
32
|
+
method: request["method"].to_sym,
|
33
|
+
url: request["uri"]
|
34
|
+
}
|
35
|
+
req[:payload] = request["body"]["string"] if has_data?(request)
|
36
|
+
req[:headers] = request["headers"] if has_headers?(request)
|
37
|
+
|
38
|
+
# normalize vcr headers as well
|
39
|
+
res = RestClient::Request.execute(req)
|
40
|
+
vcr_response = {
|
41
|
+
status: response["status"]["code"],
|
42
|
+
headers: HeaderDowncaser.downcase_headers(response["headers"]),
|
43
|
+
body: response["body"]["string"]
|
44
|
+
}
|
45
|
+
backend_response = {
|
46
|
+
status: res.code,
|
47
|
+
headers: slice(HeaderDowncaser.downcase_headers(res.raw_headers), *vcr_response[:headers].keys),
|
48
|
+
body: res.to_str
|
49
|
+
}
|
50
|
+
[req, backend_response, vcr_response]
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
def slice(source, *keys)
|
55
|
+
keys.map! { |key| source.convert_key(key) } if source.respond_to?(:convert_key, true)
|
56
|
+
keys.each_with_object(source.class.new) { |k, hash| hash[k] = source[k] if source.has_key?(k) }
|
57
|
+
end
|
58
|
+
|
59
|
+
def has_data?(request)
|
60
|
+
request["body"]["string"].length > 0
|
61
|
+
end
|
62
|
+
|
63
|
+
def has_headers?(request)
|
64
|
+
request["headers"].keys.size > 0
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
data/lib/rcv/spec.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
module RCV
|
2
|
+
module Spec
|
3
|
+
def make_expectation
|
4
|
+
raise "implement this"
|
5
|
+
end
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
def should_reverse_play(cassette_file)
|
9
|
+
describe "cassette: #{cassette_file}" do
|
10
|
+
results = RCV::Cassette.new(cassette_file).reverse_play
|
11
|
+
results.each_with_index do |(request, actual, expected), i|
|
12
|
+
describe "#{i}: #{request[:method]} #{request[:url]}" do
|
13
|
+
it "should match status" do
|
14
|
+
make_expectation(*[actual, expected].map{|h| h[:status]})
|
15
|
+
end
|
16
|
+
it "should match headers" do
|
17
|
+
expected[:headers].each do |k,v|
|
18
|
+
make_expectation actual[:headers][k], v
|
19
|
+
end
|
20
|
+
end
|
21
|
+
it "should match body" do
|
22
|
+
make_expectation(*[actual, expected].map{|h| h[:body]})
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
module MiniTest
|
32
|
+
include Spec
|
33
|
+
def self.included(base)
|
34
|
+
base.extend(self::ClassMethods)
|
35
|
+
end
|
36
|
+
def make_expectation(actual, expected)
|
37
|
+
actual.must_equal(expected)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
module RSpec
|
42
|
+
include Spec
|
43
|
+
def self.included(base)
|
44
|
+
base.extend(self::ClassMethods)
|
45
|
+
end
|
46
|
+
def make_expectation(actual, expected)
|
47
|
+
expect(actual).to eq(expected)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/lib/rcv/version.rb
ADDED
data/lib/rcv.rb
ADDED
data/lib/vcr-rcv.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'rcv'
|
data/lib/vcr_rcv.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'rcv'
|
data/vcr-rcv.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rcv/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "vcr-rcv"
|
8
|
+
spec.version = RCV::VERSION
|
9
|
+
spec.authors = ["Dotan Nahum"]
|
10
|
+
spec.email = ["jondotan@gmail.com"]
|
11
|
+
spec.summary = %q{VCR in reverse. Use RCV to do consumer driven contract testing with your existing VCR tests}
|
12
|
+
spec.description = %q{VCR in reverse. Use RCV to do consumer driven contract testing with your existing VCR tests}
|
13
|
+
spec.homepage = "https://github.com/jondot/rcv"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = ['reverse_play_cassette']
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
spec.add_runtime_dependency "rest-client", "~> 2.0.0.rc2"
|
21
|
+
spec.add_runtime_dependency "minitest", "~> 5.8.4"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
24
|
+
spec.add_development_dependency "rake", "~> 0.8"
|
25
|
+
spec.add_development_dependency "rspec", "~> 2.6"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vcr-rcv
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dotan Nahum
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-03-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rest-client
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.0.0.rc2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.0.0.rc2
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: minitest
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 5.8.4
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 5.8.4
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.6'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.6'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.8'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.8'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '2.6'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '2.6'
|
83
|
+
description: VCR in reverse. Use RCV to do consumer driven contract testing with your
|
84
|
+
existing VCR tests
|
85
|
+
email:
|
86
|
+
- jondotan@gmail.com
|
87
|
+
executables:
|
88
|
+
- reverse_play_cassette
|
89
|
+
extensions: []
|
90
|
+
extra_rdoc_files: []
|
91
|
+
files:
|
92
|
+
- ".gitignore"
|
93
|
+
- ".rspec"
|
94
|
+
- ".travis.yml"
|
95
|
+
- Gemfile
|
96
|
+
- Rakefile
|
97
|
+
- bin/reverse_play_cassette
|
98
|
+
- fixtures/sample_cassette.yml
|
99
|
+
- lib/rcv.rb
|
100
|
+
- lib/rcv/cassette.rb
|
101
|
+
- lib/rcv/spec.rb
|
102
|
+
- lib/rcv/version.rb
|
103
|
+
- lib/vcr-rcv.rb
|
104
|
+
- lib/vcr_rcv.rb
|
105
|
+
- spec/cassette_minitest_spec.rb
|
106
|
+
- spec/cassette_rspec_spec.rb
|
107
|
+
- vcr-rcv.gemspec
|
108
|
+
homepage: https://github.com/jondot/rcv
|
109
|
+
licenses:
|
110
|
+
- MIT
|
111
|
+
metadata: {}
|
112
|
+
post_install_message:
|
113
|
+
rdoc_options: []
|
114
|
+
require_paths:
|
115
|
+
- lib
|
116
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
requirements: []
|
127
|
+
rubyforge_project:
|
128
|
+
rubygems_version: 2.5.1
|
129
|
+
signing_key:
|
130
|
+
specification_version: 4
|
131
|
+
summary: VCR in reverse. Use RCV to do consumer driven contract testing with your
|
132
|
+
existing VCR tests
|
133
|
+
test_files:
|
134
|
+
- spec/cassette_minitest_spec.rb
|
135
|
+
- spec/cassette_rspec_spec.rb
|