reqres_rspec 0.0.27 → 0.0.28
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 +16 -0
- data/lib/reqres_rspec/version.rb +1 -1
- data/lib/reqres_rspec/writers/html.rb +3 -5
- data/lib/reqres_rspec/writers/json_formatter.rb +37 -0
- data/lib/reqres_rspec/writers/templates/header.erb +1 -1
- data/lib/reqres_rspec/writers/templates/index.erb +1 -1
- data/lib/reqres_rspec/writers/templates/panel.erb +2 -2
- data/lib/reqres_rspec.rb +20 -2
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5bb6f6c25de702cda33d7ade7d745595581f2b47
|
4
|
+
data.tar.gz: 8431098e926bc378384c6ccfc9fb7effbfa3b64b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 47a37d830c57ce22e437f447b36871071511b29ede79ebb84d14acea4291956cc7bf246cd02df1fe7c7f333b47fa38fd1e02bc5c82ce471c12d35890e6d57d56
|
7
|
+
data.tar.gz: fe276e431fe0c53d9e757fb7b02974b0814ee07f214560e3103d3f78d5ed6f7b2dbac88e9aa62dcdcd3fbb0dcd8b85830e5bf662b891f1afe78bd4eff7c5edf2
|
@@ -82,6 +82,7 @@ module ReqresRspec
|
|
82
82
|
end
|
83
83
|
|
84
84
|
self.records << {
|
85
|
+
filename: prepare_filename_for(spec.class.metadata),
|
85
86
|
group: section, # Top level example group
|
86
87
|
title: spec.class.example.full_description,
|
87
88
|
description: description,
|
@@ -108,6 +109,21 @@ module ReqresRspec
|
|
108
109
|
}
|
109
110
|
end
|
110
111
|
|
112
|
+
def prepare_filename_for(metadata)
|
113
|
+
description = metadata[:description]
|
114
|
+
example_group = if metadata.key?(:example_group)
|
115
|
+
metadata[:example_group]
|
116
|
+
else
|
117
|
+
metadata[:parent_example_group]
|
118
|
+
end
|
119
|
+
|
120
|
+
if example_group
|
121
|
+
[prepare_filename_for(example_group), description].join('/')
|
122
|
+
else
|
123
|
+
description
|
124
|
+
end.gsub!(/[\W]+/, '_')
|
125
|
+
end
|
126
|
+
|
111
127
|
# sorts records alphabetically
|
112
128
|
def sort
|
113
129
|
self.records.sort!{ |x,y| x[:request_path] <=> y[:request_path] }
|
data/lib/reqres_rspec/version.rb
CHANGED
@@ -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(ENV['REQRES_RSPEC_ROOT'], 'doc', '
|
45
|
+
path = File.join(ENV['REQRES_RSPEC_ROOT'], 'doc', 'rspec_doc_table_of_content.html')
|
46
46
|
file = File.open(path, 'w')
|
47
47
|
file.write(rendered_doc)
|
48
48
|
file.close
|
@@ -54,13 +54,11 @@ module ReqresRspec
|
|
54
54
|
def generate_specs
|
55
55
|
tpl_path = File.join(File.dirname(__FILE__), 'templates', 'spec.erb')
|
56
56
|
|
57
|
-
@records.
|
57
|
+
@records.each do |record|
|
58
58
|
@record = record
|
59
|
-
@index = index + 1
|
60
|
-
|
61
59
|
rendered_doc = ERB.new(File.open(tpl_path).read).result(binding)
|
62
60
|
|
63
|
-
path = File.join(ENV['REQRES_RSPEC_ROOT'], 'doc', "rspec_doc_#{
|
61
|
+
path = File.join(ENV['REQRES_RSPEC_ROOT'], 'doc', "rspec_doc_#{record[:filename]}.html")
|
64
62
|
file = File.open(path, 'w')
|
65
63
|
file.write(rendered_doc)
|
66
64
|
file.close
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'coderay'
|
2
|
+
|
3
|
+
module ReqresRspec
|
4
|
+
module Writers
|
5
|
+
class JSONFormatter
|
6
|
+
def initialize(records)
|
7
|
+
@records = records
|
8
|
+
end
|
9
|
+
|
10
|
+
def write
|
11
|
+
recreate_doc_dir
|
12
|
+
cleanup
|
13
|
+
|
14
|
+
path = File.join(ENV['REQRES_RSPEC_ROOT'], 'doc', 'reqres_rspec.json')
|
15
|
+
File.write(path, JSON.pretty_generate(@records))
|
16
|
+
puts "Reqres::Writers::JSONFormatter saved doc spec to #{path}"
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
# recreates /doc dir if it does not exist
|
22
|
+
def recreate_doc_dir
|
23
|
+
doc_dir = File.join(ENV['REQRES_RSPEC_ROOT'], 'doc')
|
24
|
+
unless Dir.exist?(doc_dir)
|
25
|
+
Dir.mkdir(doc_dir)
|
26
|
+
puts "#{doc_dir} was recreated"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# deletes previous version of HTML docs
|
31
|
+
# TODO: more info
|
32
|
+
def cleanup
|
33
|
+
FileUtils.rm_rf(Dir.glob("#{ENV['REQRES_RSPEC_ROOT']}/doc/reqres_rspec.json"), secure: true)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -19,6 +19,6 @@
|
|
19
19
|
</head>
|
20
20
|
<frameset cols="350,*" frameborder="1" border="1" bordercolor="#999999" framespacing="1">
|
21
21
|
<frame name="panel" src="./panel.html">
|
22
|
-
<frame name="specs" src="./
|
22
|
+
<frame name="specs" src="./rspec_doc_table_of_content.html">
|
23
23
|
</frameset>
|
24
24
|
</html>
|
@@ -85,7 +85,7 @@
|
|
85
85
|
</style>
|
86
86
|
</head>
|
87
87
|
<body>
|
88
|
-
<h1><a href="
|
88
|
+
<h1><a href="rspec_doc_table_of_content.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| %>
|
@@ -95,7 +95,7 @@
|
|
95
95
|
<ul>
|
96
96
|
<% records.each do |record| %>
|
97
97
|
<li>
|
98
|
-
<a href="rspec_doc_<%=
|
98
|
+
<a href="rspec_doc_<%= record[:filename] %>.html" target="specs">
|
99
99
|
<span class="method <%= record[:request][:method].downcase %>"><%= record[:request][:method] %></span>
|
100
100
|
<%= record[:title] %><br />
|
101
101
|
</a>
|
data/lib/reqres_rspec.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'reqres_rspec/version'
|
2
2
|
require 'reqres_rspec/collector'
|
3
3
|
require 'reqres_rspec/writers/html'
|
4
|
+
require 'reqres_rspec/writers/json_formatter'
|
4
5
|
require 'reqres_rspec/generators/pdf'
|
5
6
|
|
6
7
|
if defined?(RSpec) && ENV['REQRES_RSPEC'] == '1'
|
@@ -40,8 +41,25 @@ if defined?(RSpec) && ENV['REQRES_RSPEC'] == '1'
|
|
40
41
|
config.after(:suite) do
|
41
42
|
if collector.records.size > 0
|
42
43
|
collector.sort
|
43
|
-
|
44
|
-
|
44
|
+
formatters = %w(html pdf json)
|
45
|
+
|
46
|
+
requested_formats = (ENV['REQRES_RSPEC_FORMATTERS'] || 'html').split(',')
|
47
|
+
requested_formats.sort_by!{|fmt| [formatters.index(fmt), fmt]}
|
48
|
+
requested_formats.each do |fmt|
|
49
|
+
case fmt
|
50
|
+
when 'html'
|
51
|
+
ReqresRspec::Writers::Html.new(collector.records).write
|
52
|
+
when 'pdf'
|
53
|
+
ReqresRspec::Writers::Html.new(collector.records).write unless requested_formats.include?('html')
|
54
|
+
ReqresRspec::Generators::Pdf.new.generate
|
55
|
+
when 'json'
|
56
|
+
ReqresRspec::Writers::JSONFormatter.new(collector.records).write
|
57
|
+
else
|
58
|
+
puts "No formatters defined, define one of #{formatters} in REQRES_RSPEC_FORMATTERS"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
#
|
45
63
|
end
|
46
64
|
end
|
47
65
|
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.28
|
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-10-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: coderay
|
@@ -72,6 +72,7 @@ files:
|
|
72
72
|
- lib/reqres_rspec/generators/pdf.rb
|
73
73
|
- lib/reqres_rspec/version.rb
|
74
74
|
- lib/reqres_rspec/writers/html.rb
|
75
|
+
- lib/reqres_rspec/writers/json_formatter.rb
|
75
76
|
- lib/reqres_rspec/writers/templates/header.erb
|
76
77
|
- lib/reqres_rspec/writers/templates/index.erb
|
77
78
|
- lib/reqres_rspec/writers/templates/panel.erb
|