response_mate 0.2.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.rubocop.yml +31 -0
- data/Gemfile.lock +4 -3
- data/bin/response_mate +1 -10
- data/lib/response_mate/cli.rb +5 -18
- data/lib/response_mate/commands/base.rb +6 -11
- data/lib/response_mate/commands/export.rb +17 -22
- data/lib/response_mate/commands/inspect.rb +0 -2
- data/lib/response_mate/commands/list.rb +4 -3
- data/lib/response_mate/commands/record.rb +9 -14
- data/lib/response_mate/commands.rb +1 -0
- data/lib/response_mate/connection.rb +2 -2
- data/lib/response_mate/core.rb +11 -10
- data/lib/response_mate/environment.rb +6 -2
- data/lib/response_mate/exporter.rb +3 -2
- data/lib/response_mate/exporters/postman/collection.rb +0 -2
- data/lib/response_mate/exporters/postman/environment.rb +1 -2
- data/lib/response_mate/exporters/postman.rb +5 -2
- data/lib/response_mate/inspector.rb +6 -3
- data/lib/response_mate/manifest.rb +33 -24
- data/lib/response_mate/recorder.rb +0 -2
- data/lib/response_mate/request.rb +9 -5
- data/lib/response_mate/tape.rb +9 -4
- data/lib/response_mate/version.rb +2 -3
- data/lib/response_mate.rb +0 -1
- data/response_mate.gemspec +5 -5
- data/spec/lib/response_mate/cli_spec.rb +1 -35
- data/spec/lib/response_mate/commands/inspect_spec.rb +2 -4
- data/spec/lib/response_mate/commands/list_spec.rb +0 -2
- data/spec/lib/response_mate/commands/record_spec.rb +8 -12
- data/spec/lib/response_mate/core_spec.rb +0 -2
- data/spec/lib/response_mate/exporters/postman/collection_spec.rb +0 -1
- data/spec/lib/response_mate/recorder_spec.rb +0 -1
- data/spec/lib/response_mate/tape_spec.rb +1 -2
- data/spec/lib/response_mate_spec.rb +0 -2
- data/spec/spec_helper.rb +1 -3
- data/spec/support/stubbed_requests.rb +6 -5
- metadata +19 -4
- data/lib/response_mate/commands/clear.rb +0 -26
- data/lib/response_mate/commands/setup.rb +0 -26
data/.rubocop.yml
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
Style/LineLength:
|
2
|
+
Max: 120
|
3
|
+
|
4
|
+
Style/MethodLength:
|
5
|
+
Max: 20
|
6
|
+
|
7
|
+
Style/Documentation:
|
8
|
+
Enabled: false
|
9
|
+
|
10
|
+
Style/ClassAndModuleChildren:
|
11
|
+
Enabled: false
|
12
|
+
|
13
|
+
Style/Encoding:
|
14
|
+
EnforcedStyle: when_needed
|
15
|
+
|
16
|
+
Style/DotPosition:
|
17
|
+
EnforcedStyle: trailing
|
18
|
+
|
19
|
+
Style/PercentLiteralDelimiters:
|
20
|
+
PreferredDelimiters:
|
21
|
+
"%w": "[]"
|
22
|
+
|
23
|
+
Style/RaiseArgs:
|
24
|
+
EnforcedStyle: compact
|
25
|
+
|
26
|
+
Style/SpaceInsideBlockBraces:
|
27
|
+
EnforcedStyleForEmptyBraces: space
|
28
|
+
|
29
|
+
Style/Blocks:
|
30
|
+
Exclude:
|
31
|
+
- spec/**/*.rb
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
response_mate (0.
|
4
|
+
response_mate (0.3.0)
|
5
5
|
activesupport
|
6
6
|
addressable
|
7
7
|
awesome_print
|
@@ -63,7 +63,7 @@ GEM
|
|
63
63
|
guard (~> 2.0)
|
64
64
|
rubocop (~> 0.20)
|
65
65
|
highline (1.6.21)
|
66
|
-
i18n (0.6.
|
66
|
+
i18n (0.6.11)
|
67
67
|
json (1.8.1)
|
68
68
|
listen (2.7.5)
|
69
69
|
celluloid (>= 0.15.2)
|
@@ -72,7 +72,7 @@ GEM
|
|
72
72
|
lumberjack (1.0.5)
|
73
73
|
method_source (0.8.2)
|
74
74
|
mime-types (2.0)
|
75
|
-
minitest (5.
|
75
|
+
minitest (5.4.0)
|
76
76
|
multi_json (1.8.2)
|
77
77
|
multipart-post (2.0.0)
|
78
78
|
mustache (0.99.5)
|
@@ -137,4 +137,5 @@ DEPENDENCIES
|
|
137
137
|
rake
|
138
138
|
response_mate!
|
139
139
|
rspec (~> 2.14.0)
|
140
|
+
rubocop
|
140
141
|
simplecov (~> 0.8.2)
|
data/bin/response_mate
CHANGED
@@ -1,14 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
# coding: utf-8
|
3
2
|
|
4
3
|
require 'response_mate'
|
5
4
|
|
6
|
-
|
7
|
-
ResponseMate::CLI.start(ARGV)
|
8
|
-
rescue ResponseMate::OutputDirError
|
9
|
-
puts <<-OUT
|
10
|
-
Output directory does not exist, invoking setup..
|
11
|
-
Please retry after setup
|
12
|
-
OUT
|
13
|
-
ResponseMate::CLI.start(['setup'])
|
14
|
-
end
|
5
|
+
ResponseMate::CLI.start(ARGV)
|
data/lib/response_mate/cli.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
1
|
module ResponseMate
|
2
|
+
# Entry point of the command-line interface
|
4
3
|
class CLI < ::Thor
|
5
4
|
package_name 'response_mate'
|
6
5
|
|
@@ -16,24 +15,13 @@ module ResponseMate
|
|
16
15
|
|
17
16
|
desc 'inspect [key1,key2]', 'Perform requests and print their output'
|
18
17
|
method_option :requests_manifest, aliases: '-r'
|
19
|
-
def inspect(*keys)
|
18
|
+
def inspect(*keys) # rubocop:disable Lint/UnusedMethodArgument
|
20
19
|
ResponseMate::Commands::Inspect.new(args, options).run
|
21
20
|
end
|
22
21
|
|
23
|
-
desc '
|
24
|
-
def setup(output_dir = '')
|
25
|
-
ResponseMate::Commands::Setup.new(args, options).run
|
26
|
-
end
|
27
|
-
|
28
|
-
desc 'clear [output_dir]', 'Delete existing response files'
|
29
|
-
def clear(output_dir = '')
|
30
|
-
ResponseMate::Commands::Clear.new(args, options).run
|
31
|
-
end
|
32
|
-
|
33
|
-
desc 'list [request_type] (requests or recordings)',
|
34
|
-
'List available recordings or keys to record'
|
22
|
+
desc 'list', 'List available keys to record or inspect'
|
35
23
|
method_option :requests_manifest, aliases: '-r'
|
36
|
-
def list
|
24
|
+
def list # rubocop:disable Lint/UnusedMethodArgument
|
37
25
|
ResponseMate::Commands::List.new(args, options).run
|
38
26
|
end
|
39
27
|
|
@@ -43,8 +31,7 @@ module ResponseMate
|
|
43
31
|
end
|
44
32
|
map ['--version'] => :version
|
45
33
|
|
46
|
-
desc 'export',
|
47
|
-
'Export manifest or environment to one of the available formats'
|
34
|
+
desc 'export', 'Export manifest or environment to one of the available formats'
|
48
35
|
method_option :requests_manifest, aliases: '-r'
|
49
36
|
method_option :format, required: true, aliases: '-f', default: 'postman'
|
50
37
|
method_option :pretty, aliases: '-p', default: false
|
@@ -1,14 +1,9 @@
|
|
1
|
-
#
|
1
|
+
# The command all other commands inherit from to DRY common functionality
|
2
|
+
class ResponseMate::Commands::Base
|
3
|
+
attr_accessor :args, :options
|
2
4
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
attr_accessor :args, :options
|
7
|
-
|
8
|
-
def initialize(args, options)
|
9
|
-
@args = args
|
10
|
-
@options = options.dup.symbolize_keys
|
11
|
-
end
|
12
|
-
end
|
5
|
+
def initialize(args, options)
|
6
|
+
@args = args
|
7
|
+
@options = options.dup.symbolize_keys
|
13
8
|
end
|
14
9
|
end
|
@@ -1,28 +1,23 @@
|
|
1
|
-
#
|
1
|
+
# Command which performs the operations required by `response_mate list`
|
2
|
+
class ResponseMate::Commands::Export < ResponseMate::Commands::Base
|
3
|
+
def initialize(args, options)
|
4
|
+
super(args, options)
|
5
|
+
@type = args.first || 'requests'
|
2
6
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
def initialize(args, options)
|
8
|
-
super(args, options)
|
9
|
-
@type = args.first || 'requests'
|
10
|
-
|
11
|
-
@options[:environment] = ResponseMate::Environment.new(options[:environment])
|
12
|
-
@options[:manifest] = ResponseMate::Manifest.new(options[:requests_manifest])
|
13
|
-
end
|
7
|
+
@options[:environment] = ResponseMate::Environment.new(options[:environment])
|
8
|
+
@options[:manifest] = ResponseMate::Manifest.new(options[:requests_manifest])
|
9
|
+
end
|
14
10
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
puts JSON.parse(url.body)['link']
|
22
|
-
else
|
23
|
-
puts JSON.pretty_generate(output)
|
24
|
-
end
|
11
|
+
# Run the command based on args, options provided
|
12
|
+
def run
|
13
|
+
output = ResponseMate::Exporter.new(options).export
|
14
|
+
if options[:upload]
|
15
|
+
url = Faraday.post 'http://getpostman.com/collections' do |req|
|
16
|
+
req.body = output.to_json
|
25
17
|
end
|
18
|
+
puts JSON.parse(url.body)['link']
|
19
|
+
else
|
20
|
+
puts JSON.pretty_generate(output)
|
26
21
|
end
|
27
22
|
end
|
28
23
|
end
|
@@ -1,5 +1,6 @@
|
|
1
|
-
#
|
1
|
+
# Command which performs the operations required by `response_mate list`
|
2
2
|
class ResponseMate::Commands::List < ResponseMate::Commands::Base
|
3
|
+
# Run the command based on args, options provided
|
3
4
|
def run
|
4
5
|
environment = ResponseMate::Environment.new(options[:environment])
|
5
6
|
@manifest = ResponseMate::Manifest.new(options[:requests_manifest], environment)
|
@@ -24,10 +25,10 @@ class ResponseMate::Commands::List < ResponseMate::Commands::Base
|
|
24
25
|
end
|
25
26
|
|
26
27
|
def ask_key(available_keys)
|
27
|
-
choose
|
28
|
+
choose do |menu|
|
28
29
|
menu.prompt = 'Which one?'
|
29
30
|
menu.choices(*available_keys)
|
30
|
-
|
31
|
+
end.to_s
|
31
32
|
end
|
32
33
|
|
33
34
|
def perform_action(action, key)
|
@@ -1,19 +1,14 @@
|
|
1
|
-
#
|
1
|
+
# Handles the invocation of the record command
|
2
|
+
class ResponseMate::Commands::Record < ResponseMate::Commands::Base
|
3
|
+
# Run the command based on args, options provided
|
4
|
+
def run
|
5
|
+
environment = ResponseMate::Environment.new(options[:environment])
|
6
|
+
manifest = ResponseMate::Manifest.new(options[:requests_manifest], environment)
|
2
7
|
|
3
|
-
|
4
|
-
module Commands
|
5
|
-
# Handles the invocation of the record command
|
6
|
-
class Record < Base
|
7
|
-
def run
|
8
|
-
environment = ResponseMate::Environment.new(options[:environment])
|
9
|
-
manifest = ResponseMate::Manifest.new(options[:requests_manifest], environment)
|
8
|
+
options[:manifest] = manifest
|
10
9
|
|
11
|
-
|
10
|
+
recorder = ResponseMate::Recorder.new(options)
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
recorder.record(options[:keys])
|
16
|
-
end
|
17
|
-
end
|
12
|
+
recorder.record(options[:keys])
|
18
13
|
end
|
19
14
|
end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
1
|
# This class provides a layer above the HTTP client
|
4
2
|
class ResponseMate::Connection
|
5
3
|
delegate :params, to: :client
|
@@ -14,6 +12,8 @@ class ResponseMate::Connection
|
|
14
12
|
end
|
15
13
|
end
|
16
14
|
|
15
|
+
# Performs the supplied request
|
16
|
+
# @param {ResponseMate::Request} The request to be performed
|
17
17
|
def fetch(request)
|
18
18
|
uri = URI.parse(request[:url])
|
19
19
|
|
data/lib/response_mate/core.rb
CHANGED
@@ -1,16 +1,12 @@
|
|
1
|
-
# coding: utf-8
|
2
1
|
# The main module of the tool contains configuration code and some constants
|
3
2
|
module ResponseMate
|
4
3
|
class OutputDirError < StandardError; end
|
5
4
|
class KeysNotFound < StandardError; end
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
class << self
|
11
|
-
attr_accessor :configuration
|
12
|
-
end
|
6
|
+
# Methods handled by response_mate
|
7
|
+
HTTP_METHODS = %w[GET POST PUT PATCH DELETE HEAD OPTIONS]
|
13
8
|
|
9
|
+
# Responsible for keeping initialization configuration values
|
14
10
|
class Configuration
|
15
11
|
attr_accessor :output_dir, :requests_manifest, :environment
|
16
12
|
|
@@ -21,8 +17,13 @@ module ResponseMate
|
|
21
17
|
end
|
22
18
|
end
|
23
19
|
|
24
|
-
|
25
|
-
|
26
|
-
|
20
|
+
class << self
|
21
|
+
attr_accessor :configuration
|
22
|
+
|
23
|
+
# Initializer method to set configuration values
|
24
|
+
def setup
|
25
|
+
self.configuration ||= Configuration.new
|
26
|
+
yield(configuration) if block_given?
|
27
|
+
end
|
27
28
|
end
|
28
29
|
end
|
@@ -1,5 +1,7 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# Responsible for parsing the environment file
|
2
|
+
# The environment file (by default found as environment.yml in a project)
|
3
|
+
# is a Hash which will be used for the rendering of the requests manifest as a
|
4
|
+
# [Mustace template](http://mustache.github.io/mustache.5.html).
|
3
5
|
class ResponseMate::Environment
|
4
6
|
attr_accessor :filename, :env, :environment_text
|
5
7
|
|
@@ -11,6 +13,8 @@ class ResponseMate::Environment
|
|
11
13
|
parse
|
12
14
|
end
|
13
15
|
|
16
|
+
private
|
17
|
+
|
14
18
|
def parse
|
15
19
|
begin
|
16
20
|
@environment_text = File.read filename
|
@@ -1,6 +1,6 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
1
|
module ResponseMate
|
2
|
+
# Responsible for exporting response_mate manifest to
|
3
|
+
# formats understood by other similar tools
|
4
4
|
class Exporter
|
5
5
|
attr_accessor :format, :handler, :manifest, :environment, :resource
|
6
6
|
|
@@ -11,6 +11,7 @@ module ResponseMate
|
|
11
11
|
@resource = args[:resource]
|
12
12
|
end
|
13
13
|
|
14
|
+
# Returns the compatible transformed resource
|
14
15
|
def export
|
15
16
|
@handler = "ResponseMate::Exporters::#{format.capitalize}".safe_constantize.
|
16
17
|
new manifest, environment, resource
|
@@ -1,5 +1,3 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
1
|
class ResponseMate::Exporters::Postman
|
4
2
|
# Handles exporting to postman format
|
5
3
|
# Example output
|
@@ -12,6 +10,7 @@ class ResponseMate::Exporters::Postman
|
|
12
10
|
@out = {}
|
13
11
|
end
|
14
12
|
|
13
|
+
# Export the environment
|
15
14
|
def export
|
16
15
|
build_structure
|
17
16
|
build_values
|
@@ -1,5 +1,3 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
1
|
module ResponseMate::Exporters
|
4
2
|
# Handles exporting to postman format
|
5
3
|
# Example output
|
@@ -10,6 +8,9 @@ module ResponseMate::Exporters
|
|
10
8
|
|
11
9
|
attr_accessor :manifest, :environment, :resource, :out
|
12
10
|
|
11
|
+
# @param {ResponseMate::Manifest} The requests manifest
|
12
|
+
# @param {ResponseMate::Manifest} The requests manifest
|
13
|
+
# @return {Response::Mate::Exporters::Postman}
|
13
14
|
def initialize(manifest, environment, resource)
|
14
15
|
@manifest = manifest
|
15
16
|
@environment = environment
|
@@ -17,6 +18,8 @@ module ResponseMate::Exporters
|
|
17
18
|
@out = {}
|
18
19
|
end
|
19
20
|
|
21
|
+
# Performs the export operation
|
22
|
+
# @return [Hash] The transformed resource
|
20
23
|
def export
|
21
24
|
case resource
|
22
25
|
when 'manifest'
|
@@ -1,5 +1,4 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# Responsible for inspecting requests
|
3
2
|
class ResponseMate::Inspector
|
4
3
|
attr_accessor :conn, :manifest
|
5
4
|
|
@@ -9,13 +8,17 @@ class ResponseMate::Inspector
|
|
9
8
|
@conn = ResponseMate::Connection.new
|
10
9
|
end
|
11
10
|
|
12
|
-
|
11
|
+
# Prints the output of the specified request
|
12
|
+
# @param [Symbol] The key to be inspected
|
13
|
+
def inspect_key(key)
|
13
14
|
request = manifest.requests.find { |r| r.key == key }
|
14
15
|
|
15
16
|
puts request.to_cli_format
|
16
17
|
print_pretty(conn.fetch(request))
|
17
18
|
end
|
18
19
|
|
20
|
+
private
|
21
|
+
|
19
22
|
def print_pretty(response)
|
20
23
|
ap(status: response.status,
|
21
24
|
headers: response.headers,
|
@@ -1,5 +1,5 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# Responsible for parsing the requests manifest file to
|
2
|
+
# actually operate on the requests
|
3
3
|
class ResponseMate::Manifest
|
4
4
|
attr_accessor :filename, :requests, :requests_text, :environment
|
5
5
|
attr_reader :name, :description
|
@@ -10,19 +10,8 @@ class ResponseMate::Manifest
|
|
10
10
|
parse
|
11
11
|
end
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
@requests_text = File.read filename
|
16
|
-
rescue Errno::ENOENT
|
17
|
-
puts filename.red << ' does not seem to exist'
|
18
|
-
exit 1
|
19
|
-
end
|
20
|
-
|
21
|
-
if environment.present?
|
22
|
-
@requests_text = Mustache.render(@requests_text, environment.try(:env) || {})
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
13
|
+
# Parse the requests manifest
|
14
|
+
# @return [Array] of requests
|
26
15
|
def parse
|
27
16
|
preprocess_manifest
|
28
17
|
@request_hashes = YAML.load(requests_text).deep_symbolize_keys
|
@@ -33,18 +22,38 @@ class ResponseMate::Manifest
|
|
33
22
|
map { |rh| ResponseMate::Request.new(rh).normalize! }
|
34
23
|
end
|
35
24
|
|
25
|
+
# Filters requests based on the supplied Array of keys
|
26
|
+
# @param [Array] keys The keys to lookup for matching requests
|
27
|
+
# @return [Array] of matching requests
|
36
28
|
def requests_for_keys(keys)
|
37
|
-
if keys.
|
38
|
-
|
39
|
-
|
29
|
+
return [] if keys.empty?
|
30
|
+
|
31
|
+
existing_keys = requests.map(&:key)
|
32
|
+
missing_keys = keys - existing_keys
|
40
33
|
|
41
|
-
|
42
|
-
|
43
|
-
|
34
|
+
if missing_keys.present?
|
35
|
+
fail ResponseMate::KeysNotFound.new(missing_keys.join(','))
|
36
|
+
end
|
37
|
+
|
38
|
+
requests.select! do |r|
|
39
|
+
keys.include? r.key
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
# Parse the manifest file as a template
|
46
|
+
# @return [String] The manifest text parsed as a template
|
47
|
+
def preprocess_manifest
|
48
|
+
begin
|
49
|
+
@requests_text = File.read filename
|
50
|
+
rescue Errno::ENOENT
|
51
|
+
puts filename.red << ' does not seem to exist'
|
52
|
+
exit 1
|
53
|
+
end
|
44
54
|
|
45
|
-
|
46
|
-
|
47
|
-
end
|
55
|
+
if environment.present? # rubocop:disable Style/GuardClause
|
56
|
+
@requests_text = Mustache.render(@requests_text, environment.try(:env) || {})
|
48
57
|
end
|
49
58
|
end
|
50
59
|
end
|
@@ -1,24 +1,28 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# Responsible for keeping all logic related to a
|
2
|
+
# request defined in the requests manifest
|
3
3
|
class ResponseMate::Request < OpenStruct
|
4
4
|
delegate :[], to: :request
|
5
5
|
|
6
|
+
# Make sure all defined requests in the manifest have complete
|
7
|
+
# information for {ResponseMate::Connection#fetch}
|
6
8
|
def normalize!
|
7
|
-
unless ResponseMate::HTTP_METHODS.include?
|
8
|
-
|
9
|
+
unless ResponseMate::HTTP_METHODS.include? request[:verb]
|
10
|
+
request[:verb] = 'GET'
|
9
11
|
end
|
10
12
|
|
11
|
-
|
13
|
+
request[:url] = URI.encode(adjust_scheme(request[:url], request[:scheme]))
|
12
14
|
|
13
15
|
self
|
14
16
|
end
|
15
17
|
|
18
|
+
# @return [String] Output string suitable for a terminal
|
16
19
|
def to_cli_format
|
17
20
|
out = "[#{key}] #{request[:verb]}".cyan_on_black.bold << " #{request[:url]}"
|
18
21
|
out << "\tparams #{request[:params]}" if request[:params].present?
|
19
22
|
out
|
20
23
|
end
|
21
24
|
|
25
|
+
# @return [Hash] The Hash representation of the request
|
22
26
|
def to_hash
|
23
27
|
marshal_dump[:request]
|
24
28
|
end
|
data/lib/response_mate/tape.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# Responsible for the recorded responses as files
|
3
2
|
class ResponseMate::Tape
|
3
|
+
# Writes the tape as a file
|
4
4
|
def write(key, request, response, meta = {}, output_dir = nil)
|
5
|
-
output_dir
|
5
|
+
output_dir ||= ResponseMate.configuration.output_dir
|
6
6
|
|
7
7
|
output_path = File.join output_dir, "#{key}.yml"
|
8
8
|
|
@@ -25,12 +25,17 @@ class ResponseMate::Tape
|
|
25
25
|
raise ResponseMate::OutputDirError
|
26
26
|
end
|
27
27
|
|
28
|
+
private
|
29
|
+
|
28
30
|
def _utf8_encode(object)
|
29
31
|
case object
|
30
32
|
when String
|
31
33
|
object.force_encoding('UTF-8')
|
32
34
|
when Hash
|
33
|
-
object.each
|
35
|
+
object.each do |k, v| # rubocop:disable Lint/UnusedBlockArgument
|
36
|
+
k = _utf8_encode(v) # rubocop:disable Lint/UselessAssignment
|
37
|
+
v = _utf8_encode(v) # rubocop:disable Lint/UselessAssignment
|
38
|
+
end
|
34
39
|
when Array
|
35
40
|
object.each { |v| _utf8_encode(v) }
|
36
41
|
end
|
data/lib/response_mate.rb
CHANGED
data/response_mate.gemspec
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# coding: utf-8
|
2
1
|
lib = File.expand_path('../lib', __FILE__)
|
3
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
3
|
require 'response_mate/version'
|
@@ -11,17 +10,18 @@ Gem::Specification.new do |spec|
|
|
11
10
|
spec.description = <<-DESC
|
12
11
|
Cli tool to make inspecting and recording HTTP requests fun again
|
13
12
|
DESC
|
14
|
-
spec.summary = %q
|
13
|
+
spec.summary = %q(A cli tool for browsing and recording api requests with ease)
|
15
14
|
spec.homepage = 'https://github.com/Zorbash/response_mate'
|
16
15
|
spec.license = 'MIT'
|
17
16
|
|
18
|
-
spec.files = `git ls-files`.split(
|
19
|
-
spec.executables = spec.files.grep(
|
20
|
-
spec.test_files = spec.files.grep(
|
17
|
+
spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
18
|
+
spec.executables = spec.files.grep(/^bin\//) { |f| File.basename(f) }
|
19
|
+
spec.test_files = spec.files.grep(/^(test|spec|features)\//)
|
21
20
|
spec.require_paths = ['lib']
|
22
21
|
|
23
22
|
spec.add_development_dependency 'bundler', '~> 1.3'
|
24
23
|
spec.add_development_dependency 'rake'
|
24
|
+
spec.add_development_dependency 'rubocop'
|
25
25
|
|
26
26
|
spec.add_dependency 'thor', '~> 0.19'
|
27
27
|
spec.add_dependency 'awesome_print'
|
@@ -1,5 +1,3 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
1
|
require 'spec_helper'
|
4
2
|
|
5
3
|
describe ResponseMate::CLI do
|
@@ -28,7 +26,7 @@ describe ResponseMate::CLI do
|
|
28
26
|
end
|
29
27
|
end
|
30
28
|
|
31
|
-
describe'#inspect' do
|
29
|
+
describe '#inspect' do
|
32
30
|
before do
|
33
31
|
allow(ResponseMate::Commands::Inspect).to receive(:new).and_return(command)
|
34
32
|
end
|
@@ -44,38 +42,6 @@ describe ResponseMate::CLI do
|
|
44
42
|
end
|
45
43
|
end
|
46
44
|
|
47
|
-
describe '#setup' do
|
48
|
-
before do
|
49
|
-
allow(ResponseMate::Commands::Setup).to receive(:new).and_return(command)
|
50
|
-
end
|
51
|
-
|
52
|
-
it 'initializes ResponseMate::Commands::setup' do
|
53
|
-
expect(ResponseMate::Commands::Setup).to receive(:new)
|
54
|
-
capture(:stdout) { ResponseMate::CLI.start %w[setup] }
|
55
|
-
end
|
56
|
-
|
57
|
-
it 'runs the command passing any given options, arguments' do
|
58
|
-
expect(command).to receive(:run)
|
59
|
-
capture(:stdout) { ResponseMate::CLI.start %w[setup] }
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
describe '#clear' do
|
64
|
-
before do
|
65
|
-
allow(ResponseMate::Commands::Clear).to receive(:new).and_return(command)
|
66
|
-
end
|
67
|
-
|
68
|
-
it 'initializes ResponseMate::Commands::Clear' do
|
69
|
-
expect(ResponseMate::Commands::Clear).to receive(:new)
|
70
|
-
capture(:stdout) { ResponseMate::CLI.start %w[clear] }
|
71
|
-
end
|
72
|
-
|
73
|
-
it 'runs the command passing any given options, arguments' do
|
74
|
-
expect(command).to receive(:run)
|
75
|
-
capture(:stdout) { ResponseMate::CLI.start %w[clear] }
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
45
|
describe '#list' do
|
80
46
|
before do
|
81
47
|
allow(ResponseMate::Commands::List).to receive(:new).and_return(command)
|
@@ -1,5 +1,3 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
1
|
require 'spec_helper'
|
4
2
|
|
5
3
|
describe ResponseMate::Commands::Inspect do
|
@@ -16,7 +14,7 @@ describe ResponseMate::Commands::Inspect do
|
|
16
14
|
end
|
17
15
|
end
|
18
16
|
|
19
|
-
expect(error_output.strip).to eq(
|
17
|
+
expect(error_output.strip).to eq('At least one key has to be specified'.red)
|
20
18
|
end
|
21
19
|
end
|
22
20
|
|
@@ -46,7 +44,7 @@ describe ResponseMate::Commands::Inspect do
|
|
46
44
|
|
47
45
|
it 'includes the response status' do
|
48
46
|
expect(captured_output).
|
49
|
-
to include(":status => #{fake_response_user_issues[:status]
|
47
|
+
to include(":status => #{fake_response_user_issues[:status]}")
|
50
48
|
end
|
51
49
|
|
52
50
|
it 'includes the response body' do
|
@@ -1,5 +1,3 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
1
|
require 'spec_helper'
|
4
2
|
|
5
3
|
describe ResponseMate::Commands::Record do
|
@@ -8,7 +6,7 @@ describe ResponseMate::Commands::Record do
|
|
8
6
|
describe '#run' do
|
9
7
|
context 'with keys option unspecified' do
|
10
8
|
before do
|
11
|
-
quietly { ResponseMate::Commands::Record.new([],
|
9
|
+
quietly { ResponseMate::Commands::Record.new([], keys: []).run }
|
12
10
|
end
|
13
11
|
|
14
12
|
describe 'output files' do
|
@@ -25,15 +23,13 @@ describe ResponseMate::Commands::Record do
|
|
25
23
|
|
26
24
|
let(:cmd_with_output_dir) do
|
27
25
|
quietly do
|
28
|
-
ResponseMate::Commands::Record.new([],
|
29
|
-
|
30
|
-
output_dir: [other_output_dir]
|
31
|
-
}).run
|
26
|
+
ResponseMate::Commands::Record.new([], keys: [],
|
27
|
+
output_dir: [other_output_dir]).run
|
32
28
|
end
|
33
29
|
end
|
34
30
|
|
35
31
|
context 'when the specified directory exists' do
|
36
|
-
let(:output_files) { ->{ Dir[other_output_dir + '/*'] } }
|
32
|
+
let(:output_files) { -> { Dir[other_output_dir + '/*'] } }
|
37
33
|
|
38
34
|
before { cmd_with_output_dir }
|
39
35
|
after { output_files.call.each { |file| File.delete(file) } }
|
@@ -56,7 +52,7 @@ describe ResponseMate::Commands::Record do
|
|
56
52
|
|
57
53
|
context 'with output_dir option unspecified' do
|
58
54
|
it 'creates the tapes in the default output directory' do
|
59
|
-
quietly { ResponseMate::Commands::Record.new([],
|
55
|
+
quietly { ResponseMate::Commands::Record.new([], keys: []).run }
|
60
56
|
|
61
57
|
expect(output_files.call).to have_exactly(2).items
|
62
58
|
end
|
@@ -66,7 +62,7 @@ describe ResponseMate::Commands::Record do
|
|
66
62
|
context 'when the requested key exists' do
|
67
63
|
before do
|
68
64
|
quietly do
|
69
|
-
ResponseMate::Commands::Record.new([],
|
65
|
+
ResponseMate::Commands::Record.new([], keys: ['user_issues']).run
|
70
66
|
end
|
71
67
|
end
|
72
68
|
|
@@ -80,7 +76,7 @@ describe ResponseMate::Commands::Record do
|
|
80
76
|
end
|
81
77
|
|
82
78
|
it 'has the right file extension' do
|
83
|
-
expect(File.
|
79
|
+
expect(File.exist?(output_filename)).to be_true
|
84
80
|
end
|
85
81
|
|
86
82
|
describe 'YAML content' do
|
@@ -123,7 +119,7 @@ describe ResponseMate::Commands::Record do
|
|
123
119
|
|
124
120
|
context 'when the requested key does not exist' do
|
125
121
|
subject do
|
126
|
-
ResponseMate::Commands::Record.new([],
|
122
|
+
ResponseMate::Commands::Record.new([], keys: ['non_existing_key']).run
|
127
123
|
end
|
128
124
|
|
129
125
|
it 'raises ResponseMate::KeysNotFound'do
|
@@ -1,4 +1,3 @@
|
|
1
|
-
# coding: utf-8
|
2
1
|
require 'spec_helper'
|
3
2
|
|
4
3
|
describe ResponseMate::Tape do
|
@@ -44,7 +43,7 @@ describe ResponseMate::Tape do
|
|
44
43
|
describe 'tape location' do
|
45
44
|
context 'when the specified output_dir exists' do
|
46
45
|
let(:output_dir) { File.expand_path('./spec/source/other_output_dir') }
|
47
|
-
let(:output_files) { ->{ Dir[output_dir + '/*'] } }
|
46
|
+
let(:output_files) { -> { Dir[output_dir + '/*'] } }
|
48
47
|
|
49
48
|
after { output_files.call.each { |file| File.delete(file) } }
|
50
49
|
|
data/spec/spec_helper.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
1
|
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
4
2
|
require 'response_mate'
|
5
3
|
require 'fakeweb'
|
@@ -7,7 +5,7 @@ require 'coveralls'
|
|
7
5
|
|
8
6
|
Coveralls.wear!
|
9
7
|
|
10
|
-
Dir[
|
8
|
+
Dir['./spec/support/**/*.rb'].sort.each { |f| require f }
|
11
9
|
|
12
10
|
RSpec.configure do |c|
|
13
11
|
c.treat_symbols_as_metadata_keys_with_true_values = true
|
@@ -5,19 +5,19 @@ shared_context 'stubbed_requests' do
|
|
5
5
|
{
|
6
6
|
status: 418,
|
7
7
|
headers: { 'x-issue-format' => 'tps report' },
|
8
|
-
body: 'This user definitely has issues'
|
8
|
+
body: 'This user definitely has issues'
|
9
9
|
}
|
10
10
|
}
|
11
11
|
|
12
12
|
let(:fake_response_user_friends) {
|
13
13
|
{
|
14
14
|
status: 418,
|
15
|
-
body:
|
15
|
+
body: 'User has friends'
|
16
16
|
}
|
17
17
|
}
|
18
18
|
|
19
19
|
let(:output_files) do
|
20
|
-
->{ Dir[ResponseMate.configuration.output_dir + '/*'] }
|
20
|
+
-> { Dir[ResponseMate.configuration.output_dir + '/*'] }
|
21
21
|
end
|
22
22
|
|
23
23
|
before do
|
@@ -28,9 +28,10 @@ shared_context 'stubbed_requests' do
|
|
28
28
|
ResponseMate.stub_chain(:configuration, :output_dir).
|
29
29
|
and_return File.expand_path('spec/source/responses/')
|
30
30
|
|
31
|
-
FakeWeb.register_uri(:get, 'http://www.someapi.com/user/42/issues',
|
31
|
+
FakeWeb.register_uri(:get, 'http://www.someapi.com/user/42/issues',
|
32
|
+
{
|
32
33
|
status: fake_response_user_issues[:status],
|
33
|
-
body: fake_response_user_issues[:body]
|
34
|
+
body: fake_response_user_issues[:body]
|
34
35
|
}.merge(fake_response_user_issues[:headers]))
|
35
36
|
|
36
37
|
FakeWeb.register_uri(:get, 'http://www.someapi.com/user/42/friends?' \
|
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.
|
4
|
+
version: 0.3.0
|
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-
|
12
|
+
date: 2014-08-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -43,6 +43,22 @@ dependencies:
|
|
43
43
|
- - ! '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rubocop
|
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'
|
46
62
|
- !ruby/object:Gem::Dependency
|
47
63
|
name: thor
|
48
64
|
requirement: !ruby/object:Gem::Requirement
|
@@ -199,6 +215,7 @@ extra_rdoc_files: []
|
|
199
215
|
files:
|
200
216
|
- .gitignore
|
201
217
|
- .rspec
|
218
|
+
- .rubocop.yml
|
202
219
|
- .travis.yml
|
203
220
|
- Gemfile
|
204
221
|
- Gemfile.lock
|
@@ -212,12 +229,10 @@ files:
|
|
212
229
|
- lib/response_mate/cli.rb
|
213
230
|
- lib/response_mate/commands.rb
|
214
231
|
- lib/response_mate/commands/base.rb
|
215
|
-
- lib/response_mate/commands/clear.rb
|
216
232
|
- lib/response_mate/commands/export.rb
|
217
233
|
- lib/response_mate/commands/inspect.rb
|
218
234
|
- lib/response_mate/commands/list.rb
|
219
235
|
- lib/response_mate/commands/record.rb
|
220
|
-
- lib/response_mate/commands/setup.rb
|
221
236
|
- lib/response_mate/connection.rb
|
222
237
|
- lib/response_mate/core.rb
|
223
238
|
- lib/response_mate/environment.rb
|
@@ -1,26 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
module ResponseMate
|
4
|
-
module Commands
|
5
|
-
# Handles the invocation of the clear command
|
6
|
-
class ResponseMate::Commands::Clear < Base
|
7
|
-
attr_accessor :output_dir
|
8
|
-
|
9
|
-
def initialize(args, options)
|
10
|
-
super(args, options)
|
11
|
-
@options = options.dup
|
12
|
-
|
13
|
-
@output_dir = if args.present?
|
14
|
-
args.first
|
15
|
-
else
|
16
|
-
ResponseMate.configuration.output_dir
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def run
|
21
|
-
FileUtils.rm_rf(output_dir + '.')
|
22
|
-
puts "All clean and shiny!"
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
module ResponseMate
|
4
|
-
module Commands
|
5
|
-
# Handles the invocation of the setup command
|
6
|
-
class ResponseMate::Commands::Setup < Base
|
7
|
-
attr_accessor :output_dir
|
8
|
-
|
9
|
-
def initialize(args, options)
|
10
|
-
super(args, options)
|
11
|
-
@options = options.dup
|
12
|
-
|
13
|
-
@output_dir = if args.present?
|
14
|
-
args.first
|
15
|
-
else
|
16
|
-
ResponseMate.configuration.output_dir
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def run
|
21
|
-
FileUtils.mkdir_p(output_dir)
|
22
|
-
puts "[Setup] Initialized empty directory #{output_dir}"
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|