fitting 2.18.3 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +2 -11
  3. data/CHANGELOG.md +6 -0
  4. data/README.md +46 -6
  5. data/fitting.gemspec +1 -1
  6. data/lib/fitting/configuration.rb +12 -6
  7. data/lib/fitting/cover/json_schema.rb +4 -2
  8. data/lib/fitting/cover/json_schema_enum.rb +4 -2
  9. data/lib/fitting/cover/json_schema_one_of.rb +4 -2
  10. data/lib/fitting/railtie.rb +1 -0
  11. data/lib/fitting/records/documented/request.rb +1 -15
  12. data/lib/fitting/records/spherical/requests.rb +1 -1
  13. data/lib/fitting/records/tested/request.rb +11 -11
  14. data/lib/fitting/records/tested/response.rb +4 -4
  15. data/lib/fitting/report/actions.rb +4 -0
  16. data/lib/fitting/report/prefix.rb +20 -41
  17. data/lib/fitting/report/prefixes.rb +7 -8
  18. data/lib/fitting/report/response.rb +0 -3
  19. data/lib/fitting/report/tests.rb +23 -10
  20. data/lib/fitting/storage/responses.rb +5 -9
  21. data/lib/fitting/tests.rb +12 -4
  22. data/lib/fitting/version.rb +1 -1
  23. data/lib/fitting.rb +38 -43
  24. data/lib/tasks/fitting.rake +2 -186
  25. data/lib/tasks/fitting_outgoing.rake +91 -0
  26. metadata +5 -41
  27. data/lib/fitting/configuration/yaml.rb +0 -89
  28. data/lib/fitting/cover/response.rb +0 -37
  29. data/lib/fitting/documentation.rb +0 -56
  30. data/lib/fitting/matchers/response_matcher.rb +0 -88
  31. data/lib/fitting/records/realized_unit.rb +0 -52
  32. data/lib/fitting/records/test_unit/request.rb +0 -98
  33. data/lib/fitting/records/unit/combination.rb +0 -27
  34. data/lib/fitting/records/unit/json_schema.rb +0 -111
  35. data/lib/fitting/records/unit/request.rb +0 -37
  36. data/lib/fitting/records/unit/response.rb +0 -32
  37. data/lib/fitting/request.rb +0 -38
  38. data/lib/fitting/response/fully_validates.rb +0 -34
  39. data/lib/fitting/response.rb +0 -88
  40. data/lib/fitting/statistics/analysis.rb +0 -25
  41. data/lib/fitting/statistics/cover_error.rb +0 -29
  42. data/lib/fitting/statistics/cover_error_enum.rb +0 -29
  43. data/lib/fitting/statistics/cover_error_one_of.rb +0 -29
  44. data/lib/fitting/statistics/great.rb +0 -13
  45. data/lib/fitting/statistics/list.rb +0 -55
  46. data/lib/fitting/statistics/lists.rb +0 -53
  47. data/lib/fitting/statistics/measurement.rb +0 -92
  48. data/lib/fitting/statistics/measurement_cover.rb +0 -92
  49. data/lib/fitting/statistics/measurement_cover_enum.rb +0 -92
  50. data/lib/fitting/statistics/measurement_cover_one_of.rb +0 -92
  51. data/lib/fitting/statistics/not_covered_responses.rb +0 -13
  52. data/lib/fitting/statistics/percent.rb +0 -20
  53. data/lib/fitting/statistics/requests_stats.rb +0 -40
  54. data/lib/fitting/statistics/responses_stats.rb +0 -32
  55. data/lib/fitting/statistics/template.rb +0 -117
  56. data/lib/fitting/statistics/template_cover_error.rb +0 -50
  57. data/lib/fitting/statistics/template_cover_error_enum.rb +0 -50
  58. data/lib/fitting/statistics/template_cover_error_one_of.rb +0 -50
  59. data/lib/fitting/statistics.rb +0 -25
  60. data/lib/fitting/storage/white_list.rb +0 -158
  61. data/lib/fitting/templates/realized_template.rb +0 -49
  62. data/lib/fitting/view/report.html.haml +0 -16
  63. data/lib/fitting/view/style.css +0 -47
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 140967f23d0706212f16a4239f33e409fbb0430e7e7295850501426992909eed
4
- data.tar.gz: 1178f1070ea69b6a1ed9e76cb7904c11a23e6d41652eba2fa587353c0e1cb6ef
3
+ metadata.gz: dd5c81c74bb7ce55eb47ff049359ea161454e320cdca8f44cd24dbfcc24f170e
4
+ data.tar.gz: 9535573515ab8652257ac1fbf76466e7e014f52460be6d76375625987814340a
5
5
  SHA512:
6
- metadata.gz: 7649a6fa86471ab46d38e67ec1ae9bd30141802a8169f966558db9fadd1db22fc904c2ff185870937831e93411aaf81fb44dffd16a9f87ac7e71c3cc40108c2b
7
- data.tar.gz: 9787db0e0c9bbd3f2f3b23fc0d10996642774838f41d974f3f90421b69a5d425c663d9675915a4275031d371f462aeeb799c71e2b819c2abe82df7faa1f2d1a9
6
+ metadata.gz: 8207fe1f0c4339a7e60978fc154a04525b0b0cd87a47e99c9007dc32fc302855b6b3078840681b020d79af6f7f19783266bd7d72efc1d2bc216271e8131682fa
7
+ data.tar.gz: 13bb82c38b30a054c8f37d3182001248af3e192646507f5737305b12529e01f291382697a42821e67c70360f17ed2df0836a004b57e5a02207b9bb91c2b45eee
data/.rubocop.yml CHANGED
@@ -13,27 +13,18 @@ Style/FrozenStringLiteralComment:
13
13
  Metrics/BlockLength:
14
14
  Enabled: false
15
15
 
16
- Style/CaseEquality:
17
- Enabled: false
18
-
19
- Style/NilComparison:
20
- Enabled: false
21
-
22
16
  Naming/MemoizedInstanceVariableName:
23
17
  Enabled: false
24
18
 
25
- Lint/UnreachableCode:
26
- Enabled: false
27
-
28
19
  Metrics/MethodLength:
29
- Max: 50
20
+ Max: 60
30
21
 
31
22
  # FIXME
32
23
  Metrics/AbcSize:
33
24
  Max: 50
34
25
 
35
26
  Metrics/PerceivedComplexity:
36
- Max: 20
27
+ Max: 30
37
28
 
38
29
  Metrics/CyclomaticComplexity:
39
30
  Max: 20
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Change log
2
2
 
3
+ ### 3.0.0 - 2021-12-09
4
+
5
+ * features
6
+ * update configuration
7
+ * support outgoing WebMock request
8
+
3
9
  ### 2.18.3 - 2021-11-12
4
10
 
5
11
  * patch
data/README.md CHANGED
@@ -48,7 +48,9 @@ Also Swagger
48
48
  ```yaml
49
49
  prefixes:
50
50
  - name: /api/v1
51
- openapi2_json_path: doc.json
51
+ type: openapi2
52
+ schema_paths:
53
+ - doc.json
52
54
  ```
53
55
 
54
56
  ### OpenAPI 3.0
@@ -57,7 +59,9 @@ Also OpenAPI
57
59
  ```yaml
58
60
  prefixes:
59
61
  - name: /api/v1
60
- openapi3_yaml_path: doc.yaml
62
+ type: openapi3
63
+ schema_paths:
64
+ - doc.yaml
61
65
  ```
62
66
 
63
67
  ### API Blueprint
@@ -75,7 +79,9 @@ and then
75
79
  ```yaml
76
80
  prefixes:
77
81
  - name: /api/v1
78
- drafter_yaml_path: doc.yaml
82
+ type: drafter
83
+ schema_paths:
84
+ - doc.yaml
79
85
  ```
80
86
 
81
87
  ### Tomograph
@@ -85,7 +91,9 @@ To use additional features of the pre-converted [tomograph](https://github.com/f
85
91
  ```yaml
86
92
  prefixes:
87
93
  - name: /api/v1
88
- tomogram_json_path: doc.json
94
+ type: tomogram
95
+ schema_paths:
96
+ - doc.json
89
97
  ```
90
98
 
91
99
  ## Run
@@ -99,6 +107,11 @@ and then
99
107
  bundle e rake fitting:report
100
108
  ```
101
109
 
110
+ Run tests by outgoing request first to get run artifacts
111
+ ```bash
112
+ bundle e rake fitting_out:report
113
+ ```
114
+
102
115
  Console ouptut
103
116
 
104
117
  ```text
@@ -144,7 +157,9 @@ Setting the prefix name is optional. For example, you can do this:
144
157
 
145
158
  ```yaml
146
159
  prefixes:
147
- - openapi2_json_path: doc.json
160
+ - type: openapi2
161
+ schema_paths:
162
+ - doc.json
148
163
  ```
149
164
 
150
165
  ## prefix skip
@@ -153,11 +168,36 @@ It is not necessary to immediately describe each prefix in detail, you can only
153
168
  ```yaml
154
169
  prefixes:
155
170
  - name: /api/v1
156
- openapi2_json_path: doc.json
171
+ type: openapi2
172
+ schema_paths:
173
+ - doc.json
174
+ - name: /api/v3
175
+ skip: true
176
+ ```
177
+
178
+ For work with WebMock outgoing request, you should set up outgoing prefixes
179
+ ```yaml
180
+ outgoing_prefixes:
181
+ - name: /api/v1
182
+ type: openapi2
183
+ schema_paths:
184
+ - doc.json
157
185
  - name: /api/v3
158
186
  skip: true
159
187
  ```
160
188
 
189
+ You can choose location that must be teste
190
+
191
+ ```yaml
192
+ prefixes:
193
+ - type: openapi2
194
+ schema_paths:
195
+ - doc.json
196
+ only:
197
+ - POST /api/v1/users
198
+ - GET /api/v1/user/{id}
199
+ ```
200
+
161
201
  ## Contributing
162
202
 
163
203
  Bug reports and pull requests are welcome on GitHub at [github.com/funbox/fitting](https://github.com/funbox/fitting).
data/fitting.gemspec CHANGED
@@ -27,6 +27,6 @@ Gem::Specification.new do |spec|
27
27
  spec.add_development_dependency 'byebug', '~> 11.1', '>= 11.1.3'
28
28
  spec.add_development_dependency 'rake', '~> 13.0', '>= 13.0.6'
29
29
  spec.add_development_dependency 'rspec', '~> 3.10'
30
- spec.add_development_dependency 'rubocop', '~> 1.22.0'
30
+ spec.add_development_dependency 'rubocop', '>= 1.22.0'
31
31
  spec.add_development_dependency 'simplecov', '~> 0.21'
32
32
  end
@@ -1,11 +1,17 @@
1
- require 'fitting/configuration/yaml'
2
- require 'yaml'
3
-
4
1
  module Fitting
5
2
  class Configuration
6
- def self.craft
7
- yaml = YAML.safe_load(File.read('.fitting.yml'))
8
- Fitting::Configuration::Yaml.new(yaml)
3
+ attr_accessor :rspec_json_path,
4
+ :webmock_json_path,
5
+ :fitting_report_path,
6
+ :prefixes,
7
+ :outgoing_prefixes
8
+
9
+ def initialize(config)
10
+ @rspec_json_path = config['rspec_json_path'] || './fitting_tests'
11
+ @fitting_report_path = config['fitting_report_path'] || './fitting'
12
+ @prefixes = config['prefixes'] || []
13
+ @webmock_json_path = config['webmock_json_path'] || './outgoing_request_tests'
14
+ @outgoing_prefixes = config['outgoing_prefixes'] || []
9
15
  end
10
16
  end
11
17
  end
@@ -1,14 +1,16 @@
1
1
  module Fitting
2
2
  class Cover
3
3
  class JSONSchema
4
+ attr_reader :json_schema, :combinations
5
+
4
6
  def initialize(json_schema)
5
7
  @json_schema = json_schema
6
8
  @combinations = []
7
9
  end
8
10
 
9
11
  def combi
10
- inception(@json_schema, @combinations).each do |combination|
11
- combination[0] = @json_schema.merge(combination[0])
12
+ inception(json_schema, combinations).each do |combination|
13
+ combination[0] = json_schema.merge(combination[0])
12
14
  combination[1] = ['required', combination[1]]
13
15
  end
14
16
  end
@@ -1,14 +1,16 @@
1
1
  module Fitting
2
2
  class Cover
3
3
  class JSONSchemaEnum
4
+ attr_reader :json_schema, :combinations
5
+
4
6
  def initialize(json_schema)
5
7
  @json_schema = json_schema
6
8
  @combinations = []
7
9
  end
8
10
 
9
11
  def combi
10
- inception(@json_schema, @combinations).each do |combination|
11
- combination[0] = @json_schema.merge(combination[0])
12
+ inception(json_schema, combinations).each do |combination|
13
+ combination[0] = json_schema.merge(combination[0])
12
14
  combination[1] = ['enum', combination[1]]
13
15
  end
14
16
  end
@@ -1,14 +1,16 @@
1
1
  module Fitting
2
2
  class Cover
3
3
  class JSONSchemaOneOf
4
+ attr_reader :json_schema, :combinations
5
+
4
6
  def initialize(json_schema)
5
7
  @json_schema = json_schema
6
8
  @combinations = []
7
9
  end
8
10
 
9
11
  def combi
10
- inception(@json_schema, @combinations).each do |combination|
11
- combination[0] = @json_schema.merge(combination[0])
12
+ inception(json_schema, combinations).each do |combination|
13
+ combination[0] = json_schema.merge(combination[0])
12
14
  combination[1] = ['one_of', combination[1]]
13
15
  end
14
16
  end
@@ -4,6 +4,7 @@ module Fitting
4
4
  class MyRailtie < Rails::Railtie
5
5
  rake_tasks do
6
6
  load 'tasks/fitting.rake'
7
+ load 'tasks/fitting_outgoing.rake'
7
8
  end
8
9
  end
9
10
  end
@@ -2,9 +2,8 @@ module Fitting
2
2
  class Records
3
3
  class Documented
4
4
  class Request
5
- def initialize(tomogram_request, white_list)
5
+ def initialize(tomogram_request)
6
6
  @tomogram_request = tomogram_request
7
- @white_list = white_list
8
7
  end
9
8
 
10
9
  def method
@@ -24,21 +23,8 @@ module Fitting
24
23
  end
25
24
  end
26
25
 
27
- def white
28
- @white ||= white?
29
- end
30
-
31
26
  private
32
27
 
33
- def white?
34
- return true if @white_list == nil
35
- return false if @white_list[path.to_s] == nil
36
- return true if @white_list[path.to_s] == []
37
- return true if @white_list[path.to_s].include?(method)
38
-
39
- false
40
- end
41
-
42
28
  def groups
43
29
  @groups ||= @tomogram_request.responses.group_by do |tomogram_response|
44
30
  tomogram_response['status']
@@ -10,7 +10,7 @@ module Fitting
10
10
 
11
11
  array = []
12
12
  Dir['fitting_tests/*.json'].each do |file|
13
- array += JSON.parse(File.read(file))
13
+ array += JSON.parse(file)
14
14
  end
15
15
  @to_a = array.inject([]) do |res, tested_request|
16
16
  request = Fitting::Records::Spherical::Request.load(tested_request)
@@ -6,33 +6,33 @@ module Fitting
6
6
  class Records
7
7
  class Tested
8
8
  class Request
9
- def initialize(env_response, metadata)
10
- @env_response = env_response
11
- @metadata = metadata
9
+ def initialize(response, example)
10
+ @example = example
11
+ @response = response
12
12
  end
13
13
 
14
14
  def method
15
- @method ||= @env_response.request.request_method
15
+ @method ||= @response.request.request_method
16
16
  end
17
17
 
18
18
  def path
19
- @path ||= Tomograph::Path.new(@env_response.request.env['PATH_INFO'] || @env_response.request.fullpath)
19
+ @path ||= Tomograph::Path.new(@response.request.fullpath)
20
20
  end
21
21
 
22
22
  def body
23
- @body ||= @env_response.request.env['action_dispatch.request.request_parameters']
23
+ @body ||= @response.request.request_parameters
24
24
  end
25
25
 
26
- def response
27
- @response ||= Fitting::Records::Tested::Response.new(@env_response)
26
+ def fitting_response
27
+ @fitting_response ||= Fitting::Records::Tested::Response.new(@response)
28
28
  end
29
29
 
30
30
  def test_path
31
- @test_path ||= @metadata.fetch(:location)
31
+ @test_path ||= @example.location
32
32
  end
33
33
 
34
34
  def test_file_path
35
- @test_file_path ||= @metadata.fetch(:file_path)
35
+ @test_file_path ||= @example.file_path
36
36
  end
37
37
 
38
38
  def to_spherical
@@ -40,7 +40,7 @@ module Fitting
40
40
  method: method,
41
41
  path: path,
42
42
  body: body,
43
- response: response.to_spherical,
43
+ response: fitting_response.to_spherical,
44
44
  title: test_path,
45
45
  group: test_file_path
46
46
  )
@@ -4,16 +4,16 @@ module Fitting
4
4
  class Records
5
5
  class Tested
6
6
  class Response
7
- def initialize(env_response)
8
- @env_response = env_response
7
+ def initialize(response)
8
+ @response = response
9
9
  end
10
10
 
11
11
  def status
12
- @status ||= @env_response.status
12
+ @status ||= @response.status
13
13
  end
14
14
 
15
15
  def body
16
- @body ||= @env_response.body
16
+ @body ||= @response.body
17
17
  end
18
18
 
19
19
  def to_spherical
@@ -14,6 +14,10 @@ module Fitting
14
14
  @actions
15
15
  end
16
16
 
17
+ def push(actions)
18
+ @actions += actions.to_a
19
+ end
20
+
17
21
  def join(tests)
18
22
  tests.to_a.map do |test|
19
23
  if there_a_suitable_action?(test)
@@ -3,53 +3,32 @@ require 'fitting/report/actions'
3
3
  module Fitting
4
4
  module Report
5
5
  class Prefix
6
- def initialize(name: '', openapi2_json_path: nil, openapi3_yaml_path: nil,
7
- drafter_yaml_path: nil, tomogram_json_path: nil, crafter_yaml_path: nil, skip: false)
6
+ KEYS = {
7
+ 'openapi2' => :openapi2_json_path,
8
+ 'openapi3' => :openapi3_yaml_path,
9
+ 'drafter' => :drafter_yaml_path,
10
+ 'crafter' => :crafter_yaml_path,
11
+ 'tomogram' => :tomogram_json_path
12
+ }.freeze
13
+
14
+ attr_reader :name, :tests, :actions
15
+
16
+ def initialize(schema_paths: nil, type: nil, name: '', skip: false, only: [])
8
17
  @name = name
9
- @tomogram_json_path = tomogram_json_path
10
18
  @tests = Fitting::Report::Tests.new([])
11
19
  @skip = skip
12
20
  return if skip
13
21
 
14
- @actions = if openapi2_json_path
15
- Fitting::Report::Actions.new(
16
- Tomograph::Tomogram.new(
17
- prefix: name,
18
- openapi2_json_path: openapi2_json_path
19
- )
20
- )
21
- elsif openapi3_yaml_path
22
- Fitting::Report::Actions.new(
23
- Tomograph::Tomogram.new(
24
- prefix: name,
25
- openapi3_yaml_path: openapi3_yaml_path
26
- )
27
- )
28
- elsif drafter_yaml_path
29
- Fitting::Report::Actions.new(
30
- Tomograph::Tomogram.new(
31
- prefix: name,
32
- drafter_yaml_path: drafter_yaml_path
33
- )
34
- )
35
- elsif crafter_yaml_path
36
- Fitting::Report::Actions.new(
37
- Tomograph::Tomogram.new(
38
- prefix: name,
39
- crafter_yaml_path: crafter_yaml_path
40
- )
41
- )
42
- else
43
- Fitting::Report::Actions.new(
44
- Tomograph::Tomogram.new(
45
- prefix: name,
46
- tomogram_json_path: tomogram_json_path
47
- )
48
- )
49
- end
50
- end
22
+ @actions = Fitting::Report::Actions.new([])
51
23
 
52
- attr_reader :name, :tests, :actions
24
+ schema_paths.each do |path|
25
+ tomogram = Tomograph::Tomogram.new(prefix: name, KEYS[type] => path)
26
+
27
+ tomogram.to_a.filter! { |action| only.include?("#{action.method} #{action.path}") } if only.present?
28
+
29
+ @actions.push(Fitting::Report::Actions.new(tomogram))
30
+ end
31
+ end
53
32
 
54
33
  def skip?
55
34
  @skip
@@ -3,18 +3,17 @@ require 'fitting/report/prefix'
3
3
  module Fitting
4
4
  module Report
5
5
  class Prefixes
6
- def initialize(config_path)
6
+ def initialize(configuration_prefixes)
7
7
  @prefixes = []
8
- YAML.safe_load(File.read(config_path))['prefixes'].map do |prefix|
8
+
9
+ configuration_prefixes.map do |prefix|
9
10
  @prefixes.push(
10
11
  Fitting::Report::Prefix.new(
12
+ schema_paths: prefix['schema_paths'],
13
+ type: prefix['type'],
11
14
  name: prefix['name'],
12
- openapi2_json_path: prefix['openapi2_json_path'],
13
- openapi3_yaml_path: prefix['openapi3_yaml_path'],
14
- drafter_yaml_path: prefix['drafter_yaml_path'],
15
- tomogram_json_path: prefix['tomogram_json_path'],
16
- crafter_yaml_path: prefix['crafter_yaml_path'],
17
- skip: prefix['skip']
15
+ skip: prefix['skip'],
16
+ only: prefix['only']
18
17
  )
19
18
  )
20
19
  end
@@ -1,6 +1,3 @@
1
- require 'fitting/statistics/template_cover_error'
2
- require 'fitting/statistics/template_cover_error_enum'
3
- require 'fitting/statistics/template_cover_error_one_of'
4
1
  require 'fitting/report/combinations'
5
2
  require 'fitting/report/combination'
6
3
 
@@ -3,13 +3,26 @@ require 'fitting/report/test'
3
3
  module Fitting
4
4
  module Report
5
5
  class Tests
6
+ attr_reader :tests
7
+
6
8
  def initialize(tests)
7
9
  @tests = tests
8
10
  end
9
11
 
10
- def self.new_from_config(tests_path)
12
+ def self.new_from_config
13
+ tests = []
14
+ Dir["#{Fitting.configuration.rspec_json_path}/*.json"].each do |file|
15
+ JSON.parse(File.read(file)).map do |test|
16
+ tests.push(Fitting::Report::Test.new(test))
17
+ end
18
+ end
19
+ tests.sort { |a, b| b.path <=> a.path }
20
+ new(tests)
21
+ end
22
+
23
+ def self.new_from_outgoing_config
11
24
  tests = []
12
- Dir[tests_path].each do |file|
25
+ Dir["#{Fitting.configuration.webmock_json_path}/*.json"].each do |file|
13
26
  JSON.parse(File.read(file)).map do |test|
14
27
  tests.push(Fitting::Report::Test.new(test))
15
28
  end
@@ -19,45 +32,45 @@ module Fitting
19
32
  end
20
33
 
21
34
  def without_prefixes
22
- @tests.each_with_object([]) do |test, result|
35
+ tests.each_with_object([]) do |test, result|
23
36
  result.push(test.path) unless test.there_a_prefix?
24
37
  end
25
38
  end
26
39
 
27
40
  def without_actions
28
- @tests.each_with_object([]) do |test, result|
41
+ tests.each_with_object([]) do |test, result|
29
42
  result.push("#{test.method} #{test.path}") unless test.there_an_actions?
30
43
  end
31
44
  end
32
45
 
33
46
  def without_responses
34
- @tests.each_with_object([]) do |test, result|
47
+ tests.each_with_object([]) do |test, result|
35
48
  result.push(test.id) unless test.there_an_responses?
36
49
  end
37
50
  end
38
51
 
39
52
  def without_combinations
40
- @tests.each_with_object([]) do |test, result|
53
+ tests.each_with_object([]) do |test, result|
41
54
  result.push(test.path) unless test.there_an_combinations?
42
55
  end
43
56
  end
44
57
 
45
58
  def push(test)
46
- @tests.push(test)
59
+ tests.push(test)
47
60
  end
48
61
 
49
62
  def size
50
- @tests.size
63
+ tests.size
51
64
  end
52
65
 
53
66
  def to_a
54
- @tests
67
+ tests
55
68
  end
56
69
 
57
70
  def to_h
58
71
  return @hash if @hash
59
72
 
60
- @hash = @tests.inject({}) do |res, test|
73
+ @hash = tests.inject({}) do |res, test|
61
74
  res.merge!(test.id => test.to_h)
62
75
  end
63
76
  end
@@ -1,24 +1,20 @@
1
- require 'fitting/statistics'
2
- require 'fitting/tests'
3
1
  require 'fitting/records/tested/request'
4
2
 
5
3
  module Fitting
6
4
  module Storage
7
5
  class Responses
6
+ attr_reader :tested_requests
7
+
8
8
  def initialize
9
9
  @tested_requests = []
10
10
  end
11
11
 
12
- def add(env_response, metadata = {})
13
- @tested_requests.push(Fitting::Records::Tested::Request.new(env_response, metadata))
14
- end
15
-
16
- def statistics
17
- Fitting::Statistics.new(@tested_requests)
12
+ def add(response, example)
13
+ tested_requests.push(Fitting::Records::Tested::Request.new(response, example))
18
14
  end
19
15
 
20
16
  def tests
21
- Fitting::Tests.new(@tested_requests)
17
+ Fitting::Tests.new(tested_requests)
22
18
  end
23
19
  end
24
20
  end
data/lib/fitting/tests.rb CHANGED
@@ -1,5 +1,3 @@
1
- require 'fitting/statistics/template'
2
-
3
1
  module Fitting
4
2
  class Tests
5
3
  def initialize(tested_requests)
@@ -7,13 +5,23 @@ module Fitting
7
5
  end
8
6
 
9
7
  def save
10
- make_dir('fitting_tests')
8
+ make_dir(Fitting.configuration.rspec_json_path)
9
+ array = @tested_requests.inject([]) do |res, request|
10
+ res.push(request.to_spherical.to_hash)
11
+ end
12
+ json = JSON.dump(array)
13
+
14
+ File.open("#{Fitting.configuration.rspec_json_path}/test#{ENV['TEST_ENV_NUMBER']}.json", 'w') { |file| file.write(json) }
15
+ end
16
+
17
+ def outgoing_save
18
+ make_dir('./outgoing_request_tests')
11
19
  array = @tested_requests.inject([]) do |res, request|
12
20
  res.push(request.to_spherical.to_hash)
13
21
  end
14
22
  json = JSON.dump(array)
15
23
 
16
- File.open("fitting_tests/test#{ENV['TEST_ENV_NUMBER']}.json", 'w') { |file| file.write(json) }
24
+ File.open("./outgoing_request_tests/test#{ENV['TEST_ENV_NUMBER']}.json", 'w') { |file| file.write(json) }
17
25
  end
18
26
 
19
27
  def make_dir(dir_name)
@@ -1,3 +1,3 @@
1
1
  module Fitting
2
- VERSION = '2.18.3'.freeze
2
+ VERSION = '3.0.0'.freeze
3
3
  end