rack-test-poc 1.0.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2716489bf4f677edc15b8b5ee70d7e3caaa1902d
4
+ data.tar.gz: e0cbceda132bf55f2823eb45cd89283793cd0b22
5
+ SHA512:
6
+ metadata.gz: 000f19b2fa399594743a247ad8531d482239b35660b42d72169fa9eb707d5f791d34edfd07872a814839de109ba9608d4e8b288ffbcf3de9293ad5de6abfbeac
7
+ data.tar.gz: 97731ce78b49c8ff22f205071283465c59616a75f9b23db8bf854c66f98a88207e0b46532c9eb5e886d0a91f5d9c8f2311ddfb012592432011d59f85bd6e4653
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ test/poc/
2
+ pkg/
3
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source :rubygems
2
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,8 @@
1
+ Copyright (c) 2014 Adam Luzsi
2
+
3
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
4
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
5
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
6
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
7
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
8
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
data/README.md ADDED
@@ -0,0 +1,60 @@
1
+ Rack Test POC
2
+ =============
3
+
4
+ ### Description
5
+
6
+ rack/test based poc file generator, this will make you able to export
7
+ any data that traveled through the test, and be able to create poc
8
+ file with that. It is even useful for creating integration test that
9
+ is based on your api endpoints, because the export file will be
10
+ serialized into a yaml file that contain all the endpoints that
11
+ you just tested, and it's inputs and outputs
12
+
13
+ I my self use for documentation and cooperation purpose with other developers
14
+
15
+ ### Install
16
+
17
+ #### RubyGems/gem command
18
+
19
+ $ gem install rack-test-poc
20
+
21
+ #### Bundler/Gemfile
22
+
23
+ gem 'rack-test-poc'
24
+
25
+ ### example
26
+
27
+ ```ruby
28
+
29
+ require 'rack'
30
+
31
+ class APP
32
+ def self.call(env)
33
+ [200, {"Content-Type" => "application/json"}, '{"msg":"Hello Rack!"}']
34
+ end
35
+ end
36
+
37
+ require 'rack/test/poc'
38
+ require 'minitest/autorun'
39
+
40
+ describe 'AppTest' do
41
+
42
+ include Rack::Test::Methods
43
+
44
+ def app
45
+ APP
46
+ end
47
+
48
+ specify 'some rack test!' do
49
+
50
+ get '/' #> at this point poc data generated for '/'
51
+
52
+ #> bla bla bla some code here
53
+ last_response.body #> '{"msg":"Hello Rack!"}'
54
+
55
+ end
56
+
57
+
58
+ end
59
+
60
+ ```
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require File.join 'bundler','gem_tasks'
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.0
@@ -0,0 +1 @@
1
+ require 'rack/test/poc'
@@ -0,0 +1,88 @@
1
+ module RackTestPoc
2
+
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
10
+ end
11
+ end
12
+
13
+ def self.dump_obj
14
+ @dump_obj ||= Hash.new
15
+ end
16
+
17
+ module EXT
18
+
19
+ def __init_dump_poc__
20
+ $rack_test_poc_dump_export ||= -> {
21
+ Kernel.at_exit do
22
+
23
+ require 'yaml'
24
+ require 'fileutils'
25
+
26
+ dump_dir = File.join RackTestPoc.root,'test','poc'
27
+ FileUtils.mkdir_p(dump_dir) unless File.exist?(dump_dir)
28
+
29
+ unless RackTestPoc.dump_obj.empty?
30
+ File.write File.join(dump_dir,Time.now.to_i.to_s.concat('.yaml')),
31
+ RackTestPoc.dump_obj.to_yaml
32
+
33
+ end
34
+
35
+ end;true
36
+ }.call
37
+ end
38
+
39
+ def process_request(uri, env, *args)
40
+
41
+ __init_dump_poc__
42
+
43
+ super
44
+
45
+ RackTestPoc.dump_obj[uri] ||= {}
46
+ RackTestPoc.dump_obj[uri][env['REQUEST_METHOD']] ||= {}
47
+
48
+ begin
49
+
50
+ format = env['PATH_INFO'].split('.')[-1]
51
+ case format
52
+
53
+ when 'json'
54
+ require 'json'
55
+ body = JSON.parse last_response.body
56
+
57
+ # when 'xml'
58
+
59
+ else
60
+ require 'json'
61
+ body = JSON.parse last_response.body
62
+ format = 'json'
63
+
64
+ end
65
+
66
+ rescue
67
+ format = 'text/html'
68
+ body = last_response.body
69
+
70
+ end
71
+
72
+ RackTestPoc.dump_obj[uri][env['REQUEST_METHOD']]['response'] ||= {}
73
+ RackTestPoc.dump_obj[uri][env['REQUEST_METHOD']]['request'] ||= {}
74
+
75
+ RackTestPoc.dump_obj[uri][env['REQUEST_METHOD']]['request']['query'] = env['QUERY_STRING']
76
+ RackTestPoc.dump_obj[uri][env['REQUEST_METHOD']]['response']['body'] = body
77
+ RackTestPoc.dump_obj[uri][env['REQUEST_METHOD']]['response']['status']= last_response.status
78
+ RackTestPoc.dump_obj[uri][env['REQUEST_METHOD']]['response']['format']= format
79
+
80
+ return last_response
81
+
82
+ end
83
+ end
84
+
85
+ end
86
+
87
+ require 'rack/test'
88
+ Rack::Test::Session.prepend RackTestPoc::EXT
@@ -0,0 +1,39 @@
1
+ # coding: utf-8
2
+
3
+ Gem::Specification.new do |spec|
4
+
5
+ spec.name = 'rack-test-poc'
6
+ spec.version = File.read(File.join(File.dirname(__FILE__),'VERSION')).split("\n")[0].chomp.gsub(' ','')
7
+ spec.authors = ['Adam Luzsi']
8
+ spec.email = ['adamluzsi@gmail.com']
9
+
10
+ spec.description = [
11
+ 'rack/test based poc file generator,',
12
+ 'this will make you able to export any',
13
+ 'data that traveled through the test,',
14
+ 'and be able to create poc file with that.',
15
+ 'It is even useful for creating integration',
16
+ 'test that is based on your api endpoints,',
17
+ 'because the export file will be serialized',
18
+ 'into a yaml file that contain all the',
19
+ 'endpoints that you just tested, and',
20
+ 'it\'s inputs and outputs'
21
+
22
+ ].join(' ')
23
+
24
+ spec.summary = 'rack/test based poc file generator'
25
+
26
+ spec.homepage = "https://github.com/adamluzsi/#{__FILE__.split(File::Separator).last.split('.').first}"
27
+ spec.files = `git ls-files`.split($/)
28
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
29
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
30
+
31
+ spec.require_paths = ['lib']
32
+ spec.required_ruby_version = '>= 2.0.0'
33
+
34
+ spec.add_development_dependency 'bundler'
35
+ spec.add_development_dependency 'rake'
36
+
37
+ spec.add_dependency 'rack-test'
38
+
39
+ end
data/test/dummy.rb ADDED
@@ -0,0 +1,32 @@
1
+
2
+ require 'rack'
3
+
4
+ class APP
5
+ def self.call(env)
6
+ [200, {"Content-Type" => "application/json"}, '{"msg":"Hello Rack!"}']
7
+ end
8
+ end
9
+
10
+ require 'rack/test/poc'
11
+ require 'minitest/autorun'
12
+
13
+ describe 'AppTest' do
14
+
15
+ include Rack::Test::Methods
16
+
17
+ def app
18
+ APP
19
+ end
20
+
21
+ specify 'some rack test!' do
22
+
23
+ get '/' #> at this point poc data generated for '/'
24
+
25
+ #> bla bla bla some code here
26
+
27
+ last_response.body #> '{"msg":"Hello Rack!"}'
28
+
29
+ end
30
+
31
+
32
+ end
@@ -0,0 +1,48 @@
1
+ require 'yaml'
2
+ require 'timeout'
3
+ require 'minitest/autorun'
4
+ describe 'POCTest' do
5
+
6
+ specify 'it should be made able to made a poc at exiting from the process' do
7
+
8
+ `bundle exec ruby #{File.join __dir__,'dummy.rb'}`
9
+
10
+ begin
11
+
12
+ Timeout.timeout 5 do
13
+ sleep(0.1) until File.exist?(File.join __dir__,'poc')
14
+ end
15
+
16
+ true
17
+ rescue;nil
18
+ end.must_be_instance_of TrueClass
19
+
20
+ Dir.glob( File.join __dir__,'poc','*.{yml,yaml}' ).each do |path|
21
+ poc_object = YAML.load File.read(path)
22
+
23
+ poc_object.must_be_instance_of Hash
24
+ poc_object.each_pair do |endpoint,options|
25
+
26
+ endpoint.must_be_instance_of String
27
+ endpoint[0].must_be :==, '/'
28
+
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
38
+
39
+ end
40
+
41
+
42
+ end
43
+
44
+ end
45
+
46
+ end
47
+
48
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-test-poc
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Adam Luzsi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rack-test
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: rack/test based poc file generator, this will make you able to export
56
+ any data that traveled through the test, and be able to create poc file with that.
57
+ It is even useful for creating integration test that is based on your api endpoints,
58
+ because the export file will be serialized into a yaml file that contain all the
59
+ endpoints that you just tested, and it's inputs and outputs
60
+ email:
61
+ - adamluzsi@gmail.com
62
+ executables: []
63
+ extensions: []
64
+ extra_rdoc_files: []
65
+ files:
66
+ - ".gitignore"
67
+ - Gemfile
68
+ - LICENSE
69
+ - README.md
70
+ - Rakefile
71
+ - VERSION
72
+ - lib/rack-test-poc.rb
73
+ - lib/rack/test/poc.rb
74
+ - rack-test-poc.gemspec
75
+ - test/dummy.rb
76
+ - test/test_poc_generation.rb
77
+ homepage: https://github.com/adamluzsi/rack-test-poc
78
+ licenses: []
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: 2.0.0
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.2.2
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: rack/test based poc file generator
100
+ test_files:
101
+ - test/dummy.rb
102
+ - test/test_poc_generation.rb
103
+ has_rdoc: