reqres 0.0.2
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.
- data/.gitignore +19 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/lib/reqres.rb +24 -0
- data/lib/reqres/generator.rb +11 -0
- data/lib/reqres/railtie.rb +12 -0
- data/lib/reqres/test_suit_additions.rb +64 -0
- data/lib/reqres/version.rb +3 -0
- data/lib/tasks/reqres.rake +14 -0
- data/reqres.gemspec +25 -0
- metadata +91 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Anton Versal
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Reqres
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'reqres'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install reqres
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/reqres.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require "active_support/core_ext/module/attribute_accessors"
|
2
|
+
require "reqres/version"
|
3
|
+
require "reqres/railtie" if defined?(Rails)
|
4
|
+
|
5
|
+
module Reqres
|
6
|
+
# the name of the file for store generated data
|
7
|
+
mattr_accessor :file_name
|
8
|
+
@@file_name = "./reqres.yml"
|
9
|
+
|
10
|
+
# rake files pattern to run for generating yml file
|
11
|
+
mattr_accessor :test_files_pattern
|
12
|
+
@@test_files_pattern = 'test/integration/**/*_test.rb'
|
13
|
+
|
14
|
+
# Way to setup Reqres. Add file to initializers:
|
15
|
+
# initializers/reqres.rb
|
16
|
+
#
|
17
|
+
# Reqres.setup do |config|
|
18
|
+
# config.file_name = File.join(Rails.root, "doc", "reqres.yml")
|
19
|
+
# config.test_files_pattern = "test/acceptance/**/*_test.rb"
|
20
|
+
# end
|
21
|
+
def self.setup
|
22
|
+
yield self
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "test_suit_additions")
|
2
|
+
|
3
|
+
module Reqres
|
4
|
+
module Generator
|
5
|
+
def self.included(base)
|
6
|
+
if Rake.application.top_level_tasks.grep(/^(reqres:yaml$)/).any?
|
7
|
+
base.send(:include, TestSuitAdditions)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
if defined?(Rake.application) && Rake.application.top_level_tasks.grep(/^(reqres(:|$))/).any?
|
2
|
+
ENV['RAILS_ENV'] ||= 'test'
|
3
|
+
Rails.env = ENV['RAILS_ENV'] # don't know why but set ENV['RAILS_ENV'] is not enough
|
4
|
+
end
|
5
|
+
|
6
|
+
module Rails
|
7
|
+
class ReqresRailtie < Rails::Railtie
|
8
|
+
rake_tasks do
|
9
|
+
load "tasks/reqres.rake"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'active_support/concern'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
module Reqres
|
5
|
+
module TestSuitAdditions
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
@@all_tests = {}
|
8
|
+
|
9
|
+
module ClassMethods
|
10
|
+
|
11
|
+
# saves yml file to the path
|
12
|
+
def save_to_file
|
13
|
+
File.open(Reqres.file_name, "w") do |file|
|
14
|
+
file.write all_tests.to_yaml
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# returns hash for each test
|
20
|
+
def data_of_test
|
21
|
+
{__name__ =>
|
22
|
+
{
|
23
|
+
"request" => {
|
24
|
+
"url" => request.url,
|
25
|
+
"full_path" => request.fullpath,
|
26
|
+
"params" => request.params.to_hash,
|
27
|
+
"method" => request.method,
|
28
|
+
"body" => request.body.read,
|
29
|
+
"headers" =>
|
30
|
+
{
|
31
|
+
"http_authorization" => request.headers["HTTP_AUTHORIZATION"],
|
32
|
+
"content_type" => request.headers["CONTENT_TYPE"],
|
33
|
+
'accept' => request.headers["ACCEPT"]
|
34
|
+
}
|
35
|
+
},
|
36
|
+
"response" => {
|
37
|
+
"code" => response.code,
|
38
|
+
"body" => response.body
|
39
|
+
}
|
40
|
+
}
|
41
|
+
}
|
42
|
+
end
|
43
|
+
|
44
|
+
# collects data from all tests
|
45
|
+
def collect
|
46
|
+
if all_tests[self.class.name].nil?
|
47
|
+
all_tests[self.class.name] = data_of_test
|
48
|
+
else
|
49
|
+
all_tests[self.class.name].merge!(data_of_test)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
included do
|
54
|
+
cattr_reader :all_tests
|
55
|
+
teardown do
|
56
|
+
collect
|
57
|
+
end
|
58
|
+
|
59
|
+
MiniTest::Unit.after_tests do
|
60
|
+
save_to_file
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rake/testtask'
|
2
|
+
require 'rails/test_unit/sub_test_task'
|
3
|
+
|
4
|
+
namespace :reqres do
|
5
|
+
desc "Generating YAML file from integration tests"
|
6
|
+
task :yaml => "test:prepare" do
|
7
|
+
# This hack allows to use settings form Reqres module
|
8
|
+
Rails::TestTask.new("reqres:yaml2") do |t|
|
9
|
+
t.pattern = Reqres.test_files_pattern
|
10
|
+
end
|
11
|
+
Rake::Task['reqres:yaml2'].invoke
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
data/reqres.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'reqres/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "reqres"
|
8
|
+
spec.version = Reqres::VERSION
|
9
|
+
spec.authors = ["Anton Versal"]
|
10
|
+
spec.email = ["ant.ver@gmail.com"]
|
11
|
+
spec.description = %q{Request and Response YAML file generator from test.}
|
12
|
+
spec.summary = %q{Request and Response YAML file generator from test.
|
13
|
+
Can be used for creating fake API with sinatra.
|
14
|
+
And for generating API documentation.}
|
15
|
+
spec.homepage = "https://github.com/antonversal/reqres"
|
16
|
+
spec.license = "MIT"
|
17
|
+
|
18
|
+
spec.files = `git ls-files`.split($/)
|
19
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
20
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: reqres
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Anton Versal
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-10-17 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.3'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: Request and Response YAML file generator from test.
|
47
|
+
email:
|
48
|
+
- ant.ver@gmail.com
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- .gitignore
|
54
|
+
- Gemfile
|
55
|
+
- LICENSE.txt
|
56
|
+
- README.md
|
57
|
+
- Rakefile
|
58
|
+
- lib/reqres.rb
|
59
|
+
- lib/reqres/generator.rb
|
60
|
+
- lib/reqres/railtie.rb
|
61
|
+
- lib/reqres/test_suit_additions.rb
|
62
|
+
- lib/reqres/version.rb
|
63
|
+
- lib/tasks/reqres.rake
|
64
|
+
- reqres.gemspec
|
65
|
+
homepage: https://github.com/antonversal/reqres
|
66
|
+
licenses:
|
67
|
+
- MIT
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options: []
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
none: false
|
80
|
+
requirements:
|
81
|
+
- - ! '>='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
requirements: []
|
85
|
+
rubyforge_project:
|
86
|
+
rubygems_version: 1.8.25
|
87
|
+
signing_key:
|
88
|
+
specification_version: 3
|
89
|
+
summary: Request and Response YAML file generator from test. Can be used for creating
|
90
|
+
fake API with sinatra. And for generating API documentation.
|
91
|
+
test_files: []
|