reqres_rspec 0.0.25 → 0.0.26
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 +4 -4
- data/lib/reqres_rspec/collector.rb +8 -3
- data/lib/reqres_rspec/generators/pdf.rb +3 -3
- data/lib/reqres_rspec/version.rb +1 -1
- data/lib/reqres_rspec/writers/html.rb +8 -8
- data/lib/reqres_rspec/writers/templates/header.erb +2 -2
- data/lib/reqres_rspec/writers/templates/index.erb +1 -1
- data/lib/reqres_rspec/writers/templates/panel.erb +2 -2
- data/lib/reqres_rspec/writers/templates/spec.erb +7 -7
- data/lib/reqres_rspec.rb +20 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c6ca4e4259bb1d65278581ef0bd30fd584c5f30
|
4
|
+
data.tar.gz: 1fe08d50de503b97bdd9a7307f95f53ba6f9f69e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b0b91d0c7fcc0f6bf080e8447a490e19699c829a6d1f304dbccf21da96a6a33c217dabaf180c51df90775bcb6acc20aeb98cf07f5932e15e497294d2b73135d7
|
7
|
+
data.tar.gz: 07017e0e97178ad186755dded165667437783c2f8955f911b5f739746b0ef246b974358822d0c841973491eebd66e15bef368dc81d78161a811d3f6debbdc59d
|
@@ -31,6 +31,8 @@ module ReqresRspec
|
|
31
31
|
# everything that match items from this list will be stripped
|
32
32
|
EXCLUDE_REQUEST_HEADER_PATTERNS = %w[
|
33
33
|
rack.
|
34
|
+
sinatra.commonlogger
|
35
|
+
sinatra.route
|
34
36
|
ROUTES_
|
35
37
|
action_dispatch
|
36
38
|
action_controller.
|
@@ -96,7 +98,7 @@ module ReqresRspec
|
|
96
98
|
content_length: request.content_length,
|
97
99
|
content_type: request.content_type,
|
98
100
|
headers: read_request_headers(request),
|
99
|
-
accept: request.accept
|
101
|
+
accept: (request.accept rescue nil)
|
100
102
|
},
|
101
103
|
response: {
|
102
104
|
code: response.status,
|
@@ -142,8 +144,11 @@ module ReqresRspec
|
|
142
144
|
#
|
143
145
|
def get_symbolized_path(request)
|
144
146
|
request_path = request.path
|
147
|
+
request_params = request.env['action_dispatch.request.parameters'] ||
|
148
|
+
request.env['rack.request.form_hash'] ||
|
149
|
+
request.env['rack.request.query_hash']
|
145
150
|
|
146
|
-
|
151
|
+
request_params.
|
147
152
|
reject { |param| %w[controller action].include? param }.
|
148
153
|
each do |key, value|
|
149
154
|
if value.is_a? String
|
@@ -160,7 +165,7 @@ module ReqresRspec
|
|
160
165
|
# returns action comments taken from controller file
|
161
166
|
# example TODO
|
162
167
|
def get_action_comments(controller, action)
|
163
|
-
lines = File.readlines(File.join(
|
168
|
+
lines = File.readlines(File.join(ENV['REQRES_RSPEC_ROOT'], 'app', 'controllers', "#{controller}_controller.rb"))
|
164
169
|
|
165
170
|
action_line = nil
|
166
171
|
lines.each_with_index do |line, index|
|
@@ -6,8 +6,8 @@ module ReqresRspec
|
|
6
6
|
def generate
|
7
7
|
# http://www.princexml.com/download/
|
8
8
|
pdf_tool_path = 'prince'
|
9
|
-
html_docs_root = File.join(
|
10
|
-
pdf_doc_path = File.join(
|
9
|
+
html_docs_root = File.join(ENV['REQRES_RSPEC_ROOT'], 'doc')
|
10
|
+
pdf_doc_path = File.join(ENV['REQRES_RSPEC_ROOT'], 'doc', "rspec_doc_#{Time.now.strftime("%d-%h-%Y_%H-%M")}.pdf")
|
11
11
|
|
12
12
|
if `which #{pdf_tool_path}`.size > 0
|
13
13
|
files = Dir["#{html_docs_root}/rspec_doc_*.html"]
|
@@ -26,4 +26,4 @@ module ReqresRspec
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
29
|
-
end
|
29
|
+
end
|
data/lib/reqres_rspec/version.rb
CHANGED
@@ -21,7 +21,7 @@ module ReqresRspec
|
|
21
21
|
|
22
22
|
# recreates /doc dir if it does not exist
|
23
23
|
def recreate_doc_dir
|
24
|
-
doc_dir = File.join(
|
24
|
+
doc_dir = File.join(ENV['REQRES_RSPEC_ROOT'], 'doc')
|
25
25
|
unless Dir.exist?(doc_dir)
|
26
26
|
Dir.mkdir(doc_dir)
|
27
27
|
puts "#{doc_dir} was recreated"
|
@@ -31,9 +31,9 @@ module ReqresRspec
|
|
31
31
|
# deletes previous version of HTML docs
|
32
32
|
# TODO: more info
|
33
33
|
def cleanup
|
34
|
-
FileUtils.rm_rf(Dir.glob("#{
|
35
|
-
FileUtils.rm_rf(Dir.glob("#{
|
36
|
-
FileUtils.rm_rf(Dir.glob("#{
|
34
|
+
FileUtils.rm_rf(Dir.glob("#{ENV['REQRES_RSPEC_ROOT']}/doc/rspec_doc_*.html"), secure: true)
|
35
|
+
FileUtils.rm_rf(Dir.glob("#{ENV['REQRES_RSPEC_ROOT']}/doc/index.html"), secure: true)
|
36
|
+
FileUtils.rm_rf(Dir.glob("#{ENV['REQRES_RSPEC_ROOT']}/doc/panel.html"), secure: true)
|
37
37
|
end
|
38
38
|
|
39
39
|
# generates contents of HTML docs
|
@@ -42,7 +42,7 @@ module ReqresRspec
|
|
42
42
|
tpl_path = File.join(File.dirname(__FILE__), 'templates', 'header.erb')
|
43
43
|
rendered_doc = ERB.new(File.open(tpl_path).read).result(binding)
|
44
44
|
|
45
|
-
path = File.join(
|
45
|
+
path = File.join(ENV['REQRES_RSPEC_ROOT'], 'doc', 'rspec_doc_00000.html')
|
46
46
|
file = File.open(path, 'w')
|
47
47
|
file.write(rendered_doc)
|
48
48
|
file.close
|
@@ -60,7 +60,7 @@ module ReqresRspec
|
|
60
60
|
|
61
61
|
rendered_doc = ERB.new(File.open(tpl_path).read).result(binding)
|
62
62
|
|
63
|
-
path = File.join(
|
63
|
+
path = File.join(ENV['REQRES_RSPEC_ROOT'], 'doc', "rspec_doc_#{@index.to_s.rjust(5, '0') }.html")
|
64
64
|
file = File.open(path, 'w')
|
65
65
|
file.write(rendered_doc)
|
66
66
|
file.close
|
@@ -70,7 +70,7 @@ module ReqresRspec
|
|
70
70
|
|
71
71
|
# creates an index file with iframes if does not exists
|
72
72
|
def append_index
|
73
|
-
index_file = File.join(
|
73
|
+
index_file = File.join(ENV['REQRES_RSPEC_ROOT'], 'doc', 'index.html')
|
74
74
|
unless File.exists?(index_file)
|
75
75
|
tpl_path = File.join(File.dirname(__FILE__), 'templates', 'index.erb')
|
76
76
|
rendered_doc = ERB.new(File.open(tpl_path).read).result(binding)
|
@@ -79,7 +79,7 @@ module ReqresRspec
|
|
79
79
|
end
|
80
80
|
|
81
81
|
def append_panel
|
82
|
-
index_file = File.join(
|
82
|
+
index_file = File.join(ENV['REQRES_RSPEC_ROOT'], 'doc', 'panel.html')
|
83
83
|
unless File.exists?(index_file)
|
84
84
|
tpl_path = File.join(File.dirname(__FILE__), 'templates', 'panel.erb')
|
85
85
|
rendered_doc = ERB.new(File.open(tpl_path).read).result(binding)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
<html>
|
2
2
|
<head>
|
3
|
-
<title><%=
|
3
|
+
<title><%= ENV['REQRES_RSPEC_APP'] %> API Documentation</title>
|
4
4
|
<link href='http://fonts.googleapis.com/css?family=Droid+Sans:400,700' rel='stylesheet' type='text/css'>
|
5
5
|
<link href='http://fonts.googleapis.com/css?family=Droid+Sans+Mono' rel='stylesheet' type='text/css'>
|
6
6
|
<style>
|
@@ -58,7 +58,7 @@
|
|
58
58
|
</head>
|
59
59
|
<body>
|
60
60
|
<div class="container">
|
61
|
-
<h1><%=
|
61
|
+
<h1><%= ENV['REQRES_RSPEC_APP'] %> API Documentation</h1>
|
62
62
|
<p>Generated <%= Time.now.strftime('%d %B %Y at %H:%m:%S')%> with <a href="https://github.com/reqres-api/reqres_rspec">reqres_rspec</a></p>
|
63
63
|
<ul>
|
64
64
|
<% @records.each_with_index do |record, index| %>
|
@@ -1,7 +1,7 @@
|
|
1
1
|
<!DOCTYPE html>
|
2
2
|
<html>
|
3
3
|
<head>
|
4
|
-
<title><%=
|
4
|
+
<title><%= ENV['REQRES_RSPEC_APP'] %> API Documentation</title>
|
5
5
|
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />
|
6
6
|
<link href='http://fonts.googleapis.com/css?family=Droid+Sans:400,700' rel='stylesheet' type='text/css'>
|
7
7
|
<link href='http://fonts.googleapis.com/css?family=Droid+Sans+Mono' rel='stylesheet' type='text/css'>
|
@@ -1,7 +1,7 @@
|
|
1
1
|
<!DOCTYPE html>
|
2
2
|
<html>
|
3
3
|
<head>
|
4
|
-
<title><%=
|
4
|
+
<title><%= ENV['REQRES_RSPEC_APP'] %> API Documentation</title>
|
5
5
|
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />
|
6
6
|
<link href='http://fonts.googleapis.com/css?family=Droid+Sans:400,700' rel='stylesheet' type='text/css'>
|
7
7
|
<link href='http://fonts.googleapis.com/css?family=Droid+Sans+Mono' rel='stylesheet' type='text/css'>
|
@@ -86,7 +86,7 @@
|
|
86
86
|
</head>
|
87
87
|
<body>
|
88
88
|
<h1><a href="rspec_doc_00000.html" target="specs">
|
89
|
-
<%=
|
89
|
+
<%= ENV['REQRES_RSPEC_APP'] %> API
|
90
90
|
</a></h1>
|
91
91
|
<% @records.group_by{|h| h[:group]}.each do |group, items| %>
|
92
92
|
<h2><%= group %></h2>
|
@@ -1,6 +1,6 @@
|
|
1
1
|
<html>
|
2
2
|
<head>
|
3
|
-
<title><%=
|
3
|
+
<title><%= ENV['REQRES_RSPEC_APP'] %> API Documentation</title>
|
4
4
|
<link href='http://fonts.googleapis.com/css?family=Droid+Sans:400,700' rel='stylesheet' type='text/css'>
|
5
5
|
<link href='http://fonts.googleapis.com/css?family=Droid+Sans+Mono' rel='stylesheet' type='text/css'>
|
6
6
|
<style>
|
@@ -139,12 +139,12 @@
|
|
139
139
|
margin: 0;
|
140
140
|
padding: 0 4px;
|
141
141
|
}
|
142
|
-
ol li:first-child{
|
142
|
+
ol li:first-child {
|
143
143
|
padding-top: 5px;
|
144
|
-
|
145
|
-
ol li:last-child{
|
144
|
+
}
|
145
|
+
ol li:last-child {
|
146
146
|
padding-bottom: 5px;
|
147
|
-
|
147
|
+
}
|
148
148
|
</style>
|
149
149
|
</head>
|
150
150
|
<body>
|
@@ -155,7 +155,7 @@
|
|
155
155
|
</h3>
|
156
156
|
|
157
157
|
<p>
|
158
|
-
<%= @record[:description].gsub("\n", '<br>'.html_safe) %>
|
158
|
+
<%= @record[:description].gsub("\n", ('<br>'.respond_to?(:html_safe) && '<br>'.html_safe) || '<br>') %>
|
159
159
|
</p>
|
160
160
|
|
161
161
|
<code><%= @record[:request][:method] %> <%= @record[:request_path] %></code>
|
@@ -179,7 +179,7 @@
|
|
179
179
|
<% end %>
|
180
180
|
</td>
|
181
181
|
<td><%= param[:type] %></td>
|
182
|
-
<td><%= param[:description].gsub("\n", '<br>'.html_safe) %></td>
|
182
|
+
<td><%= param[:description].gsub("\n", ('<br>'.respond_to?(:html_safe) && '<br>'.html_safe) || '<br>') %></td>
|
183
183
|
</tr>
|
184
184
|
<% end %>
|
185
185
|
</table>
|
data/lib/reqres_rspec.rb
CHANGED
@@ -10,10 +10,27 @@ if defined?(RSpec) && ENV['REQRES_RSPEC'] == '1'
|
|
10
10
|
config.after(:each) do
|
11
11
|
# TODO: remove boilerplate code
|
12
12
|
# TODO: better options
|
13
|
-
|
14
|
-
if
|
13
|
+
|
14
|
+
if defined?(Rails)
|
15
|
+
ENV['REQRES_RSPEC_ROOT'] = Rails.root.to_s
|
16
|
+
ENV['REQRES_RSPEC_APP'] = Rails.application.class.to_s.sub('::Application', '')
|
17
|
+
|
18
|
+
meta_data = self.class.example.metadata
|
19
|
+
if meta_data[:type] == :request && meta_data[:skip_reqres] == true
|
20
|
+
begin
|
21
|
+
collector.collect(self, self.request, self.response)
|
22
|
+
rescue NameError
|
23
|
+
raise $!
|
24
|
+
end
|
25
|
+
end
|
26
|
+
elsif defined?(Sinatra)
|
27
|
+
raise 'REQRES_RSPEC_ROOT is not defined' if ENV['REQRES_RSPEC_ROOT'].blank?
|
28
|
+
raise 'REQRES_RSPEC_APP is not defined' if ENV['REQRES_RSPEC_APP'].blank?
|
29
|
+
|
15
30
|
begin
|
16
|
-
collector.collect(self, self.
|
31
|
+
collector.collect(self, self.last_request, self.last_response)
|
32
|
+
rescue Rack::Test::Error
|
33
|
+
#
|
17
34
|
rescue NameError
|
18
35
|
raise $!
|
19
36
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: reqres_rspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.26
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- rilian
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-09-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: coderay
|