fitting 1.3.1 → 1.4.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
  SHA1:
3
- metadata.gz: f6a1bfcb1667b2ca245f0c59adb47194c6a2798a
4
- data.tar.gz: 8ef0148851c9ecd7138e3d34a1d34fe7f6d61bbb
3
+ metadata.gz: 56f3f0f488cdee6be583ce31472dafab117afb58
4
+ data.tar.gz: 3e082349195724b60655350d648b726420118bdb
5
5
  SHA512:
6
- metadata.gz: 341b07818c2a02f7c8eff4cadabf036bd1af106703c587d43299de8cf6745610783d8b3c74c8b16b1d14cd1f6c5f6b815161ab99d49f26ae437578f8869fe739
7
- data.tar.gz: 85d611cd383932ddeff2f6e7b5421aa757a15e5491627b293c588601d99ac21e8d0b4144c415949c72c55a09ccd3072643e3b7ae96fd619f3bf479d7c1a0d0b6
6
+ metadata.gz: b0084485379e61b738e6afb271fcfd6817dc10e6884ee16282b7186a4e342a0612318223c3e80abc932e711dd376d84a54a4c91ace4ad7d5561327e38e78344e
7
+ data.tar.gz: 0440e437b56e83c8450408b3ac0fb9dba4217c57960e736d73a55e715e8a7fd7ac5e882a30d674002655b4f39acddd59690c013c30e316095faf22776de4bcd9
data/README.md CHANGED
@@ -61,6 +61,23 @@ end
61
61
 
62
62
  Default `true`. It returns `exit 1` if not implemented all(with tests expect match response) the responses.
63
63
 
64
+ ### white_list
65
+
66
+ Default all resources. This is an array of resources that are mandatory for implementation.
67
+ This list does not affect the work of the match expert.
68
+ This list is only for the report in the console and verify implementation.
69
+
70
+ ```ruby
71
+ config.white_list = {
72
+ '/users' => ['DELETE', 'POST'],
73
+ '/users/{id}' => ['GET', 'PATCH'],
74
+ '/users/{id}/employees' => ['GET'],
75
+ '/sessions' => []
76
+ }
77
+ ```
78
+
79
+ Empty array `[]` means all methods.
80
+
64
81
  ## Report
65
82
 
66
83
  Autogenerate `report_request_by_response.yaml` and `report_response.yaml reports`.
data/lib/fitting.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'fitting/version'
2
2
  require 'fitting/configuration'
3
3
  require 'fitting/documentation/response/route'
4
+ require 'fitting/documentation/response/routes'
4
5
  require 'fitting/documentation/request/route'
5
6
  require 'fitting/storage/responses'
6
7
  require 'fitting/storage/documentation'
@@ -33,19 +34,28 @@ module RSpec
33
34
 
34
35
  return returned_exit_code if Fitting::Storage::Skip.get
35
36
 
36
- response_routes = Fitting::Documentation::Response::Route.new(
37
+ responses_routes = Fitting::Documentation::Response::Routes.new(
37
38
  Fitting::Storage::Documentation.hash,
38
- Fitting::Storage::Responses.all
39
+ Fitting.configuration.white_list
39
40
  )
40
- request_routes = Fitting::Documentation::Request::Route.new(response_routes)
41
41
 
42
- request_routes.conformity_lists
43
- request_routes.statistics
44
- response_routes.statistics
42
+ puts '[Black list]'
43
+ response_routes_black = Fitting::Documentation::Response::Route.new(
44
+ Fitting::Storage::Responses.all,
45
+ responses_routes.black
46
+ )
47
+ response_routes_black.statistics
48
+
49
+ puts '[White list]'
50
+ response_routes_white = Fitting::Documentation::Response::Route.new(
51
+ Fitting::Storage::Responses.all,
52
+ responses_routes.white
53
+ )
54
+ response_routes_white.statistics_with_conformity_lists
45
55
 
46
56
  if Fitting.configuration.necessary_fully_implementation_of_responses &&
47
57
  returned_exit_code == 0 &&
48
- response_routes.not_coverage.present?
58
+ response_routes_white.not_coverage.present?
49
59
  return ERROR_EXIT_CODE
50
60
  end
51
61
  returned_exit_code
@@ -1,7 +1,8 @@
1
1
  module Fitting
2
2
  class Configuration
3
3
  attr_accessor :tomogram,
4
- :necessary_fully_implementation_of_responses
4
+ :necessary_fully_implementation_of_responses,
5
+ :white_list
5
6
 
6
7
  def initialize
7
8
  @necessary_fully_implementation_of_responses = true
@@ -93,7 +93,7 @@ module Fitting
93
93
  end
94
94
 
95
95
  def conformity_lists
96
- puts "Conforming requests: \n#{fully_implemented.join("\n")}"
96
+ puts "Fully conforming requests: \n#{fully_implemented.join("\n")}"
97
97
  puts
98
98
  puts "Partially conforming requests: \n#{partially_implemented.join("\n")}"
99
99
  puts
@@ -1,42 +1,25 @@
1
1
  require 'multi_json'
2
+ require 'fitting/documentation/request/route'
2
3
 
3
4
  module Fitting
4
5
  module Documentation
5
6
  module Response
6
7
  class Route
7
- def initialize(tomogram, coverage_responses)
8
- @tomogram = tomogram
8
+ def initialize(coverage_responses, responses_routes)
9
9
  @coverage_responses = coverage_responses
10
+ @responses_routes = responses_routes
10
11
  end
11
12
 
12
13
  def coverage
13
- @coverage ||= @coverage_responses.map do |response|
14
- response.route if response.documented? && response.valid?
15
- end.compact.uniq
14
+ @coverage ||= @responses_routes - (@responses_routes - full_coverage)
16
15
  end
17
16
 
18
17
  def not_coverage
19
- @not_coverage ||= all - coverage
20
- end
21
-
22
- def all
23
- @all ||= MultiJson.load(@tomogram).inject([]) do |routes, request|
24
- request['responses'].inject({}) do |responses, response|
25
- responses[response['status']] ||= 0
26
- responses[response['status']] += 1
27
- responses
28
- end.map do |status, indexes|
29
- indexes.times do |index|
30
- route = "#{request['method']}\t#{request['path']} #{status} #{index}"
31
- routes.push(route)
32
- end
33
- end
34
- routes
35
- end.uniq
18
+ @not_coverage ||= @responses_routes - coverage
36
19
  end
37
20
 
38
21
  def cover_ratio
39
- @cover_ratio ||= (coverage.size.to_f / all.size.to_f * 100.0).round(2)
22
+ @cover_ratio ||= (coverage.size.to_f / @responses_routes.size.to_f * 100.0).round(2)
40
23
  end
41
24
 
42
25
  def to_hash
@@ -46,16 +29,33 @@ module Fitting
46
29
  }
47
30
  end
48
31
 
32
+ def statistics_with_conformity_lists
33
+ @request_routes ||= Fitting::Documentation::Request::Route.new(self)
34
+ @request_routes.conformity_lists
35
+ statistics
36
+ end
37
+
49
38
  def statistics
39
+ @request_routes ||= Fitting::Documentation::Request::Route.new(self)
40
+ @request_routes.statistics
41
+
50
42
  valid_count = coverage.size
51
43
  valid_percentage = cover_ratio
52
- total_count = all.size
44
+ total_count = @responses_routes.size
53
45
  invalid_count = not_coverage.size
54
46
  invalid_percentage = 100.0 - cover_ratio
55
47
  puts "API responses conforming to the blueprint: #{valid_count} (#{valid_percentage}% of #{total_count})."
56
48
  puts "API responses with validation errors or untested: #{invalid_count} (#{invalid_percentage}% of #{total_count})."
57
49
  puts
58
50
  end
51
+
52
+ private
53
+
54
+ def full_coverage
55
+ @coverage_responses.map do |response|
56
+ response.route if response.documented? && response.valid?
57
+ end.compact.uniq
58
+ end
59
59
  end
60
60
  end
61
61
  end
@@ -0,0 +1,53 @@
1
+ require 'multi_json'
2
+ require 'fitting/documentation/request/route'
3
+
4
+ module Fitting
5
+ module Documentation
6
+ module Response
7
+ class Routes
8
+ def initialize(tomogram, white_list)
9
+ @tomogram = tomogram
10
+ @white_list = white_list
11
+ end
12
+
13
+ def black
14
+ if @white_list
15
+ all.select do |response|
16
+ data = response.split(' ')
17
+ data[1] && !@white_list[data[1]] || (@white_list[data[1]] != [] && !@white_list[data[1]].include?(data[0]))
18
+ end
19
+ else
20
+ []
21
+ end
22
+ end
23
+
24
+ def white
25
+ if @white_list
26
+ all.select do |response|
27
+ data = response.split(' ')
28
+ data[1] && @white_list[data[1]] && (@white_list[data[1]] == [] || @white_list[data[1]].include?(data[0]))
29
+ end
30
+ else
31
+ all
32
+ end
33
+ end
34
+
35
+ def all
36
+ @all ||= MultiJson.load(@tomogram).inject([]) do |routes, request|
37
+ request['responses'].inject({}) do |responses, response|
38
+ responses[response['status']] ||= 0
39
+ responses[response['status']] += 1
40
+ responses
41
+ end.map do |status, indexes|
42
+ indexes.times do |index|
43
+ route = "#{request['method']}\t#{request['path']} #{status} #{index}"
44
+ routes.push(route)
45
+ end
46
+ end
47
+ routes
48
+ end.uniq
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -1,3 +1,3 @@
1
1
  module Fitting
2
- VERSION = '1.3.1'.freeze
2
+ VERSION = '1.4.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fitting
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - d.efimov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-03-03 00:00:00.000000000 Z
11
+ date: 2017-03-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json-schema
@@ -214,6 +214,7 @@ files:
214
214
  - lib/fitting/configuration.rb
215
215
  - lib/fitting/documentation/request/route.rb
216
216
  - lib/fitting/documentation/response/route.rb
217
+ - lib/fitting/documentation/response/routes.rb
217
218
  - lib/fitting/matchers/response_matcher.rb
218
219
  - lib/fitting/request.rb
219
220
  - lib/fitting/response.rb