reqres 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +66 -2
- data/lib/reqres.rb +4 -0
- data/lib/reqres/test_suit_additions.rb +16 -7
- data/lib/reqres/version.rb +1 -1
- metadata +9 -15
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: dcbfdc4c9b951d7709d53447a2fdcfe5c59addf7
|
4
|
+
data.tar.gz: 59eb430301b10eb9d2bea0375bfef2ac1c9a9259
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: dc4cd71a62c773116690aff242895d36b1d7552f94665e0a80100ed2cf56a58d98da5235831ea753866734215bf619769ccf036a5ca175c7e33ae5b8d06c6a84
|
7
|
+
data.tar.gz: fa8bbb3e7eb178c1d74d9ca997093612e11786fa3c81c8f09a4edaf9ba060b8297cf308c33ac82e4257f10248f206f21b01e1e1d6368243ed2c4732ecddca4b2
|
data/README.md
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
# Reqres
|
2
2
|
|
3
|
-
|
3
|
+
Simple application for generating Request and Response YAML file from test.
|
4
|
+
Can be used for creating fake API with sinatra.
|
5
|
+
And for generating API documentation.
|
6
|
+
|
7
|
+
__Only works on Rails and MiniTest::Unit for now__
|
4
8
|
|
5
9
|
## Installation
|
6
10
|
|
@@ -15,11 +19,71 @@ And then execute:
|
|
15
19
|
Or install it yourself as:
|
16
20
|
|
17
21
|
$ gem install reqres
|
22
|
+
|
23
|
+
Include `Reqres::Generator` module to `ActiveSupport::TestCase` in `test_helper.rb`:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
require 'reqres/generator'
|
27
|
+
|
28
|
+
class ActiveSupport::TestCase
|
29
|
+
include Reqres::Generator
|
30
|
+
...
|
31
|
+
```
|
18
32
|
|
19
33
|
## Usage
|
20
34
|
|
21
|
-
|
35
|
+
For generating file run:
|
36
|
+
|
37
|
+
rake reqres:yaml
|
38
|
+
|
39
|
+
By default for generating is used integration test but you can set a pattern
|
40
|
+
in initializers:
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
# initializers/reqres.rb
|
44
|
+
Reqres.setup do |config|
|
45
|
+
config.test_files_pattern = "test/acceptance/**/*_test.rb"
|
46
|
+
end
|
47
|
+
```
|
48
|
+
|
49
|
+
Generated file saves to current dir, you can set this in settings:
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
config.file_name = File.join(Rails.root, "doc", "reqres.yml")
|
53
|
+
```
|
54
|
+
|
55
|
+
You can change default request header extraction, which is
|
56
|
+
`%w{HTTP_AUTHORIZATION HTTP_ACCEPT CONTENT_TYPE}`:
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
config.request_headers = %w{HTTP_AUTHORIZATION CONTENT_TYPE}
|
60
|
+
```
|
22
61
|
|
62
|
+
Generated file will have structure:
|
63
|
+
```yaml
|
64
|
+
ManageFooTest:
|
65
|
+
test_creates_foo:
|
66
|
+
request:
|
67
|
+
url: http://www.example.com/v1/foos
|
68
|
+
full_path: /v1/foos
|
69
|
+
params:
|
70
|
+
name: Bar
|
71
|
+
description: FooBar
|
72
|
+
action: create
|
73
|
+
controller: v1/foos
|
74
|
+
method: POST
|
75
|
+
body: '{"name":"Bar","description":"FooBar"}'
|
76
|
+
headers:
|
77
|
+
http_authorization: Token token="14d75ec70594d026de22f02502e74be9"
|
78
|
+
content_type: application/json
|
79
|
+
accept: application/json
|
80
|
+
response:
|
81
|
+
code: '201'
|
82
|
+
body: '{"id":974435878,"name":"Bar","description":"FooBar"}'
|
83
|
+
test_getting_foo:
|
84
|
+
request:
|
85
|
+
....
|
86
|
+
```
|
23
87
|
## Contributing
|
24
88
|
|
25
89
|
1. Fork it
|
data/lib/reqres.rb
CHANGED
@@ -11,6 +11,10 @@ module Reqres
|
|
11
11
|
mattr_accessor :test_files_pattern
|
12
12
|
@@test_files_pattern = 'test/integration/**/*_test.rb'
|
13
13
|
|
14
|
+
# rake files pattern to run for generating yml file
|
15
|
+
mattr_accessor :request_headers
|
16
|
+
@@request_headers = %w{HTTP_AUTHORIZATION HTTP_ACCEPT CONTENT_TYPE}
|
17
|
+
|
14
18
|
# Way to setup Reqres. Add file to initializers:
|
15
19
|
# initializers/reqres.rb
|
16
20
|
#
|
@@ -26,21 +26,30 @@ module Reqres
|
|
26
26
|
"params" => request.params.to_hash,
|
27
27
|
"method" => request.method,
|
28
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
|
-
}
|
29
|
+
"headers" => request_headers
|
35
30
|
},
|
36
31
|
"response" => {
|
37
32
|
"code" => response.code,
|
38
|
-
"body" => response.body
|
33
|
+
"body" => response.body,
|
34
|
+
"headers" => response.headers
|
39
35
|
}
|
40
36
|
}
|
41
37
|
}
|
42
38
|
end
|
43
39
|
|
40
|
+
# request.headers is ActionDispatch::Http::Headers.
|
41
|
+
# It can't be serialized right to yaml
|
42
|
+
def request_headers
|
43
|
+
hdrs = Reqres.request_headers
|
44
|
+
request.headers.inject({}) do |memo,(k,v)|
|
45
|
+
if hdrs.include? k
|
46
|
+
memo.merge(k => v)
|
47
|
+
else
|
48
|
+
memo
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
44
53
|
# collects data from all tests
|
45
54
|
def collect
|
46
55
|
if all_tests[self.class.name].nil?
|
data/lib/reqres/version.rb
CHANGED
metadata
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: reqres
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.3
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Anton Versal
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-10-
|
11
|
+
date: 2013-10-25 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: bundler
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
17
|
- - ~>
|
20
18
|
- !ruby/object:Gem::Version
|
@@ -22,7 +20,6 @@ dependencies:
|
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
24
|
- - ~>
|
28
25
|
- !ruby/object:Gem::Version
|
@@ -30,17 +27,15 @@ dependencies:
|
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rake
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - '>='
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - '>='
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
description: Request and Response YAML file generator from test.
|
@@ -65,27 +60,26 @@ files:
|
|
65
60
|
homepage: https://github.com/antonversal/reqres
|
66
61
|
licenses:
|
67
62
|
- MIT
|
63
|
+
metadata: {}
|
68
64
|
post_install_message:
|
69
65
|
rdoc_options: []
|
70
66
|
require_paths:
|
71
67
|
- lib
|
72
68
|
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
69
|
requirements:
|
75
|
-
- -
|
70
|
+
- - '>='
|
76
71
|
- !ruby/object:Gem::Version
|
77
72
|
version: '0'
|
78
73
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
-
none: false
|
80
74
|
requirements:
|
81
|
-
- -
|
75
|
+
- - '>='
|
82
76
|
- !ruby/object:Gem::Version
|
83
77
|
version: '0'
|
84
78
|
requirements: []
|
85
79
|
rubyforge_project:
|
86
|
-
rubygems_version: 1.
|
80
|
+
rubygems_version: 2.1.9
|
87
81
|
signing_key:
|
88
|
-
specification_version:
|
82
|
+
specification_version: 4
|
89
83
|
summary: Request and Response YAML file generator from test. Can be used for creating
|
90
84
|
fake API with sinatra. And for generating API documentation.
|
91
85
|
test_files: []
|