mini-apivore 0.1.8 → 0.3.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: 0e71c1d5997296bb64e9167db20ee2dd3cdd3d06058666c072d57616c8b84f4f
4
- data.tar.gz: b91e40d4044d7a2fc0d15661296c49ba224659ddaba81a2d759447f882a5c7c0
3
+ metadata.gz: cd4021c1b59f97da6c130712948c65a271135cc50ebc8b38e438c9a39ea834b7
4
+ data.tar.gz: 96056ed390b669092813bd6bd7b5f9fa44485719ed1d7135234d690440848c13
5
5
  SHA512:
6
- metadata.gz: 196b7bb59882c7e35edd141dd0e052db15b42d47e1180b1b72dca2f5dccc89b3a0ae1f58e9a2a0e1692431d53724b59a5a38abeaea3b190a5873a3012bccedf4
7
- data.tar.gz: da791cd213295519c5851b818bdb3145f7e14fa94b832b1591ff84ec3279bd16de112f377c5ad13b3d4d33dc9b2a3bdff9fa79bdf9a543088ae2b1b1da145265
6
+ metadata.gz: 7f9d82a99a608ea35f4e78791dd1356536e9ca05f63c7698a79e509794a8b1eb313cbb93f4a96691bee4478d6d6e846a541bf5379ff0a65dbb73df8c0733f223
7
+ data.tar.gz: 77e2b25f473550b9d4ea775191ccc7ecaf7fe3cb2da7e16ae7c774d67de1181c85b98786ebe87375fd361e891dec7f06931026636375a8288b402381f1ecbb9d
@@ -1,26 +1,31 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "mini_apivore/version"
2
4
 
3
- module ActiveSupport
4
- module Testing
5
- module Declarative
6
- # Helper to define a test method using a String. Under the hood, it replaces
7
- # spaces with underscores and defines the test method.
8
- #
9
- # test "verify something" do
10
- # ...
11
- # end
12
- def test(name, &block)
13
- test_name = "test_#{name.gsub(/\s+/, '_')}".to_sym
14
- defined = method_defined? test_name
15
- raise "#{test_name} is already defined in #{self}" if defined
16
- if block_given?
17
- define_method(test_name, &block)
18
- else
19
- define_method(test_name) do
20
- flunk "No implementation provided for #{name}"
5
+ unless defined?(ActiveSupport)
6
+ module ActiveSupport
7
+ module Testing
8
+ module Declarative
9
+ # Helper to define a test method using a String. Under the hood, it replaces
10
+ # spaces with underscores and defines the test method.
11
+ #
12
+ # test "verify something" do
13
+ # ...
14
+ # end
15
+ def test(name, &block)
16
+ test_name = "test_#{name.gsub(/\s+/, "_")}".to_sym
17
+ defined = method_defined?(test_name)
18
+ raise "#{test_name} is already defined in #{self}" if defined
19
+
20
+ if block_given?
21
+ define_method(test_name, &block)
22
+ else
23
+ define_method(test_name) do
24
+ flunk("No implementation provided for #{name}")
25
+ end
21
26
  end
22
27
  end
23
28
  end
24
29
  end
25
30
  end
26
- end unless defined?(ActiveSupport)
31
+ end
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "mini_apivore/version"
2
4
 
3
5
  module MiniApivore
4
6
  # This is a workaround for json-schema's fragment validation which does not allow paths to contain forward slashes
5
7
  # current json-schema attempts to split('/') on a string path to produce an array.
6
8
  class Fragment < Array
7
- def split(options = nil)
9
+ def split(_options = nil)
8
10
  self
9
11
  end
10
12
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "mini_apivore/version"
2
4
 
3
5
  module MiniApivore
@@ -7,4 +9,4 @@ module MiniApivore
7
9
  UNPROCESSABLE_ENTITY = 422
8
10
  OK = 200
9
11
  NO_CONTENT = 204
10
- end
12
+ end
@@ -1,42 +1,47 @@
1
- require "mini_apivore/version"
2
- require 'hashie'
1
+ # frozen_string_literal: true
3
2
 
3
+ require "mini_apivore/version"
4
+ require "hashie"
4
5
 
5
6
  module MiniApivore
6
- class Swagger < Hashie::Mash
7
- NONVERB_PATH_ITEMS = %q(parameters)
7
+ class Swagger < Hash
8
+ include Hashie::Extensions::MergeInitializer
9
+
10
+ NONVERB_PATH_ITEMS = "parameters"
8
11
 
9
12
  def validate
10
13
  case version
11
- when '2.0'
12
- schema = File.read(File.expand_path("../../../data/swagger_2.0_schema.json", __FILE__))
13
- else
14
- raise "Unknown/unsupported Swagger version to validate against: #{version}"
14
+ when "2.0"
15
+ schema = File.read(File.expand_path("../../data/swagger_2.0_schema.json", __dir__))
16
+ else
17
+ raise "Unknown/unsupported Swagger version to validate against: #{version}"
15
18
  end
16
19
  JSON::Validator.fully_validate(schema, self)
17
20
  end
18
21
 
19
22
  def version
20
- swagger
23
+ self['swagger']
21
24
  end
22
25
 
23
26
  def base_path
24
- self['basePath'] || ''
27
+ self["basePath"] || ""
25
28
  end
26
29
 
27
30
  def each_response(&block)
28
- paths.each do |path, path_data|
31
+ self['paths'].each do |path, path_data|
29
32
  next if vendor_specific_tag? path
30
33
  path_data.each do |verb, method_data|
31
34
  next if NONVERB_PATH_ITEMS.include?(verb)
32
35
  next if vendor_specific_tag? verb
33
- if method_data.responses.nil?
36
+ if method_data['responses'].nil?
34
37
  raise "No responses found in swagger for path '#{path}', " \
35
38
  "verb #{verb}: #{method_data.inspect}"
36
39
  end
37
- method_data.responses.each do |response_code, response_data|
40
+ method_data['responses'].each do |response_code, response_data|
38
41
  schema_location = nil
39
- if response_data.schema
42
+ if response_data['$ref']
43
+ schema_location = response_data['$ref']
44
+ elsif response_data['schema']
40
45
  schema_location = Fragment.new ['#', 'paths', path, verb, 'responses', response_code, 'schema']
41
46
  end
42
47
  block.call(path, verb, response_code, schema_location)
@@ -45,7 +50,7 @@ module MiniApivore
45
50
  end
46
51
  end
47
52
 
48
- def vendor_specific_tag? tag
53
+ def vendor_specific_tag?(tag)
49
54
  tag =~ /\Ax-.*/
50
55
  end
51
56
  end
@@ -1,23 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "English"
1
4
  require "mini_apivore/version"
2
5
 
3
6
  module MiniApivore
4
7
  class SwaggerChecker
5
8
  PATH_TO_CHECKER_MAP = {}
6
9
 
7
- def self.instance_for(path, schema = '' )
10
+ def self.instance_for(path, schema = "")
8
11
  PATH_TO_CHECKER_MAP[path] ||= new(path, schema)
9
12
  end
10
13
 
11
14
  def has_path?(path)
12
- mappings.has_key?(path)
15
+ mappings.key?(path)
13
16
  end
14
17
 
15
18
  def has_method_at_path?(path, verb)
16
- mappings[path].has_key?(verb)
19
+ mappings[path].key?(verb)
17
20
  end
18
21
 
19
22
  def has_response_code_for_path?(path, verb, code)
20
- mappings[path][verb].has_key?(code.to_s)
23
+ mappings[path][verb].key?(code.to_s)
21
24
  end
22
25
 
23
26
  def response_codes_for_path(path, verb)
@@ -32,18 +35,17 @@ module MiniApivore
32
35
 
33
36
  def fragment(path, verb, code)
34
37
  path_fragment = mappings[path][verb.to_s][code.to_s]
35
- path_fragment.dup unless path_fragment.nil?
38
+ path_fragment&.dup
36
39
  end
37
40
 
38
41
  def remove_tested_end_point_response(path, verb, code)
39
42
  return if untested_mappings[path].nil? ||
40
43
  untested_mappings[path][verb].nil?
44
+
41
45
  untested_mappings[path][verb].delete(code.to_s)
42
- if untested_mappings[path][verb].size == 0
46
+ if untested_mappings[path][verb].size.zero?
43
47
  untested_mappings[path].delete(verb)
44
- if untested_mappings[path].size == 0
45
- untested_mappings.delete(path)
46
- end
48
+ untested_mappings.delete(path) if untested_mappings[path].size.zero?
47
49
  end
48
50
  end
49
51
 
@@ -51,20 +53,14 @@ module MiniApivore
51
53
  @swagger.base_path
52
54
  end
53
55
 
54
- def response=(response)
55
- @response = response
56
- end
57
-
58
- attr_reader :response, :swagger, :swagger_path
59
-
60
- def untested_mappings; @untested_mappings end
61
- def untested_mappings=( other ); @untested_mappings = other end
56
+ attr_accessor :response, :untested_mappings
57
+ attr_reader :swagger, :swagger_path
62
58
 
63
59
  private
64
60
 
65
61
  attr_reader :mappings
66
62
 
67
- def initialize(swagger_path, schema )
63
+ def initialize(swagger_path, schema)
68
64
  @swagger_path = swagger_path
69
65
  @schema = schema
70
66
  load_swagger_doc!
@@ -79,15 +75,15 @@ module MiniApivore
79
75
 
80
76
  def fetch_swagger!
81
77
  return @schema unless @schema.empty?
82
-
83
- if File.exist?( swagger_path )
84
- JSON.parse( File.read(swagger_path) )
78
+
79
+ if File.exist?(swagger_path)
80
+ JSON.parse(File.read(swagger_path))
85
81
  else
86
82
  session = ActionDispatch::Integration::Session.new(Rails.application)
87
83
  begin
88
84
  session.get(swagger_path)
89
- rescue
90
- fail "Unable to perform GET request for swagger json: #{swagger_path} - #{$!}."
85
+ rescue StandardError
86
+ raise "Unable to perform GET request for swagger json: #{swagger_path} - #{$ERROR_INFO}."
91
87
  end
92
88
  JSON.parse(session.response.body)
93
89
  end
@@ -98,7 +94,7 @@ module MiniApivore
98
94
  unless errors.empty?
99
95
  msg = "The document fails to validate as Swagger #{swagger.version}:\n"
100
96
  msg += errors.join("\n")
101
- fail msg
97
+ raise msg
102
98
  end
103
99
  end
104
100
 
@@ -108,6 +104,7 @@ module MiniApivore
108
104
  @mappings[path] ||= {}
109
105
  @mappings[path][verb] ||= {}
110
106
  raise "duplicate" unless @mappings[path][verb][response_code].nil?
107
+
111
108
  @mappings[path][verb][response_code] = fragment
112
109
  end
113
110
 
@@ -1,84 +1,98 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "cgi"
2
4
 
3
- class Object
4
- # Alias of <tt>to_s</tt>.
5
- def to_param
6
- to_s
7
- end
5
+ unless Object.method_defined?(:to_param)
6
+ class Object
7
+ # Alias of <tt>to_s</tt>.
8
+ def to_param
9
+ to_s
10
+ end
8
11
 
9
- # Converts an object into a string suitable for use as a URL query string,
10
- # using the given <tt>key</tt> as the param name.
11
- def to_query(key)
12
- "#{CGI.escape(key.to_param)}=#{CGI.escape(to_param.to_s)}"
12
+ # Converts an object into a string suitable for use as a URL query string,
13
+ # using the given <tt>key</tt> as the param name.
14
+ def to_query(key)
15
+ "#{CGI.escape(key.to_param)}=#{CGI.escape(to_param.to_s)}"
16
+ end
13
17
  end
14
- end unless Object.method_defined?( :to_param )
18
+ end
15
19
 
16
- class NilClass
17
- # Returns +self+.
18
- def to_param
19
- self
20
+ unless NilClass.method_defined?(:to_param)
21
+ class NilClass
22
+ # Returns +self+.
23
+ def to_param
24
+ self
25
+ end
20
26
  end
21
- end unless NilClass.method_defined?( :to_param )
27
+ end
22
28
 
23
- class TrueClass
24
- # Returns +self+.
25
- def to_param
26
- self
29
+ unless TrueClass.method_defined?(:to_param)
30
+ class TrueClass
31
+ # Returns +self+.
32
+ def to_param
33
+ self
34
+ end
27
35
  end
28
- end unless TrueClass.method_defined?( :to_param )
36
+ end
29
37
 
30
- class FalseClass
31
- # Returns +self+.
32
- def to_param
33
- self
38
+ unless FalseClass.method_defined?(:to_param)
39
+ class FalseClass
40
+ # Returns +self+.
41
+ def to_param
42
+ self
43
+ end
34
44
  end
35
- end unless FalseClass.method_defined?( :to_param )
45
+ end
36
46
 
37
- class Array
38
- # Calls <tt>to_param</tt> on all its elements and joins the result with
39
- # slashes. This is used by <tt>url_for</tt> in Action Pack.
40
- def to_param
41
- collect(&:to_param).join "/"
42
- end
47
+ unless Array.method_defined?(:to_param)
48
+ class Array
49
+ # Calls <tt>to_param</tt> on all its elements and joins the result with
50
+ # slashes. This is used by <tt>url_for</tt> in Action Pack.
51
+ def to_param
52
+ collect(&:to_param).join("/")
53
+ end
43
54
 
44
- # Converts an array into a string suitable for use as a URL query string,
45
- # using the given +key+ as the param name.
46
- #
47
- # ['Rails', 'coding'].to_query('hobbies') # => "hobbies%5B%5D=Rails&hobbies%5B%5D=coding"
48
- def to_query(key)
49
- prefix = "#{key}[]"
55
+ # Converts an array into a string suitable for use as a URL query string,
56
+ # using the given +key+ as the param name.
57
+ #
58
+ # ['Rails', 'coding'].to_query('hobbies') # => "hobbies%5B%5D=Rails&hobbies%5B%5D=coding"
59
+ def to_query(key)
60
+ prefix = "#{key}[]"
50
61
 
51
- if empty?
52
- nil.to_query(prefix)
53
- else
54
- collect { |value| value.to_query(prefix) }.join "&"
62
+ if empty?
63
+ nil.to_query(prefix)
64
+ else
65
+ collect { |value| value.to_query(prefix) }.join("&")
66
+ end
55
67
  end
56
68
  end
57
- end unless Array.method_defined?( :to_param )
69
+ end
58
70
 
59
- class Hash
60
- # Returns a string representation of the receiver suitable for use as a URL
61
- # query string:
62
- #
63
- # {name: 'David', nationality: 'Danish'}.to_query
64
- # # => "name=David&nationality=Danish"
65
- #
66
- # An optional namespace can be passed to enclose key names:
67
- #
68
- # {name: 'David', nationality: 'Danish'}.to_query('user')
69
- # # => "user%5Bname%5D=David&user%5Bnationality%5D=Danish"
70
- #
71
- # The string pairs "key=value" that conform the query string
72
- # are sorted lexicographically in ascending order.
73
- #
74
- # This method is also aliased as +to_param+.
75
- def to_query(namespace = nil)
76
- collect do |key, value|
77
- unless (value.is_a?(Hash) || value.is_a?(Array)) && value.empty?
78
- value.to_query(namespace ? "#{namespace}[#{key}]" : key)
79
- end
80
- end.compact.sort! * "&"
81
- end
71
+ unless Hash.method_defined?(:to_param)
72
+ class Hash
73
+ # Returns a string representation of the receiver suitable for use as a URL
74
+ # query string:
75
+ #
76
+ # {name: 'David', nationality: 'Danish'}.to_query
77
+ # # => "name=David&nationality=Danish"
78
+ #
79
+ # An optional namespace can be passed to enclose key names:
80
+ #
81
+ # {name: 'David', nationality: 'Danish'}.to_query('user')
82
+ # # => "user%5Bname%5D=David&user%5Bnationality%5D=Danish"
83
+ #
84
+ # The string pairs "key=value" that conform the query string
85
+ # are sorted lexicographically in ascending order.
86
+ #
87
+ # This method is also aliased as +to_param+.
88
+ def to_query(namespace = nil)
89
+ collect do |key, value|
90
+ unless (value.is_a?(Hash) || value.is_a?(Array)) && value.empty?
91
+ value.to_query(namespace ? "#{namespace}[#{key}]" : key)
92
+ end
93
+ end.compact.sort! * "&"
94
+ end
82
95
 
83
- alias_method :to_param, :to_query
84
- end unless Hash.method_defined?( :to_param )
96
+ alias_method :to_param, :to_query
97
+ end
98
+ end
@@ -1,14 +1,16 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "mini_apivore/version"
2
4
 
3
5
  module MiniApivore
4
- module Validation # former Validator
5
-
6
+ # former Validator
7
+ module Validation
6
8
  class IndHash < Hash
7
9
  include Hashie::Extensions::MergeInitializer
8
10
  include Hashie::Extensions::IndifferentAccess
9
11
  end
10
12
 
11
- def prepare_action_env(verb, path, expected_response_code, params = {})
13
+ def prepare_action_env(verb, path, expected_response_code, **params)
12
14
  @errors = []
13
15
  @verb = verb.to_s
14
16
  @path = path.to_s
@@ -16,39 +18,45 @@ module MiniApivore
16
18
  @expected_response_code = expected_response_code.to_i
17
19
  end
18
20
 
19
- def swagger_checker; self.class.swagger_checker end
21
+ def swagger_checker
22
+ self.class.swagger_checker
23
+ end
20
24
 
21
- def check_route( verb, path, expected_response_code, params = {} )
22
- prepare_action_env( verb, path, expected_response_code, params )
23
- assert( match?, <<FAIL )
24
- Failed at: #{Thread.current.backtrace[2]}\n
25
- Failure message: #{failure_message},\n
26
- fullpath: #{full_path}, \n
27
- params causing failure:#{params}
25
+ def check_route(verb, path, expected_response_code, **params)
26
+ prepare_action_env(verb, path, expected_response_code, **params)
27
+ assert(match?, <<FAIL)
28
+ Failed at: #{prepare_error_backtrace}\n
29
+ Failure message: #{failure_message},\n#{" "}
30
+ fullpath: #{full_path}, \n#{" "}
31
+ params causing failure:#{params}
28
32
  FAIL
29
33
  end
30
34
 
35
+ def prepare_error_backtrace
36
+ # it will deliver something like this:
37
+ # "/app/test/helpers/base_routes_helpers.rb:57:in `__create_card'",
38
+ # "/app/test/integration/cards_api_test.rb:71:in `block (2 levels) in <class:CommentsApiTest>'",
39
+ Thread.current.backtrace[2..].slice_after { |trc| trc[/check_route/] }.to_a.last[0..1]
40
+ end
41
+
31
42
  def match?
32
- #pre_checks
43
+ # pre_checks
33
44
  check_request_path
34
45
 
35
46
  # request
36
47
  unless has_errors?
37
- send(
48
+ action_dispatch_request(
38
49
  @verb,
39
- *action_dispatch_request_args(
40
- full_path,
41
- params: @params['_data'] || {},
42
- headers: @params['_headers'] || {}
43
- )
50
+ full_path,
51
+ params: @params["_data"] || {},
52
+ headers: @params["_headers"] || {}
44
53
  )
45
54
 
46
- #post_checks
55
+ # post_checks
47
56
  check_status_code
48
57
  check_response_is_valid unless has_errors?
49
58
 
50
-
51
- if has_errors? && response.body.length > 0
59
+ if has_errors? && response.body.length.positive?
52
60
  @errors << "\nResponse body:\n #{JSON.pretty_generate(JSON.parse(response.body))}"
53
61
  end
54
62
 
@@ -62,19 +70,19 @@ FAIL
62
70
  def check_request_path
63
71
  if !swagger_checker.has_path?(@path)
64
72
  @errors << "Swagger doc: #{swagger_checker.swagger_path} does not have"\
65
- " a documented @path for #{@path}"
73
+ " a documented @path for #{@path}"
66
74
  elsif !swagger_checker.has_method_at_path?(@path, @verb)
67
75
  @errors << "Swagger doc: #{swagger_checker.swagger_path} does not have"\
68
- " a documented @path for #{@verb} #{@path}"
76
+ " a documented @path for #{@verb} #{@path}"
69
77
  elsif !swagger_checker.has_response_code_for_path?(@path, @verb, @expected_response_code)
70
78
  @errors << "Swagger doc: #{swagger_checker.swagger_path} does not have"\
71
- " a documented response code of #{@expected_response_code} at @path"\
72
- " #{@verb} #{@path}. "\
73
- "\n Available response codes: #{swagger_checker.response_codes_for_path(@path, @verb)}"
79
+ " a documented response code of #{@expected_response_code} at @path"\
80
+ " #{@verb} #{@path}. "\
81
+ "\n Available response codes: #{swagger_checker.response_codes_for_path(@path, @verb)}"
74
82
  elsif @verb == "get" && swagger_checker.fragment(@path, @verb, @expected_response_code).nil?
75
83
  @errors << "Swagger doc: #{swagger_checker.swagger_path} missing"\
76
- " response model for get request with #{@path} for code"\
77
- " #{@expected_response_code}"
84
+ " response model for get request with #{@path} for code"\
85
+ " #{@expected_response_code}"
78
86
  end
79
87
  end
80
88
 
@@ -83,56 +91,59 @@ FAIL
83
91
  end
84
92
 
85
93
  def apivore_build_path(path, data)
86
- path.scan(/\{([^\}]*)\}/).each do |param|
94
+ path.scan(/\{([^}]*)\}/).each do |param|
87
95
  key = param.first
88
- dkey = data && ( data[key] || data[key.to_sym] )
96
+ dkey = data && (data[key] || data[key.to_sym])
89
97
  if dkey
90
- path = path.gsub "{#{key}}", dkey.to_param.to_s
98
+ path = path.gsub("{#{key}}", dkey.to_param.to_s)
91
99
  else
92
100
  raise URI::InvalidURIError, "No substitution data found for {#{key}}"\
93
- " to test the path #{path}.", caller
101
+ " to test the path #{path}.", caller
94
102
  end
95
103
  end
96
- path + (data['_query_string'] ? "?#{data['_query_string'].to_param}" : '')
104
+ path + (data["_query_string"] ? "?#{data["_query_string"].to_param}" : "")
97
105
  end
98
106
 
99
- def has_errors?; !@errors.empty? end
107
+ def has_errors?
108
+ !@errors.empty?
109
+ end
100
110
 
101
- def failure_message; @errors.join(" ") end
111
+ def failure_message
112
+ @errors.join(" ")
113
+ end
102
114
 
103
115
  def check_status_code
104
116
  if response.status != @expected_response_code
105
117
  @errors << "Path #{@path} did not respond with expected status code."\
106
- " Expected #{@expected_response_code} got #{response.status}"\
107
- end
118
+ " Expected #{@expected_response_code} got #{response.status}"\
119
+ end
108
120
  end
109
121
 
110
122
  def check_response_is_valid
111
123
  swagger_errors = swagger_checker.has_matching_document_for(
112
124
  @path, @verb, response.status, response_body
113
125
  )
114
- unless swagger_errors.empty?
115
- @errors.concat(
116
- swagger_errors.map do |e|
117
- e.sub("'#", "'#{full_path}#").gsub(
118
- /^The property|in schema.*$/,''
119
- )
120
- end
121
- )
122
- end
126
+ return if swagger_errors.empty?
127
+
128
+ @errors.concat(
129
+ swagger_errors.map do |e|
130
+ e.sub("'#", "'#{full_path}#").gsub(
131
+ /^The property|in schema.*$/, ""
132
+ )
133
+ end
134
+ )
123
135
  end
124
136
 
125
137
  def response_body
126
138
  JSON.parse(response.body) if response.body && !response.body.empty?
127
139
  end
128
140
 
129
- def action_dispatch_request_args(path, params: {}, headers: {})
141
+ def action_dispatch_request(verb, path, params: {}, headers: {})
130
142
  if defined?(ActionPack) && ActionPack::VERSION::MAJOR >= 5
131
- [path, params: params, headers: headers]
143
+ send(verb, path, params: params, headers: headers)
132
144
  else
133
- [path, params, headers]
145
+ send(verb, path, params, headers)
134
146
  end
135
147
  end
136
148
  end
137
-
138
- end
149
+ end
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Mini
2
4
  module Apivore
3
- VERSION = "0.1.8"
5
+ VERSION = "0.3.0"
4
6
  end
5
7
  end
data/lib/mini_apivore.rb CHANGED
@@ -1,17 +1,24 @@
1
- require 'json-schema'
2
- require 'mini_apivore/version'
3
- require 'mini_apivore/fragment'
4
- require 'mini_apivore/swagger'
5
- require 'mini_apivore/swagger_checker'
6
- require 'mini_apivore/validation'
7
- require 'mini_apivore/http_codes'
8
- require 'mini_apivore/to_param'
1
+ # frozen_string_literal: true
2
+
3
+ require "json-schema"
4
+ require "mini_apivore/version"
5
+ require "mini_apivore/fragment"
6
+ require "mini_apivore/swagger"
7
+ require "mini_apivore/swagger_checker"
8
+ require "mini_apivore/validation"
9
+ require "mini_apivore/http_codes"
10
+ require "mini_apivore/to_param"
9
11
 
10
12
  module MiniApivore
11
13
  SWAGGER_CHECKERS = {}
12
14
  #----- Module globals -----------------
13
- def self.runnable_list; @@runnable_list ||= [] end
14
- def self.all_test_ran?; runnable_list.empty? end
15
+ def self.runnable_list
16
+ @@runnable_list ||= [] # rubocop:disable Style/ClassVars
17
+ end
18
+
19
+ def self.all_test_ran?
20
+ runnable_list.empty?
21
+ end
15
22
 
16
23
  def self.prepare_untested_errors
17
24
  errors = []
@@ -19,7 +26,7 @@ module MiniApivore
19
26
  chkr.untested_mappings.each do |path, methods|
20
27
  methods.each do |method, codes|
21
28
  codes.each do |code, _|
22
- errors << "#{method} #{path} is untested for response code #{code} in test class #{cls.to_s}"
29
+ errors << "#{method} #{path} is untested for response code #{code} in test class #{cls}"
23
30
  end
24
31
  end
25
32
  end
@@ -28,26 +35,25 @@ module MiniApivore
28
35
  end
29
36
 
30
37
  def self.included(base)
31
- base.extend ClassMethods
32
- base.include MiniApivore::Validation
38
+ base.extend(ClassMethods)
39
+ base.include(MiniApivore::Validation)
33
40
  end
34
41
 
35
42
  #---- class methods -----------
36
43
  module ClassMethods
37
-
38
- def init_swagger( swagger_path, schema= '' )
44
+ def init_swagger(swagger_path, schema = "")
39
45
  SWAGGER_CHECKERS[self] ||= MiniApivore::SwaggerChecker.instance_for(swagger_path, schema)
40
46
  end
41
47
 
42
48
  def runnable_methods
43
- super | ['final_test']
49
+ super | ["final_test"]
44
50
  end
45
51
 
46
- def test(name, &block )
47
- super( name, &block ).tap{ |sym| MiniApivore.runnable_list << "#{to_s}::#{sym}" }
52
+ def test(name, &block)
53
+ super(name, &block).tap { |sym| MiniApivore.runnable_list << "#{self}::#{sym}" }
48
54
  end
49
55
 
50
- def swagger_checker;
56
+ def swagger_checker
51
57
  SWAGGER_CHECKERS[self]
52
58
  end
53
59
  end
@@ -55,7 +61,7 @@ module MiniApivore
55
61
  #----- Minitest callback -----------
56
62
  def teardown
57
63
  super
58
- MiniApivore.runnable_list.delete( "#{self.class.to_s}::#{@NAME}" )
64
+ MiniApivore.runnable_list.delete("#{self.class}::#{@NAME}")
59
65
  end
60
66
 
61
67
  #----- test for untested routes ---------
@@ -63,13 +69,9 @@ module MiniApivore
63
69
  return unless MiniApivore.all_test_ran?
64
70
 
65
71
  @errors = MiniApivore.prepare_untested_errors
66
- assert( @errors.empty?, @errors.join("\n") )
72
+ assert(@errors.empty?, @errors.join("\n"))
67
73
 
68
74
  # preventing duplicate execution
69
- MiniApivore.runnable_list << "#{self.class.to_s}::#{__method__}_runned"
75
+ MiniApivore.runnable_list << "#{self.class}::#{__method__}_runned"
70
76
  end
71
-
72
-
73
77
  end
74
-
75
-
metadata CHANGED
@@ -1,57 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mini-apivore
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - alekseyl
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-07-02 00:00:00.000000000 Z
11
+ date: 2022-07-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: json-schema
14
+ name: hashie
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '2.5'
19
+ version: '3.3'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '2.5'
26
+ version: '3.3'
27
27
  - !ruby/object:Gem::Dependency
28
- name: minitest
28
+ name: json-schema
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '5.0'
33
+ version: '2.5'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '5.0'
40
+ version: '2.5'
41
41
  - !ruby/object:Gem::Dependency
42
- name: hashie
42
+ name: minitest
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '3.3'
47
+ version: '5.0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '3.3'
54
+ version: '5.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: pry
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: 12.3.3
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop-shopify
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
83
97
  description: " Minitest adaptation of apivore gem,\n Provides
84
98
  a tool for testing your application api against your swagger schema "
85
99
  email:
@@ -104,7 +118,7 @@ licenses:
104
118
  - MIT
105
119
  metadata:
106
120
  allowed_push_host: https://rubygems.org
107
- post_install_message:
121
+ post_install_message:
108
122
  rdoc_options: []
109
123
  require_paths:
110
124
  - lib
@@ -120,9 +134,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
134
  - !ruby/object:Gem::Version
121
135
  version: '0'
122
136
  requirements: []
123
- rubyforge_project:
124
- rubygems_version: 2.7.6
125
- signing_key:
137
+ rubygems_version: 3.2.15
138
+ signing_key:
126
139
  specification_version: 4
127
140
  summary: Minitest adaptation of an apivore gem
128
141
  test_files: []