rspec_api_blueprint 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +8 -8
- data/lib/rspec_api_blueprint/version.rb +1 -1
- data/lib/rspec_api_blueprint.rb +17 -2
- metadata +1 -7
data/README.md
CHANGED
@@ -23,14 +23,14 @@ Or install it yourself as:
|
|
23
23
|
In your spec_helper.rb file add
|
24
24
|
|
25
25
|
require 'rspec_api_blueprint'
|
26
|
-
|
26
|
+
|
27
27
|
Write tests using the following convention:
|
28
28
|
|
29
29
|
- Top level descriptions are named after the model (plural form) followed by the word “Requests”. For a example model called Arena it would be “Arenas Requests”.
|
30
30
|
- Second level descriptions are actions in the form of “VERB path”. For the show action of the Arenas controller it would be “GET /arenas/{id}”.
|
31
31
|
|
32
32
|
Example:
|
33
|
-
|
33
|
+
|
34
34
|
describe 'Arenas Requests' do
|
35
35
|
describe 'GET /v1/arenas/{id}' do
|
36
36
|
it 'responds with the requested arena' do
|
@@ -41,12 +41,12 @@ Example:
|
|
41
41
|
end
|
42
42
|
end
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
The output:
|
46
46
|
|
47
|
-
# GET /v1/arenas/{id}
|
47
|
+
# GET /v1/arenas/{id}
|
48
48
|
|
49
|
-
+ Response 200 (application/json)
|
49
|
+
+ Response 200 (application/json)
|
50
50
|
|
51
51
|
{
|
52
52
|
"arena": {
|
@@ -57,14 +57,14 @@ The output:
|
|
57
57
|
"foursquare_id": "5104"
|
58
58
|
}
|
59
59
|
}
|
60
|
-
|
61
|
-
|
60
|
+
|
61
|
+
|
62
62
|
## Caveats
|
63
63
|
|
64
64
|
401, 403 and 301 statuses are ignored since rspec produces a undesired output.
|
65
65
|
|
66
66
|
TODO: Add option to choose ignored statuses.
|
67
|
-
|
67
|
+
|
68
68
|
## Contributing
|
69
69
|
|
70
70
|
1. Fork it
|
data/lib/rspec_api_blueprint.rb
CHANGED
@@ -1,5 +1,20 @@
|
|
1
1
|
require "rspec_api_blueprint/version"
|
2
2
|
|
3
|
+
unless "".respond_to?(:indent)
|
4
|
+
class String
|
5
|
+
def indent(count, char = ' ')
|
6
|
+
gsub(/([^\n]*)(\n|$)/) do |match|
|
7
|
+
last_iteration = ($1 == "" && $2 == "")
|
8
|
+
line = ""
|
9
|
+
line << (char * count) unless last_iteration
|
10
|
+
line << $1
|
11
|
+
line << $2
|
12
|
+
line
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
3
18
|
RSpec.configure do |config|
|
4
19
|
config.before(:all, type: :request) do
|
5
20
|
api_docs_folder_path = File.join(Rails.root, '/api_docs/')
|
@@ -42,7 +57,7 @@ RSpec.configure do |config|
|
|
42
57
|
end
|
43
58
|
|
44
59
|
# Request Body
|
45
|
-
if request_body.present?
|
60
|
+
if request_body.present? && request.content_type == 'application/json'
|
46
61
|
f.write "+ Body\n\n".indent(4) if authorization_header
|
47
62
|
f.write "#{JSON.pretty_generate(JSON.parse(request_body))}\n\n".indent(authorization_header ? 12 : 8)
|
48
63
|
end
|
@@ -51,7 +66,7 @@ RSpec.configure do |config|
|
|
51
66
|
# Response
|
52
67
|
f.write "+ Response #{response.status} #{response.content_type}\n\n"
|
53
68
|
|
54
|
-
if response.body.present?
|
69
|
+
if response.body.present? && request.content_type == 'application/json'
|
55
70
|
f.write "#{JSON.pretty_generate(JSON.parse(response.body))}\n\n".indent(8)
|
56
71
|
end
|
57
72
|
end unless response.status == 401 || response.status == 403 || response.status == 301
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec_api_blueprint
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -87,18 +87,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
87
87
|
- - ! '>='
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '0'
|
90
|
-
segments:
|
91
|
-
- 0
|
92
|
-
hash: 1602726730343922702
|
93
90
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
91
|
none: false
|
95
92
|
requirements:
|
96
93
|
- - ! '>='
|
97
94
|
- !ruby/object:Gem::Version
|
98
95
|
version: '0'
|
99
|
-
segments:
|
100
|
-
- 0
|
101
|
-
hash: 1602726730343922702
|
102
96
|
requirements: []
|
103
97
|
rubyforge_project:
|
104
98
|
rubygems_version: 1.8.24
|