VcrToCurl 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bfa008a2b036bb8b714523639e5192b41cdb694e
4
+ data.tar.gz: d452aa05bdd71bae3d44412fb6eb7de2ce2244c3
5
+ SHA512:
6
+ metadata.gz: d466e768d529cc12fd2cf6b2cee4762887aa56eb07aa32761b1b575f3e0044ab56f3337b3d399abc6572e37c811fbf1f1d4d7050d3edbd12b5ce58caeb1a3283
7
+ data.tar.gz: af1ac20f88cc550ce876cbbec1abd6a26dcd2f5c001040a93d4de46dc12e92ef580557c6035a6e6f46f34e443720d1cc904097ad1163c5170f22252ef7e8f91d
@@ -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
@@ -0,0 +1,2 @@
1
+ --format progress
2
+ --color
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - 2.1.0
6
+ script: rspec spec
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in VcrToCurl.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Yan Lhert
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,38 @@
1
+ # VcrToCurl
2
+ [![Build Status](https://travis-ci.org/yanismydj/vcr_to_curl.svg?branch=master)](https://travis-ci.org/yanismydj/vcr_to_curl)
3
+
4
+ Use this gem to convert vcr cassettes into curl commands. Great for replaying requests in your tests
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'VcrToCurl'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install VcrToCurl
19
+
20
+ ## Usage
21
+
22
+ ### Command Line Utility
23
+ ```
24
+ $ convert_cassette path/to/vcr_cassette_here.yml
25
+ curl -X POST -d 'fizz=buzz&foo=bar' http://echo.httpkit.com/
26
+ ```
27
+
28
+ ### In your codez
29
+ `cassette_to_curl = VcrToCurl::CassetteToCurl.new('your_cassette_here.yml')`
30
+ `cassette_to_curl.curl_commands` => an array of curl commands for interactions in this cassette
31
+
32
+ ## Contributing
33
+
34
+ 1. Fork it ( https://github.com/[my-github-username]/VcrToCurl/fork )
35
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
36
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
37
+ 4. Push to the branch (`git push origin my-new-feature`)
38
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'VcrToCurl/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "VcrToCurl"
8
+ spec.version = VcrToCurl::VERSION
9
+ spec.authors = ["Yan Lhert"]
10
+ spec.email = ["info@yanlhert.com"]
11
+ spec.summary = %q{Turn VCR cassettes into curl commands}
12
+ spec.description = %q{This gem allows you to take a vcr
13
+ cassette and turn it into a curl command}
14
+ spec.homepage = "https://github.com/yanismydj/vcr_to_curl"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0")
18
+ spec.executables = ['convert_cassette']
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.6"
23
+ spec.add_development_dependency "rake", "~> 0.8"
24
+ spec.add_development_dependency "rspec", "~> 2.6"
25
+ spec.add_development_dependency "vcr", "~> 2.9"
26
+ spec.add_development_dependency "httparty", "~> 0.13"
27
+ spec.add_development_dependency "webmock", "~> 1.18"
28
+ spec.add_development_dependency "pry", "~> 0.9"
29
+ end
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'VcrToCurl'
5
+
6
+ cassette = ARGV[0]
7
+ vcr_to_curl = VcrToCurl::CassetteToCurl.new(cassette)
8
+ vcr_to_curl.curl_commands.each do |curl_command|
9
+ puts curl_command
10
+ end
@@ -0,0 +1,53 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://echo.httpkit.com/
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
+ Server:
16
+ - nginx/1.1.19
17
+ Date:
18
+ - Mon, 03 Nov 2014 23:33:26 GMT
19
+ Content-Type:
20
+ - application/json; charset=utf-8
21
+ Content-Length:
22
+ - '407'
23
+ Connection:
24
+ - keep-alive
25
+ X-Powered-By:
26
+ - http://httpkit.com
27
+ Vary:
28
+ - Accept-Encoding
29
+ body:
30
+ encoding: UTF-8
31
+ string: |-
32
+ {
33
+ "method": "POST",
34
+ "uri": "/",
35
+ "path": {
36
+ "name": "/",
37
+ "query": "",
38
+ "params": {}
39
+ },
40
+ "headers": {
41
+ "x-forwarded-for": "50.254.144.14",
42
+ "host": "echo.httpkit.com",
43
+ "content-length": "17",
44
+ "content-type": "application/x-www-form-urlencoded"
45
+ },
46
+ "body": "fizz=buzz&foo=bar",
47
+ "ip": "127.0.0.1",
48
+ "powered-by": "http://httpkit.com",
49
+ "docs": "http://httpkit.com/echo"
50
+ }
51
+ http_version:
52
+ recorded_at: Mon, 03 Nov 2014 22:50:08 GMT
53
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,56 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://echo.httpkit.com/
6
+ body:
7
+ encoding: UTF-8
8
+ string: ''
9
+ headers:
10
+ Yan:
11
+ - isawesome
12
+ response:
13
+ status:
14
+ code: 200
15
+ message: OK
16
+ headers:
17
+ Server:
18
+ - nginx/1.1.19
19
+ Date:
20
+ - Mon, 03 Nov 2014 23:33:26 GMT
21
+ Content-Type:
22
+ - application/json; charset=utf-8
23
+ Content-Length:
24
+ - '415'
25
+ Connection:
26
+ - keep-alive
27
+ X-Powered-By:
28
+ - http://httpkit.com
29
+ Vary:
30
+ - Accept-Encoding
31
+ body:
32
+ encoding: UTF-8
33
+ string: |-
34
+ {
35
+ "method": "POST",
36
+ "uri": "/",
37
+ "path": {
38
+ "name": "/",
39
+ "query": "",
40
+ "params": {}
41
+ },
42
+ "headers": {
43
+ "x-forwarded-for": "50.254.144.14",
44
+ "host": "echo.httpkit.com",
45
+ "yan": "isawesome",
46
+ "content-length": "0",
47
+ "content-type": "application/x-www-form-urlencoded"
48
+ },
49
+ "body": null,
50
+ "ip": "127.0.0.1",
51
+ "powered-by": "http://httpkit.com",
52
+ "docs": "http://httpkit.com/echo"
53
+ }
54
+ http_version:
55
+ recorded_at: Mon, 03 Nov 2014 22:50:08 GMT
56
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,56 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://echo.httpkit.com/
6
+ body:
7
+ encoding: UTF-8
8
+ string: foo=blah
9
+ headers:
10
+ Yan:
11
+ - isawesome
12
+ response:
13
+ status:
14
+ code: 200
15
+ message: OK
16
+ headers:
17
+ Server:
18
+ - nginx/1.1.19
19
+ Date:
20
+ - Mon, 03 Nov 2014 23:33:26 GMT
21
+ Content-Type:
22
+ - application/json; charset=utf-8
23
+ Content-Length:
24
+ - '421'
25
+ Connection:
26
+ - keep-alive
27
+ X-Powered-By:
28
+ - http://httpkit.com
29
+ Vary:
30
+ - Accept-Encoding
31
+ body:
32
+ encoding: UTF-8
33
+ string: |-
34
+ {
35
+ "method": "POST",
36
+ "uri": "/",
37
+ "path": {
38
+ "name": "/",
39
+ "query": "",
40
+ "params": {}
41
+ },
42
+ "headers": {
43
+ "x-forwarded-for": "50.254.144.14",
44
+ "host": "echo.httpkit.com",
45
+ "yan": "isawesome",
46
+ "content-length": "8",
47
+ "content-type": "application/x-www-form-urlencoded"
48
+ },
49
+ "body": "foo=blah",
50
+ "ip": "127.0.0.1",
51
+ "powered-by": "http://httpkit.com",
52
+ "docs": "http://httpkit.com/echo"
53
+ }
54
+ http_version:
55
+ recorded_at: Mon, 03 Nov 2014 22:50:08 GMT
56
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,5 @@
1
+ require "VcrToCurl/version"
2
+ require "VcrToCurl/cassette_to_curl"
3
+
4
+ module VcrToCurl
5
+ end
@@ -0,0 +1,56 @@
1
+ require 'yaml'
2
+
3
+ module VcrToCurl
4
+ class CassetteToCurl
5
+ def initialize(cassette_file)
6
+ @loaded_cassette = ::YAML.load_file(cassette_file)
7
+ end
8
+
9
+ def curl_commands
10
+ http_interactions.map do |http_interaction|
11
+ convert_request_to_curl(http_interaction["request"])
12
+ end
13
+ end
14
+
15
+ def convert_request_to_curl(request)
16
+ curl_command = "curl -X #{request_type(request)} "
17
+ curl_command += request_data(request) if has_data?(request)
18
+ curl_command += request_headers(request) if has_headers?(request)
19
+ curl_command += request_url(request)
20
+ curl_command
21
+ end
22
+
23
+ def http_interactions
24
+ @loaded_cassette['http_interactions']
25
+ end
26
+
27
+ private
28
+ def has_data?(request)
29
+ request["body"]["string"].length > 0
30
+ end
31
+
32
+ def has_headers?(request)
33
+ request["headers"].keys.size > 0
34
+ end
35
+
36
+ def request_type(request)
37
+ request["method"].upcase
38
+ end
39
+
40
+ def request_url(request)
41
+ request["uri"]
42
+ end
43
+
44
+ def request_data(request)
45
+ "-d '#{request["body"]["string"]}' "
46
+ end
47
+
48
+ def request_headers(request)
49
+ header_string = ''
50
+ request["headers"].each do |key, value|
51
+ header_string += "-H '#{key.capitalize}: #{value[0]}' "
52
+ end
53
+ header_string
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,3 @@
1
+ module VcrToCurl
2
+ VERSION = "0.0.6"
3
+ end
@@ -0,0 +1,77 @@
1
+ require 'vcr'
2
+ require 'httparty'
3
+ require 'webmock'
4
+ require 'pry'
5
+ require 'VcrToCurl'
6
+
7
+ VCR.configure do |c|
8
+ c.cassette_library_dir = 'fixtures/vcr_cassettes'
9
+ c.hook_into :webmock
10
+ end
11
+
12
+ describe VcrToCurl::CassetteToCurl do
13
+ describe '#curl_commands' do
14
+ describe 'request with body and no headers' do
15
+ let(:cassette) { 'fixtures/vcr_cassettes/sample_vcr_cassette.yml' }
16
+ let(:vcr_to_curl) { VcrToCurl::CassetteToCurl.new(cassette) }
17
+
18
+ it 'has the correct_number of commands based on the interactions' do
19
+ expect(vcr_to_curl.curl_commands.length).to eq(1)
20
+ end
21
+
22
+ it "converts the interaction to curl command" do
23
+ curl_command = vcr_to_curl.curl_commands[0]
24
+ expect(curl_command).to eq("curl -X POST -d 'fizz=buzz&foo=bar' http://echo.httpkit.com/")
25
+ end
26
+
27
+ describe '#http_interactions' do
28
+ it 'has the correct number of interactions' do
29
+ expect(vcr_to_curl.http_interactions.length).to eq(1)
30
+ end
31
+ end
32
+ end
33
+
34
+ describe 'request with headers and no body' do
35
+ let(:cassette) { 'fixtures/vcr_cassettes/sample_vcr_cassette_with_headers.yml' }
36
+ let(:vcr_to_curl) { VcrToCurl::CassetteToCurl.new(cassette) }
37
+
38
+ it 'creates the correct curl command' do
39
+ curl_command = vcr_to_curl.curl_commands[0]
40
+ expect(curl_command).to eq("curl -X POST -H 'Yan: isawesome' http://echo.httpkit.com/")
41
+ end
42
+ end
43
+
44
+ describe 'request with headers and body' do
45
+ let(:cassette) { 'fixtures/vcr_cassettes/sample_vcr_cassette_with_headers_and_post_data.yml' }
46
+ let(:vcr_to_curl) { VcrToCurl::CassetteToCurl.new(cassette) }
47
+
48
+ it 'creates the correct curl command' do
49
+ curl_command = vcr_to_curl.curl_commands[0]
50
+ expect(curl_command).to eq("curl -X POST -d 'foo=blah' -H 'Yan: isawesome' http://echo.httpkit.com/")
51
+ end
52
+ end
53
+ end
54
+
55
+ describe 'create sample cassettes' do
56
+ it 'creates a new cassette' do
57
+ VCR.use_cassette('sample vcr cassette') do
58
+ uri = 'http://echo.httpkit.com'
59
+ response = HTTParty.post(uri, body: { 'fizz' => 'buzz', 'foo' => 'bar' })
60
+ end
61
+ end
62
+
63
+ it 'creates a cassette with headers' do
64
+ VCR.use_cassette('sample vcr cassette with headers') do
65
+ uri = 'http://echo.httpkit.com'
66
+ response = HTTParty.post(uri, headers: { 'Yan' => 'isawesome' })
67
+ end
68
+ end
69
+
70
+ it 'creates a cassette with headers and post data' do
71
+ VCR.use_cassette('sample vcr cassette with headers and post data') do
72
+ uri = 'http://echo.httpkit.com'
73
+ response = HTTParty.post(uri, headers: { 'Yan' => 'isawesome' }, body: { foo: "blah"})
74
+ end
75
+ end
76
+ end
77
+ end
metadata ADDED
@@ -0,0 +1,163 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: VcrToCurl
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.6
5
+ platform: ruby
6
+ authors:
7
+ - Yan Lhert
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.8'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.8'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.6'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: vcr
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.9'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.9'
69
+ - !ruby/object:Gem::Dependency
70
+ name: httparty
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.13'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.13'
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.18'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.18'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.9'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.9'
111
+ description: |-
112
+ This gem allows you to take a vcr
113
+ cassette and turn it into a curl command
114
+ email:
115
+ - info@yanlhert.com
116
+ executables:
117
+ - convert_cassette
118
+ extensions: []
119
+ extra_rdoc_files: []
120
+ files:
121
+ - ".gitignore"
122
+ - ".rspec"
123
+ - ".travis.yml"
124
+ - Gemfile
125
+ - LICENSE.txt
126
+ - README.md
127
+ - Rakefile
128
+ - VcrToCurl.gemspec
129
+ - bin/convert_cassette
130
+ - fixtures/vcr_cassettes/sample_vcr_cassette.yml
131
+ - fixtures/vcr_cassettes/sample_vcr_cassette_with_headers.yml
132
+ - fixtures/vcr_cassettes/sample_vcr_cassette_with_headers_and_post_data.yml
133
+ - lib/VcrToCurl.rb
134
+ - lib/VcrToCurl/cassette_to_curl.rb
135
+ - lib/VcrToCurl/version.rb
136
+ - spec/cassette_to_curl_spec.rb
137
+ homepage: https://github.com/yanismydj/vcr_to_curl
138
+ licenses:
139
+ - MIT
140
+ metadata: {}
141
+ post_install_message:
142
+ rdoc_options: []
143
+ require_paths:
144
+ - lib
145
+ required_ruby_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ required_rubygems_version: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ requirements: []
156
+ rubyforge_project:
157
+ rubygems_version: 2.2.2
158
+ signing_key:
159
+ specification_version: 4
160
+ summary: Turn VCR cassettes into curl commands
161
+ test_files:
162
+ - spec/cassette_to_curl_spec.rb
163
+ has_rdoc: