rack-test-poc 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2716489bf4f677edc15b8b5ee70d7e3caaa1902d
4
- data.tar.gz: e0cbceda132bf55f2823eb45cd89283793cd0b22
3
+ metadata.gz: 8abaa5a14ca7bf666d2e4f932eccea6145f5d4bf
4
+ data.tar.gz: 0272b76fb384693b12fbebf4d20d03b791cf637d
5
5
  SHA512:
6
- metadata.gz: 000f19b2fa399594743a247ad8531d482239b35660b42d72169fa9eb707d5f791d34edfd07872a814839de109ba9608d4e8b288ffbcf3de9293ad5de6abfbeac
7
- data.tar.gz: 97731ce78b49c8ff22f205071283465c59616a75f9b23db8bf854c66f98a88207e0b46532c9eb5e886d0a91f5d9c8f2311ddfb012592432011d59f85bd6e4653
6
+ metadata.gz: 2e23a6d95d2d78752d54dc5ebe6d8f26186f7a62e1c42d8cec6d28bd43788eda7392074e7289663878ba92419d6879f51547c5678759a932a32f991904f9f8c2
7
+ data.tar.gz: 189c0002bccd8768a0f5c2abca38901a5cf6b14111b882a367ad4302518cd0618ce662cc871a6c7491cace7909d4ee69645c5af12351219f5c2da7a4fa566955
data/README.md CHANGED
@@ -22,6 +22,12 @@ I my self use for documentation and cooperation purpose with other developers
22
22
 
23
23
  gem 'rack-test-poc'
24
24
 
25
+ ### Use
26
+
27
+ All you need to do is to require 'rack/test/poc' in your test_helper
28
+ when you working with rack-test module,
29
+ and you good to go!
30
+
25
31
  ### example
26
32
 
27
33
  ```ruby
@@ -57,4 +63,22 @@ describe 'AppTest' do
57
63
 
58
64
  end
59
65
 
60
- ```
66
+ ```
67
+
68
+ this will generate a yaml file with the current unix timestamp in the following format:
69
+
70
+ ```yaml
71
+
72
+ ---
73
+ "/": #> endpoint
74
+ GET: #> endpoint method
75
+ response:
76
+ body: #> parsed response.body
77
+ msg: Hello Rack!
78
+ status: 200
79
+ format: json #> format of the response
80
+ request:
81
+ query: '' #> query string that been used
82
+
83
+
84
+ ```
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.0.1
@@ -12,7 +12,7 @@ module RackTestPoc
12
12
 
13
13
  def self.dump_obj
14
14
  @dump_obj ||= Hash.new
15
- end
15
+ end;self.dump_obj #> eager load for multiThread
16
16
 
17
17
  module EXT
18
18
 
@@ -72,11 +72,39 @@ module RackTestPoc
72
72
  RackTestPoc.dump_obj[uri][env['REQUEST_METHOD']]['response'] ||= {}
73
73
  RackTestPoc.dump_obj[uri][env['REQUEST_METHOD']]['request'] ||= {}
74
74
 
75
- RackTestPoc.dump_obj[uri][env['REQUEST_METHOD']]['request']['query'] = env['QUERY_STRING']
75
+ raw_query = env.find{|k,v|
76
+ %W[ QUERY_STRING rack.request.form_vars ].any?{|tag| k == tag && !v.nil? && v != '' }
77
+ }[1] rescue nil
78
+
79
+ query_hash = if raw_query
80
+ require 'cgi'
81
+ CGI.parse(raw_query).reduce({}){
82
+ |m,o| m.merge!(o[0]=> (o[1].length == 1 ? o[1][0] : o[1] ) )
83
+ }
84
+
85
+ else
86
+ {}
87
+
88
+ end
89
+
90
+ RackTestPoc.dump_obj[uri][env['REQUEST_METHOD']]['request']['query'] ||= {}
91
+ RackTestPoc.dump_obj[uri][env['REQUEST_METHOD']]['request']['query']['raw'] = raw_query
92
+ RackTestPoc.dump_obj[uri][env['REQUEST_METHOD']]['request']['query']['object'] = query_hash
93
+ RackTestPoc.dump_obj[uri][env['REQUEST_METHOD']]['request']['headers']= env.reduce({}){
94
+ |m,o| m.merge!(o[0]=>o[1]) if o[0].to_s.downcase =~ /^http_/ ; m
95
+ }
96
+
76
97
  RackTestPoc.dump_obj[uri][env['REQUEST_METHOD']]['response']['body'] = body
77
98
  RackTestPoc.dump_obj[uri][env['REQUEST_METHOD']]['response']['status']= last_response.status
78
99
  RackTestPoc.dump_obj[uri][env['REQUEST_METHOD']]['response']['format']= format
79
100
 
101
+ if env['CONTENT_TYPE']
102
+ RackTestPoc.dump_obj[uri][env['REQUEST_METHOD']]['response']['content_type']= env['CONTENT_TYPE']
103
+
104
+ end
105
+
106
+
107
+
80
108
  return last_response
81
109
 
82
110
  end
@@ -85,4 +113,4 @@ module RackTestPoc
85
113
  end
86
114
 
87
115
  require 'rack/test'
88
- Rack::Test::Session.prepend RackTestPoc::EXT
116
+ Rack::Test::Session.prepend RackTestPoc::EXT
@@ -20,7 +20,8 @@ describe 'AppTest' do
20
20
 
21
21
  specify 'some rack test!' do
22
22
 
23
- get '/' #> at this point poc data generated for '/'
23
+ header('Accept-Version','v1')
24
+ get '/',one_param: 'data' #> at this point poc data generated for '/'
24
25
 
25
26
  #> bla bla bla some code here
26
27
 
@@ -1,11 +1,13 @@
1
1
  require 'yaml'
2
2
  require 'timeout'
3
3
  require 'minitest/autorun'
4
+ require_relative '../lib/rack/test/poc'
5
+
4
6
  describe 'POCTest' do
5
7
 
6
8
  specify 'it should be made able to made a poc at exiting from the process' do
7
9
 
8
- `bundle exec ruby #{File.join __dir__,'dummy.rb'}`
10
+ $stdout.puts `bundle exec ruby #{File.join __dir__,'dummy.rb'}`
9
11
 
10
12
  begin
11
13
 
@@ -17,29 +19,31 @@ describe 'POCTest' do
17
19
  rescue;nil
18
20
  end.must_be_instance_of TrueClass
19
21
 
20
- Dir.glob( File.join __dir__,'poc','*.{yml,yaml}' ).each do |path|
21
- poc_object = YAML.load File.read(path)
22
+ path = Dir.glob( File.join __dir__,'poc','*.{yml,yaml}' ).sort{
23
+ |a,b| a.split(File::Separator)[-1].split('.')[0] <=> b.split(File::Separator)[-1].split('.')[0]
24
+ }[-1]
22
25
 
23
- poc_object.must_be_instance_of Hash
24
- poc_object.each_pair do |endpoint,options|
26
+ poc_object = YAML.load File.read(path)
27
+ poc_object.must_be_instance_of Hash
28
+ poc_object.each_pair do |endpoint,options|
25
29
 
26
- endpoint.must_be_instance_of String
27
- endpoint[0].must_be :==, '/'
30
+ endpoint.must_be_instance_of String
31
+ endpoint[0].must_be :==, '/'
28
32
 
29
- options.must_be_instance_of Hash
30
- options.keys.first.must_be_instance_of String
31
- options.values.each do |rest_options|
32
- rest_options.must_be_instance_of Hash
33
- rest_options['response'].must_be_instance_of Hash
34
- rest_options['response']['body'].wont_be :==, nil
35
- rest_options['response']['status'].class.must_be :<=,Numeric
36
- rest_options['response']['format'].must_be_instance_of String
37
- rest_options['request']['query'].must_be_instance_of String
33
+ options.must_be_instance_of Hash
34
+ options.keys.first.must_be_instance_of String
35
+ options.values.each do |rest_options|
36
+ rest_options.must_be_instance_of Hash
37
+ rest_options['response'].must_be_instance_of Hash
38
+ rest_options['response']['body'].wont_be :==, nil
39
+ rest_options['response']['status'].class.must_be :<=,Numeric
40
+ rest_options['response']['format'].must_be_instance_of String
41
+ rest_options['request']['query']['raw'].must_be_instance_of String
42
+ rest_options['request']['query']['object'].must_be_instance_of Hash
38
43
 
39
- end
44
+ end
40
45
 
41
46
 
42
- end
43
47
 
44
48
  end
45
49
 
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.0.0
4
+ version: 1.0.1
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-10-16 00:00:00.000000000 Z
11
+ date: 2014-10-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler