rack-test-poc 1.1.0 → 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: 46a3bb92ca40f94800c03a6a051131225680c1a6
4
- data.tar.gz: b1d1e08780a95399be8d8d13acc9b9be79315b14
3
+ metadata.gz: cce9633d21092ba28d822d448effd6ffe1e0ba18
4
+ data.tar.gz: c5985ca6394c44769bb4ef9a39c624d0f308719f
5
5
  SHA512:
6
- metadata.gz: af9deb1af48aa3204949d790b705f20e25bed5527f9041f21c46421f6e2c64b96de8bb2f6c5392c9e9cd84d01782446b7aae0d4808aa022a3393c14583713e20
7
- data.tar.gz: 2bf4efcd8e3bba1416bdafc8336f34b881f554f5ccf75e929cf57e5d2f37d7b9dbc235064b708f4570a2dd3fed6c6811ef6c54e2db5795aab17e46898eb7a1ef
6
+ metadata.gz: b9a612216dfdd57272d5e0345670b221b9dd04c01b215629406c65ae88f7455b39921e42b83f0f93069faa831516e55cbca371f162fdb3e4dd4f9ba1ba450039
7
+ data.tar.gz: 6ba7a28169ef568020bb87b2b787d619de06723349b3a891458528393282ba535bcfdbe6cb9a878ed6f4e8d1aad85e20ebb6b8e503fa6b44168b8bcd8d9cfa0f
data/README.md CHANGED
@@ -28,6 +28,10 @@ All you need to do is to require 'rack/test/poc' in your test_helper
28
28
  when you working with rack-test module,
29
29
  and you good to go!
30
30
 
31
+ If you can, you should always describe with :is_for object methods, the response content,
32
+ so it can be easy to analyze out from the poc file, or even can be used in documentation generating!
33
+ With that you can make Google Api docs level documentations!
34
+
31
35
  ### example
32
36
 
33
37
  ```ruby
@@ -57,6 +61,11 @@ describe 'AppTest' do
57
61
 
58
62
  #> bla bla bla some code here
59
63
  last_response.body #> '{"msg":"Hello Rack!"}'
64
+
65
+ #> you should describe a response so it can be easy to understand from the poc!
66
+ resp = JSON.parse(last_response.body)
67
+ resp['msg'].desc 'Hy'
68
+ resp['data']['key'].desc 'bye'
60
69
 
61
70
  end
62
71
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.0
1
+ 2.0.0
data/lib/rack/test/poc.rb CHANGED
@@ -1,18 +1,95 @@
1
+ require 'minitest/unit'
2
+
1
3
  module RackTestPoc
2
4
 
3
- def self.root
4
- if defined?(Rails) && Rails.respond_to?(:root) && !!Rails.root
5
- Rails.root.to_s
6
- elsif !!ENV['BUNDLE_GEMFILE']
7
- ENV['BUNDLE_GEMFILE'].split(File::Separator)[0..-2].join(File::Separator)
8
- else
9
- Dir.pwd
5
+ module ObjectExt
6
+
7
+ def is_for(description_text)
8
+ return unless RackTestPoc.last_poc
9
+
10
+ old_body = RackTestPoc.last_poc['response']['body']['object']
11
+ RackTestPoc.last_poc['response']['body']['description'] ||= ->{
12
+
13
+ begin
14
+ JSON.parse(old_body.to_json) #> hard clone
15
+ rescue
16
+ old_body.dup rescue old_body
17
+ end
18
+
19
+ }.call
20
+
21
+ desc_body = RackTestPoc.last_poc['response']['body']['description']
22
+ RackTestPoc.description_helper(desc_body,self,description_text)
23
+
24
+ nil
25
+
10
26
  end
27
+
11
28
  end
12
29
 
13
- def self.dump_obj
14
- @dump_obj ||= Hash.new
15
- end;self.dump_obj #> eager load for multiThread
30
+ ::Object.__send__ :include, ObjectExt
31
+
32
+ class << self
33
+
34
+ def desc_comp_search(container,object,description_text)
35
+ case container
36
+
37
+ when Array
38
+ if container.index(object)
39
+ container[container.index(object)]= description_text
40
+ else
41
+ container.each do |element|
42
+ desc_comp_search(element,object,description_text)
43
+ end
44
+ end
45
+
46
+ when Hash
47
+ if container.key(object)
48
+ container[container.key(object)]= description_text
49
+ else
50
+ container.each { |k,v| desc_comp_search(v,object,description_text) }
51
+ end
52
+
53
+ end
54
+ end
55
+
56
+ def description_helper(container,object,description_text)
57
+ case container
58
+
59
+ when Array,Hash
60
+ desc_comp_search(container,object,description_text)
61
+
62
+ else
63
+ RackTestPoc.last_poc['response']['body']['description']=description_text
64
+
65
+ end
66
+
67
+ end
68
+
69
+ def root
70
+ if defined?(Rails) && Rails.respond_to?(:root) && !!Rails.root
71
+ Rails.root.to_s
72
+ elsif !!ENV['BUNDLE_GEMFILE']
73
+ ENV['BUNDLE_GEMFILE'].split(File::Separator)[0..-2].join(File::Separator)
74
+ else
75
+ Dir.pwd
76
+ end
77
+ end
78
+
79
+ def dump_object
80
+ @dump_object ||= Hash.new
81
+ end
82
+
83
+ def last_poc=(last_poc)
84
+ @last_poc=last_poc
85
+ end
86
+
87
+ def last_poc
88
+ @last_poc
89
+ end
90
+
91
+ end
92
+ self.dump_object #> eager load for multiThread
16
93
 
17
94
  module EXT
18
95
 
@@ -26,9 +103,9 @@ module RackTestPoc
26
103
  dump_dir = File.join RackTestPoc.root,'test','poc'
27
104
  FileUtils.mkdir_p(dump_dir) unless File.exist?(dump_dir)
28
105
 
29
- unless RackTestPoc.dump_obj.empty?
106
+ unless RackTestPoc.dump_object.empty?
30
107
  File.write File.join(dump_dir,Time.now.to_i.to_s.concat('.yaml')),
31
- RackTestPoc.dump_obj.to_yaml
108
+ RackTestPoc.dump_object.to_yaml
32
109
 
33
110
  end
34
111
 
@@ -44,8 +121,8 @@ module RackTestPoc
44
121
 
45
122
  request_method_str = env['REQUEST_METHOD'].to_s.upcase
46
123
 
47
- RackTestPoc.dump_obj[uri] ||= {}
48
- RackTestPoc.dump_obj[uri][request_method_str] ||= {}
124
+ RackTestPoc.dump_object[uri] ||= {}
125
+ RackTestPoc.dump_object[uri][request_method_str] ||= {}
49
126
 
50
127
  begin
51
128
 
@@ -71,8 +148,8 @@ module RackTestPoc
71
148
 
72
149
  end
73
150
 
74
- RackTestPoc.dump_obj[uri][request_method_str]['response'] ||= {}
75
- RackTestPoc.dump_obj[uri][request_method_str]['request'] ||= {}
151
+ RackTestPoc.dump_object[uri][request_method_str]['response'] ||= {}
152
+ RackTestPoc.dump_object[uri][request_method_str]['request'] ||= {}
76
153
 
77
154
  raw_query = env.find{|k,v|
78
155
  %W[ QUERY_STRING rack.request.form_vars ].any?{|tag| k == tag && !v.nil? && v != '' }
@@ -89,24 +166,28 @@ module RackTestPoc
89
166
 
90
167
  end
91
168
 
92
- RackTestPoc.dump_obj[uri][request_method_str]['request']['query'] ||= {}
93
- RackTestPoc.dump_obj[uri][request_method_str]['request']['query']['raw'] = raw_query
94
- RackTestPoc.dump_obj[uri][request_method_str]['request']['query']['object'] = query_hash
95
- RackTestPoc.dump_obj[uri][request_method_str]['request']['headers'] = @headers
169
+ RackTestPoc.dump_object[uri][request_method_str]['request']['query'] ||= {}
170
+ RackTestPoc.dump_object[uri][request_method_str]['request']['query']['raw'] = raw_query
171
+ RackTestPoc.dump_object[uri][request_method_str]['request']['query']['object'] = query_hash
172
+ RackTestPoc.dump_object[uri][request_method_str]['request']['headers'] = @headers
96
173
 
97
- RackTestPoc.dump_obj[uri][request_method_str]['response']['body'] = body
98
- RackTestPoc.dump_obj[uri][request_method_str]['response']['raw_body'] = last_response.body
174
+ RackTestPoc.dump_object[uri][request_method_str]['response']['body']= {}
99
175
 
100
- RackTestPoc.dump_obj[uri][request_method_str]['response']['headers']= env.reduce({}){
101
- |m,o| m.merge!(o[0]=>o[1]) if o[0].to_s.downcase =~ /^http_/ ; m
102
- }
103
-
104
- RackTestPoc.dump_obj[uri][request_method_str]['response']['status']= last_response.status
105
- RackTestPoc.dump_obj[uri][request_method_str]['response']['format']= format
176
+ RackTestPoc.dump_object[uri][request_method_str]['response']['body']['object'] = body
177
+ RackTestPoc.dump_object[uri][request_method_str]['response']['body']['raw'] = last_response.body
106
178
 
107
- if env['CONTENT_TYPE']
108
- RackTestPoc.dump_obj[uri][request_method_str]['response']['content_type']= env['CONTENT_TYPE']
109
- end
179
+ # RackTestPoc.dump_object[uri][request_method_str]['response']['headers']= env.reduce({}){
180
+ # |m,o| m.merge!(o[0]=>o[1]) if o[0].to_s.downcase =~ /^http_/ ; m
181
+ # }
182
+
183
+ RackTestPoc.dump_object[uri][request_method_str]['response']['status']= last_response.status
184
+ RackTestPoc.dump_object[uri][request_method_str]['response']['format']= format
185
+
186
+ # if env['CONTENT_TYPE']
187
+ # RackTestPoc.dump_object[uri][request_method_str]['response']['content_type']= env['CONTENT_TYPE']
188
+ # end
189
+
190
+ RackTestPoc.last_poc = RackTestPoc.dump_object[uri][request_method_str]
110
191
 
111
192
  return last_response
112
193
 
@@ -3,7 +3,8 @@ require 'rack'
3
3
 
4
4
  class APP
5
5
  def self.call(env)
6
- [200, {"Content-Type" => "application/json"}, '{"msg":"Hello Rack!"}']
6
+ [200, {"Content-Type" => "application/json"}, '{"msg":"Hello Rack!","data":{"key":"value"}}']
7
+ # [200, {"Content-Type" => "text/html"}, 'true']
7
8
  end
8
9
  end
9
10
 
@@ -27,6 +28,13 @@ describe 'AppTest' do
27
28
 
28
29
  last_response.body #> '{"msg":"Hello Rack!"}'
29
30
 
31
+ resp = JSON.parse(last_response.body)
32
+ resp['msg'].is_for 'Hy'
33
+ resp['data']['key'].is_for 'bye'
34
+
35
+ # last_response.body.desc 'boolean response'
36
+
37
+
30
38
  end
31
39
 
32
40
 
@@ -7,7 +7,7 @@ describe 'POCTest' do
7
7
 
8
8
  specify 'it should be made able to made a poc at exiting from the process' do
9
9
 
10
- $stdout.puts `bundle exec ruby #{File.join __dir__,'dummy.rb'}`
10
+ $stdout.puts `bundle exec ruby #{File.join __dir__,'test_description.rb'}`
11
11
 
12
12
  begin
13
13
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-test-poc
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Luzsi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-04 00:00:00.000000000 Z
11
+ date: 2014-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -72,7 +72,7 @@ files:
72
72
  - lib/rack-test-poc.rb
73
73
  - lib/rack/test/poc.rb
74
74
  - rack-test-poc.gemspec
75
- - test/dummy.rb
75
+ - test/test_description.rb
76
76
  - test/test_poc_generation.rb
77
77
  homepage: https://github.com/adamluzsi/rack-test-poc
78
78
  licenses: []
@@ -98,6 +98,6 @@ signing_key:
98
98
  specification_version: 4
99
99
  summary: rack/test based poc file generator
100
100
  test_files:
101
- - test/dummy.rb
101
+ - test/test_description.rb
102
102
  - test/test_poc_generation.rb
103
103
  has_rdoc: