response_mate 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +1 -0
- data/Gemfile.lock +0 -2
- data/README.md +12 -35
- data/lib/response_mate/cli.rb +0 -1
- data/lib/response_mate/commands.rb +9 -0
- data/lib/response_mate/connection.rb +1 -1
- data/lib/response_mate/core.rb +2 -3
- data/lib/response_mate/exporters/postman/collection.rb +18 -23
- data/lib/response_mate/exporters/postman.rb +2 -1
- data/lib/response_mate/exporters.rb +3 -0
- data/lib/response_mate/manifest.rb +3 -3
- data/lib/response_mate/request.rb +1 -1
- data/lib/response_mate/tape.rb +16 -4
- data/lib/response_mate/version.rb +1 -1
- data/lib/response_mate.rb +15 -26
- data/response_mate.gemspec +0 -1
- data/spec/lib/response_mate/exporters/postman/collection_spec.rb +116 -0
- data/spec/lib/response_mate/tape_spec.rb +125 -0
- data/spec/source/requests.yml +7 -0
- metadata +8 -21
- data/lib/response_mate/helpers/application.rb +0 -5
- data/lib/response_mate/http.rb +0 -43
- data/lib/response_mate/manifest_parser.rb +0 -9
data/.travis.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -43,7 +43,6 @@ GEM
|
|
43
43
|
debugger-ruby_core_source (1.3.5)
|
44
44
|
diff-lcs (1.2.5)
|
45
45
|
docile (1.1.1)
|
46
|
-
fakefs (0.4.3)
|
47
46
|
fakeweb (1.2.8)
|
48
47
|
faraday (0.9.0)
|
49
48
|
multipart-post (>= 1.2, < 3)
|
@@ -131,7 +130,6 @@ PLATFORMS
|
|
131
130
|
DEPENDENCIES
|
132
131
|
bundler (~> 1.3)
|
133
132
|
coveralls
|
134
|
-
fakefs
|
135
133
|
fakeweb (~> 1.2.8)
|
136
134
|
guard-rspec
|
137
135
|
guard-rubocop
|
data/README.md
CHANGED
@@ -4,6 +4,7 @@
|
|
4
4
|
[![Code Climate](https://codeclimate.com/github/Zorbash/response_mate.png)](https://codeclimate.com/github/Zorbash/response_mate)
|
5
5
|
[![Dependencies tatus](https://gemnasium.com/Zorbash/response_mate.png)](https://gemnasium.com/Zorbash/response_mate)
|
6
6
|
[![Coverage Status](https://coveralls.io/repos/Zorbash/response_mate/badge.png?branch=master)](https://coveralls.io/r/Zorbash/response_mate?branch=master)
|
7
|
+
[![Build Status](https://travis-ci.org/Zorbash/response_mate.svg)](https://travis-ci.org/Zorbash/response_mate)
|
7
8
|
|
8
9
|
ResponseMate is a command line tool that aims to make inspecting and
|
9
10
|
recording HTTP requests/responses. It is designed with APIs in mind.
|
@@ -23,32 +24,30 @@ A specific directory structure must be present to store the recordings.
|
|
23
24
|
To scaffold it do:
|
24
25
|
`response_mate setup`
|
25
26
|
|
26
|
-
ResponseMate's tasks heavily depend on a manifest file where you declare
|
27
|
+
ResponseMate's tasks heavily depend on a manifest file where you declare
|
27
28
|
the requests to be made. The default expected filename of this manifest
|
28
29
|
is `requests.yml`.
|
29
|
-
The expected format of this file is like [this](https://gist.github.com/anonymous/8055040)
|
30
30
|
|
31
31
|
Example:
|
32
32
|
|
33
33
|
```yaml
|
34
|
-
base_url: http://localhost:3000/api
|
35
34
|
default_headers:
|
36
|
-
accept: 'application/vnd.
|
35
|
+
accept: 'application/vnd.{{app_name}}.beta+json'
|
37
36
|
requests:
|
38
|
-
-
|
39
|
-
key: user_repos
|
40
|
-
request: 'GET /user/repos'
|
41
37
|
-
|
42
38
|
key: user_issues
|
43
39
|
request:
|
44
|
-
|
45
|
-
params:
|
46
|
-
sort: 'updated'
|
40
|
+
url: 'http://someapi.com/users/42/issues
|
47
41
|
-
|
48
|
-
key:
|
49
|
-
request:
|
50
|
-
|
42
|
+
key: user_friends
|
43
|
+
request:
|
44
|
+
url: 'http://someapi.com/users/42/friends'
|
45
|
+
params:
|
46
|
+
since: 'childhood'
|
47
|
+
honest: '{{are_my_friends_host}}'
|
51
48
|
```
|
49
|
+
Expressions inside `{{}}` will be evaluated as Mustache templates using
|
50
|
+
values from a file `environment.yml` that may be present.
|
52
51
|
|
53
52
|
## Record
|
54
53
|
### Default
|
@@ -64,10 +63,6 @@ Record all the keys of the requests manifest file being `requests.yml`
|
|
64
63
|
|
65
64
|
`response_mate record -r foo_api.yml`
|
66
65
|
|
67
|
-
### Specify a different base url for the requests
|
68
|
-
|
69
|
-
`response_mate record -b http://api.foo.com`
|
70
|
-
|
71
66
|
## Clear
|
72
67
|
|
73
68
|
Remove any existing recordings
|
@@ -80,20 +75,6 @@ Performs the request and displays the output without recording
|
|
80
75
|
|
81
76
|
`response_mate inspect some_key`
|
82
77
|
|
83
|
-
### Interactive mode
|
84
|
-
|
85
|
-
`response_mate inspect -i`
|
86
|
-
|
87
|
-
Starts a `response_mate>` interactive shell that allows you to issue
|
88
|
-
requests and inspect their output.
|
89
|
-
|
90
|
-
Examples:
|
91
|
-
|
92
|
-
`>response_mate GET google.com`
|
93
|
-
|
94
|
-
Also you can type `history` in the shell to get the history of requests
|
95
|
-
and replay any of them.
|
96
|
-
|
97
78
|
## List
|
98
79
|
|
99
80
|
Lists existing recordings
|
@@ -132,7 +113,3 @@ Exports a requests manifest file to a different format
|
|
132
113
|
Released under the MIT License. See the
|
133
114
|
[LICENSE](https://github.com/Zorbash/response_mate/blob/master/LICENSE) file
|
134
115
|
for further details.
|
135
|
-
|
136
|
-
|
137
|
-
[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/Zorbash/response_mate/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
|
138
|
-
|
data/lib/response_mate/cli.rb
CHANGED
@@ -15,7 +15,6 @@ module ResponseMate
|
|
15
15
|
|
16
16
|
desc 'inspect [key1,key2]', 'Perform requests and print their output'
|
17
17
|
method_option :requests_manifest, aliases: '-r'
|
18
|
-
method_option :interactive, type: :boolean, aliases: '-i'
|
19
18
|
def inspect(*keys)
|
20
19
|
ResponseMate::Commands::Inspect.new(args, options).run
|
21
20
|
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
module ResponseMate::Commands
|
2
|
+
autoload :Base, 'response_mate/commands/base'
|
3
|
+
autoload :Record, 'response_mate/commands/record'
|
4
|
+
autoload :Inspect, 'response_mate/commands/inspect'
|
5
|
+
autoload :List, 'response_mate/commands/list'
|
6
|
+
autoload :Export, 'response_mate/commands/export'
|
7
|
+
autoload :Setup, 'response_mate/commands/setup'
|
8
|
+
autoload :Clear, 'response_mate/commands/clear'
|
9
|
+
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
# This class provides a layer above the HTTP client
|
4
4
|
class ResponseMate::Connection
|
5
5
|
delegate :params, to: :client
|
6
|
-
delegate(*(ResponseMate::
|
6
|
+
delegate(*(ResponseMate::HTTP_METHODS), to: :client)
|
7
7
|
|
8
8
|
attr_accessor :client
|
9
9
|
|
data/lib/response_mate/core.rb
CHANGED
@@ -4,9 +4,8 @@ module ResponseMate
|
|
4
4
|
class OutputDirError < StandardError; end
|
5
5
|
class KeysNotFound < StandardError; end
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
}
|
7
|
+
HTTP_METHODS = %w(GET POST PUT PATCH DELETE HEAD OPTIONS)
|
8
|
+
DEFAULT_HEADERS = { 'User-Agent' => 'Response-Mate' }
|
10
9
|
|
11
10
|
class << self
|
12
11
|
attr_accessor :configuration
|
@@ -5,8 +5,6 @@ class ResponseMate::Exporters::Postman
|
|
5
5
|
# Example output
|
6
6
|
# https://www.getpostman.com/collections/dbc0521911e45471ff4a
|
7
7
|
class Collection
|
8
|
-
include ResponseMate::ManifestParser
|
9
|
-
|
10
8
|
attr_accessor :manifest, :out
|
11
9
|
|
12
10
|
def initialize(manifest)
|
@@ -26,6 +24,7 @@ class ResponseMate::Exporters::Postman
|
|
26
24
|
out.merge!(
|
27
25
|
id: SecureRandom.uuid,
|
28
26
|
name: manifest.name,
|
27
|
+
description: manifest.description,
|
29
28
|
requests: [],
|
30
29
|
order: [],
|
31
30
|
timestamp: Time.now.to_i
|
@@ -34,31 +33,27 @@ class ResponseMate::Exporters::Postman
|
|
34
33
|
|
35
34
|
def build_requests
|
36
35
|
manifest.requests.each do |request|
|
37
|
-
|
38
|
-
url = if req[:params].present?
|
39
|
-
"#{req[:path]}?#{req[:params].to_query}"
|
40
|
-
else
|
41
|
-
req[:path]
|
42
|
-
end
|
43
|
-
|
44
|
-
out_req = {
|
45
|
-
id: SecureRandom.uuid,
|
46
|
-
collectionId: out[:id],
|
47
|
-
data: [],
|
48
|
-
description: '',
|
49
|
-
method: req[:verb],
|
50
|
-
name: request.key,
|
51
|
-
url: url,
|
52
|
-
version: 2,
|
53
|
-
responses: [],
|
54
|
-
dataMode: 'params',
|
55
|
-
headers: (request.headers || manifest.default_headers)
|
56
|
-
.map{|k,v| "#{k}: #{v}" }.join("\n")
|
57
|
-
}
|
36
|
+
out_req = build_request(request)
|
58
37
|
|
59
38
|
out[:order] << out_req[:id]
|
60
39
|
out[:requests] << out_req
|
61
40
|
end
|
62
41
|
end
|
42
|
+
|
43
|
+
def build_request(request)
|
44
|
+
{
|
45
|
+
id: SecureRandom.uuid,
|
46
|
+
collectionId: out[:id],
|
47
|
+
data: [],
|
48
|
+
description: '',
|
49
|
+
method: request[:verb],
|
50
|
+
name: request.key,
|
51
|
+
url: request[:url],
|
52
|
+
version: 2,
|
53
|
+
responses: [],
|
54
|
+
dataMode: 'params',
|
55
|
+
headers: request[:headers].map { |k, v| "#{k}: #{v}" }.join("\n")
|
56
|
+
}
|
57
|
+
end
|
63
58
|
end
|
64
59
|
end
|
@@ -5,7 +5,8 @@ module ResponseMate::Exporters
|
|
5
5
|
# Example output
|
6
6
|
# https://www.getpostman.com/collections/dbc0521911e45471ff4a
|
7
7
|
class Postman
|
8
|
-
|
8
|
+
autoload :Collection, 'response_mate/exporters/postman/collection'
|
9
|
+
autoload :Environment, 'response_mate/exporters/postman/environment'
|
9
10
|
|
10
11
|
attr_accessor :manifest, :environment, :resource, :out
|
11
12
|
|
@@ -1,9 +1,8 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
3
|
class ResponseMate::Manifest
|
4
|
-
|
5
|
-
|
6
|
-
attr_accessor :filename, :requests, :requests_text, :environment, :name
|
4
|
+
attr_accessor :filename, :requests, :requests_text, :environment
|
5
|
+
attr_reader :name, :description
|
7
6
|
|
8
7
|
def initialize(filename, environment = nil)
|
9
8
|
@filename = filename || ResponseMate.configuration.requests_manifest
|
@@ -28,6 +27,7 @@ class ResponseMate::Manifest
|
|
28
27
|
preprocess_manifest
|
29
28
|
@request_hashes = YAML.load(requests_text).deep_symbolize_keys
|
30
29
|
@name = @request_hashes[:name] || filename
|
30
|
+
@description = @request_hashes[:description] || ''
|
31
31
|
@requests = @request_hashes[:requests].
|
32
32
|
map(&:deep_symbolize_keys!).
|
33
33
|
map { |rh| ResponseMate::Request.new(rh).normalize! }
|
@@ -4,7 +4,7 @@ class ResponseMate::Request < OpenStruct
|
|
4
4
|
delegate :[], to: :request
|
5
5
|
|
6
6
|
def normalize!
|
7
|
-
unless ResponseMate::
|
7
|
+
unless ResponseMate::HTTP_METHODS.include? self.request[:verb]
|
8
8
|
self.request[:verb] = 'GET'
|
9
9
|
end
|
10
10
|
|
data/lib/response_mate/tape.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
class ResponseMate::Tape
|
4
4
|
def write(key, request, response, meta = {})
|
@@ -10,9 +10,10 @@ class ResponseMate::Tape
|
|
10
10
|
request: request.to_hash.select { |_, v| !v.nil? },
|
11
11
|
response: {
|
12
12
|
status: response.status,
|
13
|
-
headers: response.headers,
|
14
|
-
body: response.body
|
15
|
-
}
|
13
|
+
headers: _utf8_encode(response.headers.to_hash),
|
14
|
+
body: _utf8_encode(response.body)
|
15
|
+
},
|
16
|
+
created_at: Time.now
|
16
17
|
}
|
17
18
|
|
18
19
|
file_content.merge!(meta: meta) if meta.present?
|
@@ -23,6 +24,17 @@ class ResponseMate::Tape
|
|
23
24
|
raise ResponseMate::OutputDirError
|
24
25
|
end
|
25
26
|
|
27
|
+
def _utf8_encode(object)
|
28
|
+
case object
|
29
|
+
when String
|
30
|
+
object.force_encoding('UTF-8')
|
31
|
+
when Hash
|
32
|
+
object.each { |k, v| k = _utf8_encode(v); v = _utf8_encode(v) }
|
33
|
+
when Array
|
34
|
+
object.each { |v| _utf8_encode(v) }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
26
38
|
class << self
|
27
39
|
def load(key)
|
28
40
|
YAML.load_file(File.join(ResponseMate.configuration.output_dir, "#{key}.yml")).
|
data/lib/response_mate.rb
CHANGED
@@ -13,32 +13,21 @@ require 'ostruct'
|
|
13
13
|
autoload :YAML, 'yaml'
|
14
14
|
|
15
15
|
require 'response_mate/version'
|
16
|
-
|
17
|
-
require 'response_mate/commands/base'
|
18
|
-
|
19
|
-
# Load all commands
|
20
|
-
Dir.glob(File.join(File.expand_path('..', __FILE__),
|
21
|
-
'response_mate/commands/*')).each(&method(:require))
|
22
|
-
|
23
|
-
# Load all helpers
|
24
|
-
Dir.glob(File.join(File.expand_path('..', __FILE__), 'response_mate/helpers/*')).each(&method(:require))
|
25
|
-
|
26
|
-
require 'response_mate/manifest_parser'
|
27
|
-
require 'response_mate/connection'
|
28
|
-
require 'response_mate/http'
|
29
16
|
require 'response_mate/core'
|
30
|
-
require 'response_mate/
|
31
|
-
require 'response_mate/
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
17
|
+
require 'response_mate/commands'
|
18
|
+
require 'response_mate/exporters'
|
19
|
+
|
20
|
+
module ResponseMate
|
21
|
+
autoload :ManifestParser, 'response_mate/manifest_parser'
|
22
|
+
autoload :Connection, 'response_mate/connection'
|
23
|
+
autoload :Request, 'response_mate/request'
|
24
|
+
autoload :Environment, 'response_mate/environment'
|
25
|
+
autoload :Manifest, 'response_mate/manifest'
|
26
|
+
autoload :Tape, 'response_mate/tape'
|
27
|
+
autoload :Recorder, 'response_mate/recorder'
|
28
|
+
autoload :Inspector, 'response_mate/inspector'
|
29
|
+
autoload :CLI, 'response_mate/cli'
|
30
|
+
autoload :Exporter, 'response_mate/exporter'
|
31
|
+
end
|
43
32
|
|
44
33
|
ResponseMate.setup
|
data/response_mate.gemspec
CHANGED
@@ -0,0 +1,116 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe ResponseMate::Exporters::Postman::Collection do
|
5
|
+
include_context 'stubbed_requests'
|
6
|
+
|
7
|
+
let(:environment) do
|
8
|
+
ResponseMate::Environment.new(ResponseMate.configuration.environment)
|
9
|
+
end
|
10
|
+
|
11
|
+
let(:manifest) do
|
12
|
+
ResponseMate::Manifest.new(ResponseMate.configuration.requests_manifest,
|
13
|
+
environment)
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '#export' do
|
17
|
+
let(:collection) do
|
18
|
+
ResponseMate::Exporters::
|
19
|
+
Postman::Collection.new(manifest)
|
20
|
+
end
|
21
|
+
|
22
|
+
let(:exported) { collection.export }
|
23
|
+
|
24
|
+
subject { exported }
|
25
|
+
|
26
|
+
it 'is can be valid JSON' do
|
27
|
+
expect { subject.to_json }.to_not raise_error
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'contains id' do
|
31
|
+
expect(subject).to have_key :id
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'contains name' do
|
35
|
+
expect(subject).to have_key :name
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'contains description' do
|
39
|
+
expect(subject).to have_key :description
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'contains order' do
|
43
|
+
expect(subject).to have_key :order
|
44
|
+
end
|
45
|
+
|
46
|
+
describe 'order' do
|
47
|
+
it { expect(subject[:order]).to be_an(Array) }
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'contains timestamp' do
|
51
|
+
expect(subject).to have_key :order
|
52
|
+
end
|
53
|
+
|
54
|
+
describe 'requests' do
|
55
|
+
subject { exported[:requests].first }
|
56
|
+
|
57
|
+
it 'contains id' do
|
58
|
+
expect(subject).to have_key(:id)
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'contains collectionId' do
|
62
|
+
expect(subject[:collectionId]).to eq(exported[:id])
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'contains data' do
|
66
|
+
expect(subject).to have_key(:data)
|
67
|
+
end
|
68
|
+
|
69
|
+
describe 'data' do
|
70
|
+
it 'is an Array' do
|
71
|
+
expect(subject[:data]).to be_an(Array)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'contains description' do
|
76
|
+
expect(subject).to have_key(:description)
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'contains method' do
|
80
|
+
expect(subject).to have_key(:method)
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'contains name' do
|
84
|
+
expect(subject).to have_key(:name)
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'contains url' do
|
88
|
+
expect(subject).to have_key(:url)
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'contains version' do
|
92
|
+
expect(subject[:version]).to eq(2)
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'contains responses' do
|
96
|
+
expect(subject).to have_key(:responses)
|
97
|
+
end
|
98
|
+
|
99
|
+
describe 'responses' do
|
100
|
+
it { expect(subject[:responses]).to be_an(Array) }
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'contains dataMode' do
|
104
|
+
expect(subject).to have_key(:responses)
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'contains headers' do
|
108
|
+
expect(subject).to have_key(:headers)
|
109
|
+
end
|
110
|
+
|
111
|
+
describe 'headers' do
|
112
|
+
it { expect(subject[:headers]).to be_a(String) }
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,125 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe ResponseMate::Tape do
|
5
|
+
include_context 'stubbed_requests'
|
6
|
+
|
7
|
+
let(:response_headers_hash) do
|
8
|
+
{ x_powered_by: 'ninjas' }
|
9
|
+
end
|
10
|
+
|
11
|
+
let(:response_headers) { double(to_hash: response_headers_hash) }
|
12
|
+
let(:response) { double(status: 200, body: 'hello', headers: response_headers) }
|
13
|
+
|
14
|
+
let(:user_issues_request) do
|
15
|
+
ResponseMate::Request.new(
|
16
|
+
key: 'user_issues',
|
17
|
+
request: {
|
18
|
+
url: 'www.someapi.com/user/42/issues',
|
19
|
+
something_nil: nil
|
20
|
+
}).normalize!
|
21
|
+
end
|
22
|
+
|
23
|
+
let(:request) { user_issues_request }
|
24
|
+
let(:meta) { nil }
|
25
|
+
|
26
|
+
let(:key) { 'some_tape' }
|
27
|
+
|
28
|
+
describe '#write' do
|
29
|
+
let(:tape) { YAML.load_file(output_files.call.last) }
|
30
|
+
|
31
|
+
before do
|
32
|
+
ResponseMate::Tape.new.write(key, request, response, meta)
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'creates a new tape with key parameter as the filename' do
|
36
|
+
expect(File.basename(output_files.call.last)).to eq("#{key}.yml")
|
37
|
+
end
|
38
|
+
|
39
|
+
describe 'the created tape' do
|
40
|
+
subject { tape }
|
41
|
+
|
42
|
+
it 'is valid YAML' do
|
43
|
+
subject
|
44
|
+
end
|
45
|
+
|
46
|
+
describe 'the request' do
|
47
|
+
subject { tape[:request] }
|
48
|
+
|
49
|
+
it 'exists' do
|
50
|
+
expect(subject).to be
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'does not have any nil values' do
|
54
|
+
expect(subject).to_not have_key(:something_nil)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe 'the response' do
|
59
|
+
subject { tape[:response] }
|
60
|
+
|
61
|
+
it 'exists' do
|
62
|
+
expect(subject).to be
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'contains status' do
|
66
|
+
expect(subject).to have_key(:status)
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'contains headers' do
|
70
|
+
expect(subject).to have_key(:headers)
|
71
|
+
end
|
72
|
+
|
73
|
+
describe 'headers' do
|
74
|
+
subject { tape[:response][:headers] }
|
75
|
+
|
76
|
+
it { expect(subject).to be_a(Hash) }
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'contains body' do
|
80
|
+
expect(subject).to have_key(:body)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'contains a created_at timestamp' do
|
85
|
+
expect(subject).to have_key(:created_at)
|
86
|
+
end
|
87
|
+
|
88
|
+
context 'when meta is supplied' do
|
89
|
+
let(:meta) { 'some meta info' }
|
90
|
+
|
91
|
+
it 'contains meta' do
|
92
|
+
expect(subject).to have_key(:meta)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
context 'when meta is not supplied' do
|
97
|
+
it 'does not contain meta' do
|
98
|
+
expect(subject).to_not have_key(:meta)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
describe '.load' do
|
105
|
+
subject { ResponseMate::Tape.load(key) }
|
106
|
+
|
107
|
+
context 'when a tape for the given key exists' do
|
108
|
+
before do
|
109
|
+
ResponseMate::Tape.new.write(key, request, response, meta)
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'returns valid YAML' do
|
113
|
+
expect { subject }.to_not raise_error
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
context 'when tape for the given key does not exist' do
|
118
|
+
let(:key) { 'nonexistent_key' }
|
119
|
+
|
120
|
+
it 'raises an error' do
|
121
|
+
expect { subject }.to raise_error(Errno::ENOENT)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
data/spec/source/requests.yml
CHANGED
@@ -2,15 +2,22 @@ default_headers: &default_headers
|
|
2
2
|
accept: 'application/vnd.someapi+json; version=3'
|
3
3
|
authorization: 'Bearer {{oauth_token}}'
|
4
4
|
|
5
|
+
description: |
|
6
|
+
A thorought description about the requests of this manifest.
|
7
|
+
|
5
8
|
requests:
|
6
9
|
-
|
7
10
|
key: user_issues
|
11
|
+
meta:
|
12
|
+
description: The issues of the user
|
8
13
|
request:
|
9
14
|
url: 'www.someapi.com/user/42/issues'
|
10
15
|
headers:
|
11
16
|
<<: *default_headers
|
12
17
|
|
13
18
|
- key: user_friends
|
19
|
+
meta:
|
20
|
+
description: The friends of the user
|
14
21
|
request:
|
15
22
|
url: 'www.someapi.com/user/42/friends'
|
16
23
|
headers:
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: response_mate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-07-
|
12
|
+
date: 2014-07-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -43,22 +43,6 @@ dependencies:
|
|
43
43
|
- - ! '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: '0'
|
46
|
-
- !ruby/object:Gem::Dependency
|
47
|
-
name: fakefs
|
48
|
-
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
|
-
requirements:
|
51
|
-
- - ! '>='
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
version: '0'
|
54
|
-
type: :development
|
55
|
-
prerelease: false
|
56
|
-
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
|
-
requirements:
|
59
|
-
- - ! '>='
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
46
|
- !ruby/object:Gem::Dependency
|
63
47
|
name: thor
|
64
48
|
requirement: !ruby/object:Gem::Requirement
|
@@ -226,6 +210,7 @@ files:
|
|
226
210
|
- environment.yml.sample
|
227
211
|
- lib/response_mate.rb
|
228
212
|
- lib/response_mate/cli.rb
|
213
|
+
- lib/response_mate/commands.rb
|
229
214
|
- lib/response_mate/commands/base.rb
|
230
215
|
- lib/response_mate/commands/clear.rb
|
231
216
|
- lib/response_mate/commands/export.rb
|
@@ -237,14 +222,12 @@ files:
|
|
237
222
|
- lib/response_mate/core.rb
|
238
223
|
- lib/response_mate/environment.rb
|
239
224
|
- lib/response_mate/exporter.rb
|
225
|
+
- lib/response_mate/exporters.rb
|
240
226
|
- lib/response_mate/exporters/postman.rb
|
241
227
|
- lib/response_mate/exporters/postman/collection.rb
|
242
228
|
- lib/response_mate/exporters/postman/environment.rb
|
243
|
-
- lib/response_mate/helpers/application.rb
|
244
|
-
- lib/response_mate/http.rb
|
245
229
|
- lib/response_mate/inspector.rb
|
246
230
|
- lib/response_mate/manifest.rb
|
247
|
-
- lib/response_mate/manifest_parser.rb
|
248
231
|
- lib/response_mate/recorder.rb
|
249
232
|
- lib/response_mate/request.rb
|
250
233
|
- lib/response_mate/tape.rb
|
@@ -258,7 +241,9 @@ files:
|
|
258
241
|
- spec/lib/response_mate/commands/list_spec.rb
|
259
242
|
- spec/lib/response_mate/commands/record_spec.rb
|
260
243
|
- spec/lib/response_mate/core_spec.rb
|
244
|
+
- spec/lib/response_mate/exporters/postman/collection_spec.rb
|
261
245
|
- spec/lib/response_mate/recorder_spec.rb
|
246
|
+
- spec/lib/response_mate/tape_spec.rb
|
262
247
|
- spec/lib/response_mate_spec.rb
|
263
248
|
- spec/source/environment.yml
|
264
249
|
- spec/source/requests.yml
|
@@ -297,7 +282,9 @@ test_files:
|
|
297
282
|
- spec/lib/response_mate/commands/list_spec.rb
|
298
283
|
- spec/lib/response_mate/commands/record_spec.rb
|
299
284
|
- spec/lib/response_mate/core_spec.rb
|
285
|
+
- spec/lib/response_mate/exporters/postman/collection_spec.rb
|
300
286
|
- spec/lib/response_mate/recorder_spec.rb
|
287
|
+
- spec/lib/response_mate/tape_spec.rb
|
301
288
|
- spec/lib/response_mate_spec.rb
|
302
289
|
- spec/source/environment.yml
|
303
290
|
- spec/source/requests.yml
|
data/lib/response_mate/http.rb
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
module ResponseMate::Http
|
4
|
-
STATUS_CODES = {
|
5
|
-
100 => 'Continue',
|
6
|
-
101 => 'Switching Protocols',
|
7
|
-
200 => 'OK',
|
8
|
-
201 => 'Created',
|
9
|
-
202 => 'Accepted',
|
10
|
-
203 => 'Non-Authoritative Information',
|
11
|
-
204 => 'No Content',
|
12
|
-
205 => 'Reset Content',
|
13
|
-
206 => 'Partial Content',
|
14
|
-
300 => 'Multiple Choices',
|
15
|
-
301 => 'Moved Permanently',
|
16
|
-
302 => 'Moved Temporarily',
|
17
|
-
303 => 'See Other',
|
18
|
-
304 => 'Not Modified',
|
19
|
-
305 => 'Use Proxy',
|
20
|
-
400 => 'Bad Request',
|
21
|
-
401 => 'Unauthorized',
|
22
|
-
402 => 'Payment Required',
|
23
|
-
403 => 'Forbidden',
|
24
|
-
404 => 'Not Found',
|
25
|
-
405 => 'Method Not Allowed',
|
26
|
-
406 => 'Not Acceptable',
|
27
|
-
407 => 'Proxy Authentication Required',
|
28
|
-
408 => 'Request Time-out',
|
29
|
-
409 => 'Conflict',
|
30
|
-
410 => 'Gone',
|
31
|
-
411 => 'Length Required',
|
32
|
-
412 => 'Precondition Failed',
|
33
|
-
413 => 'Request Entity Too Large',
|
34
|
-
414 => 'Request-URI Too Large',
|
35
|
-
415 => 'Unsupported Media Type',
|
36
|
-
500 => 'Internal Server Error',
|
37
|
-
501 => 'Not Implemented',
|
38
|
-
502 => 'Bad Gateway',
|
39
|
-
503 => 'Service Unavailable',
|
40
|
-
504 => 'Gateway Time-out',
|
41
|
-
505 => 'HTTP Version not supported'
|
42
|
-
}
|
43
|
-
end
|