fitting 1.6.2 → 2.0.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: 687724fcdc1df94e6f43ead5dd7d07a2847c4957
4
- data.tar.gz: 86bbae4ea5919bd2b846b35430b2d55c976c037a
3
+ metadata.gz: 06aa35a9c436cb26d67b98c6e0b5f0a895154837
4
+ data.tar.gz: b00ac2fe2a7a6decec12900aac058b9ef289ee7e
5
5
  SHA512:
6
- metadata.gz: 94369cc36505eaa4fc30b70cea9583ad445508cee603f80151a263667cb6081c143bd2fa8ef05d3c83d5abe62f81034d166accd4cf45337f71deb10cd62c3913
7
- data.tar.gz: c3579f89a6ddf00adb0b24140edb570cb8fee0cb86445149edc0099ce92c3f35836940079b2d41ccdefdd608062c3bbd60447e54cd140b40b0852a2d9c4264cc
6
+ metadata.gz: bff39029299d63108358a8ba66809da543af39f08fd73647ca74e8d0dc396aa61cfc2c7033ab3f93166b5a57495c2afaf204da52ed1e505504522d2373c623a0
7
+ data.tar.gz: 94f4ab0036598e52ed418600c4a30ef04bbfa47ddb8de772073731217fbda75af0408793b3db0fd75da336f2fa791a02a4d868a3b00d12507ac02b74d936bb43
data/README.md CHANGED
@@ -26,14 +26,40 @@ Or install it yourself as:
26
26
  In your `spec_helper.rb`:
27
27
 
28
28
  ```ruby
29
- Fitting.configure do |config|
30
- config.apib_path = '/path/to/doc.apib'
29
+ require 'fitting'
30
+
31
+ Fitting.statistics
32
+
33
+ Fitting.configure do |config|
34
+ config.apib_path = '/path/to/doc.apib'
35
+ end
36
+ ```
37
+
38
+ or
39
+
40
+ ```ruby
41
+ require 'fitting'
42
+
43
+ responses = Fitting::Storage::Responses.new
44
+
45
+ RSpec.configure do |config|
46
+ config.after(:each, type: :controller) do
47
+ responses.add(response)
48
+ end
49
+
50
+ config.after(:suite) do
51
+ responses.statistics.save
31
52
  end
53
+ end
54
+
55
+ Fitting.configure do |config|
56
+ config.apib_path = '/path/to/doc.apib'
57
+ end
32
58
  ```
33
59
 
34
60
  ## Example output
35
61
 
36
- After running tests you will get statistics in the console:
62
+ After running tests you will get statistics in the file `fitting/stats`:
37
63
 
38
64
  ```
39
65
  Fully conforming requests:
@@ -59,6 +85,8 @@ API responses conforming to the blueprint: 16 (64.00% of 25).
59
85
  API responses with validation errors or untested: 9 (36.00% of 25).
60
86
  ```
61
87
 
88
+ Also you will get not covered responses in the file `fitting/not_covered`.
89
+
62
90
  ## Matchers
63
91
 
64
92
  If you want to know why you get crosses instead of checkmarks you can use matchers for RSpec.
@@ -67,20 +95,20 @@ If you want to know why you get crosses instead of checkmarks you can use matche
67
95
  config.include Fitting::Matchers, type: :controller
68
96
  ```
69
97
 
70
- ### match_response
98
+ ### match_schema
71
99
 
72
100
  Makes a simple validation against JSON Schema.
73
101
 
74
102
  ```ruby
75
- expect(response).to match_response
103
+ expect(response).to match_schema
76
104
  ```
77
105
 
78
- ### strict_match_response
106
+ ### strictly_match_schema
79
107
 
80
108
  Makes a strict validation against JSON Schema. All properties are condisidered to have `"required": true` and all objects `"additionalProperties": false`.
81
109
 
82
110
  ```ruby
83
- expect(response).to strict_match_response
111
+ expect(response).to strictly_match_schema
84
112
  ```
85
113
 
86
114
  ## Config
@@ -93,10 +121,6 @@ Path to API Blueprint documentation. There must be an installed [drafter](https:
93
121
 
94
122
  Path to API Blueprint documentation pre-parsed with `drafter` and saved to a YAML file.
95
123
 
96
- ### necessary_fully_implementation_of_responses
97
-
98
- Default `true`. It returns `exit 1` if not all responses are implemented according to the documentation. For this to work, `match_response` (see above) should run.
99
-
100
124
  ### strict
101
125
 
102
126
  Default `false`. If `true` then all properties are condisidered to have `"required": true` and all objects `"additionalProperties": false`.
@@ -122,14 +146,6 @@ config.white_list = {
122
146
 
123
147
  Empty array `[]` means all methods.
124
148
 
125
- ### create_report_with_name
126
-
127
- File name for the report.
128
-
129
- ### show_statistics_in_console
130
-
131
- Default `true`.
132
-
133
149
  ## Contributing
134
150
 
135
151
  Bug reports and pull requests are welcome on GitHub at https://github.com/funbox/fitting. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
data/fitting.gemspec CHANGED
@@ -22,7 +22,6 @@ Gem::Specification.new do |spec|
22
22
  spec.add_runtime_dependency 'json-schema', '~> 2.6', '>= 2.6.2'
23
23
  spec.add_runtime_dependency 'tomogram_routing', '~> 0.1', '>= 0.1.0'
24
24
  spec.add_runtime_dependency 'multi_json'
25
- spec.add_runtime_dependency 'rspec-core', '~> 3.0', '>= 3.0.0'
26
25
  spec.add_runtime_dependency 'tomograph', '~> 0.4', '>= 0.4.0'
27
26
  spec.add_development_dependency 'bundler', '~> 1.12'
28
27
  spec.add_development_dependency 'rake', '~> 10.0'
data/lib/fitting.rb CHANGED
@@ -1,15 +1,11 @@
1
1
  require 'fitting/version'
2
2
  require 'fitting/configuration'
3
3
  require 'fitting/storage/documentation'
4
- require 'fitting/storage/skip'
5
4
  require 'fitting/matchers/response_matcher'
6
- require 'rspec/core'
7
5
  require 'fitting/statistics'
8
6
  require 'fitting/documentation'
9
7
  require 'fitting/storage/responses'
10
8
 
11
- ERROR_EXIT_CODE = 1
12
-
13
9
  module Fitting
14
10
  class << self
15
11
  def configure
@@ -19,46 +15,19 @@ module Fitting
19
15
  def configuration
20
16
  @configuration ||= Configuration.new
21
17
  end
22
- end
23
- end
24
-
25
- module RSpec
26
- module Core
27
- # Provides the main entry point to run a suite of RSpec examples.
28
- class Runner
29
- alias origin_run_specs run_specs
30
18
 
31
- def run_specs(example_groups)
32
- returned_exit_code = origin_run_specs(example_groups)
19
+ def statistics
20
+ responses = Fitting::Storage::Responses.new
33
21
 
34
- return returned_exit_code if Fitting::Storage::Skip.get
35
-
36
- statistics = Fitting::Statistics.new(
37
- Fitting::Documentation.new(Fitting::Storage::Documentation.tomogram, Fitting.configuration.white_list),
38
- Fitting::Storage::Responses.all,
39
- Fitting.configuration.strict
40
- )
41
- puts statistics if Fitting.configuration.show_statistics_in_console
42
- if Fitting.configuration.create_report_with_name
43
- statistics.save(Fitting.configuration.create_report_with_name)
22
+ RSpec.configure do |config|
23
+ config.after(:each, type: :controller) do
24
+ responses.add(response)
44
25
  end
45
26
 
46
- if Fitting.configuration.necessary_fully_implementation_of_responses &&
47
- returned_exit_code == 0 &&
48
- statistics.not_coverage?
49
- return ERROR_EXIT_CODE
27
+ config.after(:suite) do
28
+ responses.statistics.save
50
29
  end
51
- returned_exit_code
52
30
  end
53
31
  end
54
32
  end
55
33
  end
56
-
57
- RSpec.configure do |config|
58
- config.after(:each, :type => :controller) do
59
- Fitting::Storage::Responses.push(
60
- Fitting::Response.new(
61
- response,
62
- Fitting::Storage::Documentation.tomogram))
63
- end
64
- end
@@ -2,19 +2,13 @@ module Fitting
2
2
  class Configuration
3
3
  attr_accessor :apib_path,
4
4
  :drafter_yaml_path,
5
- :necessary_fully_implementation_of_responses,
6
5
  :strict,
7
6
  :prefix,
8
- :white_list,
9
- :create_report_with_name,
10
- :tomogram,
11
- :show_statistics_in_console
7
+ :white_list
12
8
 
13
9
  def initialize
14
- @necessary_fully_implementation_of_responses = true
15
10
  @strict = false
16
11
  @prefix = ''
17
- @show_statistics_in_console = true
18
12
  end
19
13
  end
20
14
  end
@@ -59,11 +59,11 @@ module Fitting
59
59
  end
60
60
  end
61
61
 
62
- def match_response
62
+ def match_schema
63
63
  Response.new
64
64
  end
65
65
 
66
- def strict_match_response
66
+ def strictly_match_schema
67
67
  StrictResponse.new
68
68
  end
69
69
  end
@@ -1,5 +1,7 @@
1
1
  require 'fitting/request'
2
2
  require 'fitting/response/fully_validates'
3
+ require 'json'
4
+ require 'multi_json'
3
5
 
4
6
  module Fitting
5
7
  class Response
@@ -35,12 +37,12 @@ module Fitting
35
37
  end
36
38
 
37
39
  def got
38
- @body
40
+ JSON.pretty_generate(MultiJson.load(@body))
39
41
  end
40
42
 
41
43
  def expected
42
- @schemas.inject([]) do |res, schema|
43
- res.push("#{schema}")
44
+ @expected ||= @schemas.inject([]) do |res, schema|
45
+ res.push("#{JSON.pretty_generate(schema)}")
44
46
  end.join("\n\n")
45
47
  end
46
48
 
data/lib/fitting/route.rb CHANGED
@@ -10,16 +10,18 @@ module Fitting
10
10
  @responses = Fitting::Route::Responses.new(routes, @coverage)
11
11
  end
12
12
 
13
- def not_coverage?
14
- @coverage.not_coverage.present?
15
- end
16
-
17
13
  def statistics
18
14
  [@requests.statistics, @responses.statistics].join("\n\n")
19
15
  end
20
16
 
21
17
  def statistics_with_conformity_lists
18
+ return "All responses are 100% valid! Great job!\n" if @coverage.not_coverage.empty?
19
+
22
20
  [@requests.conformity_lists, statistics].join("\n\n")
23
21
  end
22
+
23
+ def errors
24
+ @coverage.not_coverage.join("\n") + "\n"
25
+ end
24
26
  end
25
27
  end
@@ -1,4 +1,5 @@
1
1
  require 'fitting/route'
2
+ require 'fileutils'
2
3
 
3
4
  module Fitting
4
5
  class Statistics
@@ -8,12 +9,10 @@ module Fitting
8
9
  @white_route = Fitting::Route.new(all_responses, @documentation.white, strict)
9
10
  end
10
11
 
11
- def not_coverage?
12
- @white_route.not_coverage?
13
- end
14
-
15
- def save(name)
16
- File.open(name, 'w') { |file| file.write(to_s) }
12
+ def save
13
+ FileUtils::mkdir_p 'fitting'
14
+ File.open('fitting/stats', 'w') { |file| file.write(to_s) }
15
+ File.open('fitting/not_covered', 'w') { |file| file.write(@white_route.errors) }
17
16
  end
18
17
 
19
18
  def to_s
@@ -7,23 +7,23 @@ module Fitting
7
7
  module Documentation
8
8
  class << self
9
9
  def tomogram
10
- @tomogram ||= if Fitting.configuration.apib_path
10
+ @tomogram ||= craft
11
+ end
12
+
13
+ def craft
14
+ if Fitting.configuration.apib_path
11
15
  @yaml ||= `drafter #{Fitting.configuration.apib_path}`
12
16
  Tomograph.configure do |config|
13
17
  config.drafter_yaml = @yaml
14
18
  config.prefix = Fitting.configuration.prefix
15
19
  end
16
- TomogramRouting::Tomogram.craft(Tomograph::Tomogram.json)
17
- elsif Fitting.configuration.tomogram
18
- # legacy
19
- TomogramRouting::Tomogram.craft(Fitting.configuration.tomogram)
20
20
  else
21
21
  Tomograph.configure do |config|
22
22
  config.documentation = Fitting.configuration.drafter_yaml_path
23
23
  config.prefix = Fitting.configuration.prefix
24
24
  end
25
- TomogramRouting::Tomogram.craft(Tomograph::Tomogram.json)
26
25
  end
26
+ TomogramRouting::Tomogram.craft(Tomograph::Tomogram.json)
27
27
  end
28
28
  end
29
29
  end
@@ -1,20 +1,25 @@
1
1
  module Fitting
2
2
  module Storage
3
- module Responses
4
- class << self
5
- def push(test)
6
- @responses ||= []
7
- @responses.push(test)
8
- end
3
+ class Responses
4
+ def initialize
5
+ @responses = []
6
+ end
9
7
 
10
- def all
11
- @responses ||= []
12
- @responses.uniq
13
- end
8
+ def add(response)
9
+ @responses.push(
10
+ Fitting::Response.new(
11
+ response,
12
+ Fitting::Storage::Documentation.tomogram))
13
+ end
14
14
 
15
- def nil?
16
- @responses.nil?
17
- end
15
+ def statistics
16
+ Fitting::Statistics.new(
17
+ Fitting::Documentation.new(
18
+ Fitting::Storage::Documentation.tomogram,
19
+ Fitting.configuration.white_list),
20
+ @responses.uniq,
21
+ Fitting.configuration.strict
22
+ )
18
23
  end
19
24
  end
20
25
  end
@@ -1,3 +1,3 @@
1
1
  module Fitting
2
- VERSION = '1.6.2'.freeze
2
+ VERSION = '2.0.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.6.2
4
+ version: 2.0.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-04-03 00:00:00.000000000 Z
11
+ date: 2017-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json-schema
@@ -64,26 +64,6 @@ dependencies:
64
64
  - - ">="
65
65
  - !ruby/object:Gem::Version
66
66
  version: '0'
67
- - !ruby/object:Gem::Dependency
68
- name: rspec-core
69
- requirement: !ruby/object:Gem::Requirement
70
- requirements:
71
- - - "~>"
72
- - !ruby/object:Gem::Version
73
- version: '3.0'
74
- - - ">="
75
- - !ruby/object:Gem::Version
76
- version: 3.0.0
77
- type: :runtime
78
- prerelease: false
79
- version_requirements: !ruby/object:Gem::Requirement
80
- requirements:
81
- - - "~>"
82
- - !ruby/object:Gem::Version
83
- version: '3.0'
84
- - - ">="
85
- - !ruby/object:Gem::Version
86
- version: 3.0.0
87
67
  - !ruby/object:Gem::Dependency
88
68
  name: tomograph
89
69
  requirement: !ruby/object:Gem::Requirement
@@ -244,7 +224,6 @@ files:
244
224
  - lib/fitting/statistics.rb
245
225
  - lib/fitting/storage/documentation.rb
246
226
  - lib/fitting/storage/responses.rb
247
- - lib/fitting/storage/skip.rb
248
227
  - lib/fitting/version.rb
249
228
  homepage: https://github.com/funbox/fitting
250
229
  licenses:
@@ -1,15 +0,0 @@
1
- module Fitting
2
- module Storage
3
- module Skip
4
- class << self
5
- def set(skip)
6
- @skip = skip
7
- end
8
-
9
- def get
10
- @skip ||= false
11
- end
12
- end
13
- end
14
- end
15
- end