reqres_rspec 0.0.30 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 16e3a6ed401d13b632bd5ccc8600f1346715d3d6
4
- data.tar.gz: bee53bd581700e1a7b6dd56d97dc7caa3716d0a1
3
+ metadata.gz: 4f574d33801a5576da4abaffffb99110a428a358
4
+ data.tar.gz: e303ce1d7e6ba81ce6fe00c21d6ba38e3056ff6d
5
5
  SHA512:
6
- metadata.gz: ea8fdd6b422fa2d15ca3fd1ec95062142de46cdbd46e653f41c3f5637e8bf7da595a242029c2b7477b10822bf30259589af5623880a04e9ee52e5b4ba4e3f479
7
- data.tar.gz: ea7c0260a238d9922b9ecb50013234b59839c9906c9967debf2c87e0b62a9af724dabf74f1c697d7c773f820f82d1f01c98521427ae5ce287263e5e579e20008
6
+ metadata.gz: 41ea72db92b4ba65ccdbf5623198e5282a05ab0229d14ff6ecf2ee9b0117b7e8ee3d023adc92e9ce74e6537d3690aef5bfe00349901c451bb62310d35cd60d68
7
+ data.tar.gz: c9aab7c397bdb1e6f642e7c9e89aadbe17b84b379bb51403574fd1947ddb156ab8dde99a52945621cd96455076ee746840413f4f7c14b410c90d2e12774069fc
data/README.md CHANGED
@@ -37,6 +37,12 @@ by default `reqres_rspec` is not active (this may be configured!). To activate i
37
37
 
38
38
  Documentation will be put into your application's `/doc` folder
39
39
 
40
+ ## Upload to S3
41
+
42
+ By default ReqRes will use `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, `AWS_REGION` and `AWS_REQRES_BUCKET` environment variables. But you can alter that in configuration, see below.
43
+
44
+ `REQRES_UPLOAD=1 REQRES_RSPEC=1 bundle exec rspec --order=defined`
45
+
40
46
  ### Sample controller action
41
47
 
42
48
  ```ruby
@@ -79,6 +85,21 @@ Each param text is started with `@param` and first word will be param name, then
79
85
 
80
86
  Doc will use full example description, as a title for each separate spec
81
87
 
88
+ If you want to group examples in another way, you can do something like:
89
+
90
+ ```ruby
91
+ describe 'Something', reqres_section: 'Foo' do
92
+ context 'valid params', reqres_title: 'Bakes Pie' do
93
+ it 'works' do
94
+ ...
95
+ end
96
+ end
97
+ end
98
+ ```
99
+
100
+ In this case all the `reqres_sections` can be used for grouping colleced data into section, and `reqres_title` will become human readable titles:
101
+ [![Cusomized titles](http://i57.tinypic.com/2581lw9.jpg)](http://i57.tinypic.com/2581lw9.jpg)
102
+
82
103
  ### Generates documentation example
83
104
 
84
105
  [![Generated Doc](http://i44.tinypic.com/kda1pw.png)](http://i44.tinypic.com/kda1pw.png)
@@ -88,7 +109,59 @@ Documentation is written in HTML format, which then converted to PDF. PDF files
88
109
 
89
110
  ## Configuration
90
111
 
91
- TODO: Write instruction on gem configuration
112
+ ```ruby
113
+ ReqresRspec.configure do |c|
114
+ c.templates_path = Rails.root.join('spec/support/reqres/templates') # Path to custom templates
115
+ c.output_path = 'some path' # by default it will use doc/reqres
116
+ c.formatters = %w(MyCustomFormatter) # List of custom formatters, these can be inherited from ReqresRspec::Formatters::HTML
117
+ c.title = 'My API Documentation' # Title for your documentation
118
+ c.amazon_s3 = {
119
+ credentials: {
120
+ access_key_id: ENV['AWS_ACCESS_KEY_ID'], # by default it will use AWS_ACCESS_KEY_ID env var
121
+ secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'], # by default it will use AWS_SECRET_ACCESS_KEY env var
122
+ region: (ENV['AWS_REGION'] || 'us-east-1'),
123
+ },
124
+ bucket: ENV['AWS_REQRES_BUCKET'], # by default it will use AWS_REQRES_BUCKET env for bucket name
125
+ enabled: false # Enable upload (only with REQRES_UPLOAD env var set)
126
+ }
127
+ end
128
+ ```
129
+
130
+ ## Custom Formatter example
131
+
132
+ ```ruby
133
+ class CustomAPIDoc < ReqresRspec::Formatters::HTML
134
+ private
135
+ def write
136
+ # Copy assets
137
+ %w(styles images components scripts).each do |folder|
138
+ FileUtils.cp_r(path(folder), output_path)
139
+ end
140
+
141
+ # Generate general pages
142
+ @pages = {
143
+ 'index.html' => 'Introduction',
144
+ 'authentication.html' => 'Authentication',
145
+ 'filtering.html' => 'Filtering, Sorting and Pagination',
146
+ 'locations.html' => 'Locations',
147
+ 'files.html' => 'Files',
148
+ 'external-ids.html' => 'External IDs',
149
+ }
150
+
151
+ @pages.each do |filename, _|
152
+ @current_page = filename
153
+ save filename, render("pages/#{filename}")
154
+ end
155
+
156
+ # Generate API pages
157
+ @records.each do |record|
158
+ @record = record
159
+ @current_page = @record[:filename]
160
+ save "#{record[:filename]}.html", render('spec.html.erb')
161
+ end
162
+ end
163
+ end
164
+ ```
92
165
 
93
166
  ## Future plans
94
167
 
@@ -83,8 +83,8 @@ module ReqresRspec
83
83
 
84
84
  self.records << {
85
85
  filename: prepare_filename_for(spec.class.metadata),
86
- group: section, # Top level example group
87
- title: spec.class.example.full_description,
86
+ group: spec.class.metadata[:reqres_section] || section, # Top level example group
87
+ title: spec.class.metadata[:reqres_title] || spec.class.example.full_description,
88
88
  description: description,
89
89
  params: params,
90
90
  request_path: get_symbolized_path(request),
@@ -181,7 +181,7 @@ module ReqresRspec
181
181
  # returns action comments taken from controller file
182
182
  # example TODO
183
183
  def get_action_comments(controller, action)
184
- lines = File.readlines(File.join(ENV['REQRES_RSPEC_ROOT'], 'app', 'controllers', "#{controller}_controller.rb"))
184
+ lines = File.readlines(File.join(ReqresRspec.root, 'app', 'controllers', "#{controller}_controller.rb"))
185
185
 
186
186
  action_line = nil
187
187
  lines.each_with_index do |line, index|
@@ -0,0 +1,67 @@
1
+ module ReqresRspec
2
+ extend self
3
+
4
+ def configure
5
+ yield configuration
6
+ end
7
+
8
+ def configuration
9
+ @configuration ||= Configuration.new
10
+ end
11
+
12
+ def logger
13
+ @logger ||= if defined?(Rails)
14
+ Rails.logger
15
+ else
16
+ Logger.new(STDOUT)
17
+ end
18
+ end
19
+
20
+ def root
21
+ configuration.root
22
+ end
23
+
24
+ class Configuration
25
+ DEFAULT_FORMATTERS = %w(html pdf json)
26
+ def initialize
27
+ ReqresRspec.logger.level = Logger::INFO
28
+ @root = if defined?(Rails)
29
+ Rails.root.to_s
30
+ else
31
+ raise 'REQRES_RSPEC_ROOT is not defined' if ENV['REQRES_RSPEC_ROOT'].blank?
32
+ ENV['REQRES_RSPEC_ROOT']
33
+ end
34
+
35
+ @templates_path = File.expand_path('../templates', __FILE__)
36
+ @output_path = File.join(@root, '/doc/reqres')
37
+
38
+ requested_formats = (ENV['REQRES_RSPEC_FORMATTERS'].to_s).split(',')
39
+ requested_formats.sort_by!{|fmt| [DEFAULT_FORMATTERS.index(fmt), fmt]}
40
+ @formatters = requested_formats.empty? ? %w(html) : requested_formats
41
+
42
+ @amazon_s3 = {
43
+ credentials: {
44
+ access_key_id: ENV['AWS_ACCESS_KEY_ID'],
45
+ secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'],
46
+ region: (ENV['AWS_REGION'] || 'us-east-1'),
47
+ },
48
+ bucket: ENV['AWS_REQRES_BUCKET'],
49
+ enabled: false
50
+ }
51
+
52
+ @title = 'API Docs'
53
+ end
54
+
55
+ attr_accessor :templates_path
56
+ attr_accessor :output_path
57
+ attr_accessor :title
58
+ attr_accessor :formatters
59
+ attr_reader :root
60
+ attr_reader :amazon_s3
61
+
62
+ def amazon_s3=(config={})
63
+ @amazon_s3.deep_merge!(config)
64
+ end
65
+
66
+ end
67
+ end
@@ -0,0 +1,33 @@
1
+ module ReqresRspec
2
+ module Formatters
3
+ class Base
4
+ def initialize(records)
5
+ @records = records
6
+ @output_path = ReqresRspec.configuration.output_path
7
+ @logger = ReqresRspec.logger
8
+ end
9
+ attr_reader :logger, :output_path, :records
10
+
11
+ def process
12
+ cleanup
13
+ write
14
+ end
15
+ private
16
+ def write
17
+ raise 'Not Implemented'
18
+ end
19
+
20
+ def cleanup_pattern
21
+ '**/*'
22
+ end
23
+
24
+ def cleanup
25
+ unless Dir.exist?(output_path)
26
+ FileUtils.mkdir_p(output_path)
27
+ logger.info "#{output_path} was recreated"
28
+ end
29
+ FileUtils.rm_rf(Dir.glob("#{output_path}/#{cleanup_pattern}"), secure: true)
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,43 @@
1
+ require 'coderay'
2
+
3
+ module ReqresRspec
4
+ module Formatters
5
+ class HTML < Base
6
+ private
7
+ def write
8
+ files = {
9
+ 'rspec_doc_table_of_content.html' => 'header.erb',
10
+ 'index.html' => 'index.erb',
11
+ 'panel.html' => 'panel.erb'
12
+ }
13
+
14
+ files.each { |filename, template| save(filename, render(template)) }
15
+
16
+ @records.each do |record|
17
+ @record = record
18
+ save "rspec_doc_#{record[:filename]}.html", render('spec.erb')
19
+ end
20
+ end
21
+
22
+ def cleanup_pattern
23
+ '*.html'
24
+ end
25
+
26
+ def path(filename)
27
+ File.join(ReqresRspec.configuration.templates_path, filename)
28
+ end
29
+
30
+ def render(filename, arguments = {})
31
+ eval <<-RUBY
32
+ #{ arguments.map {|k, v| "#{k} = #{v}"}.join("\n") }
33
+ ERB.new(File.open(path(filename)).read).result(binding)
34
+ RUBY
35
+ end
36
+
37
+ def save(filename, data)
38
+ File.write(File.join(output_path, filename), data)
39
+ logger.info "Reqres::Formatters::HTML saved #{path(filename)}"
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,16 @@
1
+ module ReqresRspec
2
+ module Formatters
3
+ class JSON < Base
4
+ private
5
+ def write
6
+ path = File.join(output_path, 'reqres_rspec.json')
7
+ File.write(path, ::JSON.pretty_generate(records))
8
+ logger.info "Reqres::Writers::#{self.class.name} saved doc spec to #{path}"
9
+ end
10
+
11
+ def cleanup_pattern
12
+ 'reqres_rspec.json'
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,35 @@
1
+ module ReqresRspec
2
+ module Formatters
3
+ class Pdf < Base
4
+ # generates PDF file from existing HTML docs
5
+ # TODO: more info
6
+ def write
7
+ # http://www.princexml.com/download/
8
+ pdf_tool_path = 'prince'
9
+ pdf_doc_path = File.join(output_path, 'reqres_rspec.pdf')
10
+
11
+ if `which #{pdf_tool_path}`.size > 0
12
+ files = Dir["#{output_path}/*.html"]
13
+ files.reject!{ |filename| filename.scan(/rspec_doc/).empty? }
14
+ files.delete("#{output_path}/rspec_doc_table_of_content.html")
15
+ files.unshift("#{output_path}/rspec_doc_table_of_content.html")
16
+
17
+ if files.size > 0
18
+ files_arg = files.join('" "')
19
+ `#{pdf_tool_path} "#{files_arg}" -o "#{pdf_doc_path}"`
20
+
21
+ logger.info "ReqresRspec::Formatters::Pdf saved doc to #{pdf_doc_path}" if File.exists? pdf_doc_path
22
+ else
23
+ logger.error 'No HTML files found'
24
+ end
25
+ else
26
+ logger.error "#{pdf_tool_path} is not installed! Check README.md for more info"
27
+ end
28
+ end
29
+
30
+ def cleanup_pattern
31
+ 'reqres_rspec.pdf'
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,36 @@
1
+ module ReqresRspec
2
+ module Formatters
3
+ extend self
4
+
5
+ def process(records)
6
+ formatters = ReqresRspec.configuration.formatters
7
+ raise 'No formatters defined' if formatters.empty?
8
+
9
+ formatters.each do |fmt|
10
+ case fmt
11
+ when 'html'
12
+ HTML.new(records).process
13
+ when 'pdf'
14
+ HTML.new(records).process unless formatters.include?('html')
15
+ Pdf.new(records).process
16
+ when 'json'
17
+ JSON.new(records).process
18
+ else
19
+ begin
20
+ klass = Object.const_get(fmt)
21
+ unless klass.public_instance_methods.include?(:process)
22
+ raise "Formatter #{fmt} should respond to `process` method"
23
+ end
24
+ klass.new(records).process
25
+ rescue NameError => e
26
+ if e.message =~ /(uninitialized constant|wrong constant name) #{fmt}$/
27
+ raise "Formatter #{fmt} does not exists"
28
+ else
29
+ raise e
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -1,6 +1,6 @@
1
1
  <html>
2
2
  <head>
3
- <title><%= ENV['REQRES_RSPEC_APP'] %> API Documentation</title>
3
+ <title><%= ReqresRspec.configuration.title %></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><%= ENV['REQRES_RSPEC_APP'] %> API Documentation</h1>
61
+ <h1><%= ReqresRspec.configuration.title %></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><%= ENV['REQRES_RSPEC_APP'] %> API Documentation</title>
4
+ <title><%= ReqresRspec.configuration.title %></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><%= ENV['REQRES_RSPEC_APP'] %> API Documentation</title>
4
+ <title><%= ReqresRspec.configuration.title %></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_table_of_content.html" target="specs">
89
- <%= ENV['REQRES_RSPEC_APP'] %> API
89
+ <%= ReqresRspec.configuration.title %>
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><%= ENV['REQRES_RSPEC_APP'] %> API Documentation</title>
3
+ <title><%= ReqresRspec.configuration.title %></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>
@@ -0,0 +1,57 @@
1
+ require 'aws-sdk-core'
2
+
3
+ module ReqresRspec
4
+ module Uploaders
5
+ class AmazonS3
6
+ def initialize
7
+ @path = ReqresRspec.configuration.output_path
8
+ @logger = ReqresRspec.logger
9
+ @enabled = ReqresRspec.configuration.amazon_s3[:enabled] || false
10
+ @bucket = ReqresRspec.configuration.amazon_s3[:bucket]
11
+
12
+ ::Aws.config = ReqresRspec.configuration.amazon_s3[:credentials]
13
+ @s3 = ::Aws::S3::Client.new
14
+ end
15
+ attr_reader :logger, :path
16
+
17
+ def self.upload
18
+ uploader = self.new
19
+ uploader.process if uploader.enabled?
20
+ end
21
+
22
+ def enabled?
23
+ !!@enabled
24
+ end
25
+
26
+ def process
27
+ prepare_bucket
28
+
29
+ for file in Dir["#{path}/**/*"]
30
+ next if File.directory?(file)
31
+ local_path = file.gsub("#{@path}/", '')
32
+
33
+ start = Time.now
34
+ @s3.put_object bucket: @bucket, key: local_path, body: File.open(file, 'rb'), acl: "public-read"
35
+ done = Time.now
36
+
37
+ puts "[#{local_path}] Uploaded in #{done.to_i - start.to_i}s"
38
+ end
39
+ end
40
+
41
+ private
42
+ def prepare_bucket
43
+ @s3.create_bucket(
44
+ acl: "public-read",
45
+ bucket: @bucket
46
+ )
47
+
48
+ @s3.put_bucket_website(
49
+ bucket: @bucket,
50
+ website_configuration: {
51
+ index_document: { suffix: 'index.html' }
52
+ }
53
+ )
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,27 @@
1
+ module ReqresRspec
2
+ module Uploaders
3
+ extend self
4
+
5
+ def upload
6
+ if defined?(WebMock)
7
+ WebMock.allow_net_connect!
8
+ end
9
+
10
+ if defined?(VCR)
11
+ VCR.configure do |c|
12
+ c.ignore_request do |request|
13
+ URI(request.uri).host == 's3.amazonaws.com'
14
+ end
15
+ end
16
+ end
17
+
18
+ self.constants.each do |name|
19
+ klass = Object.const_get("ReqresRspec::Uploaders::#{name}")
20
+ if klass.public_instance_methods.include?(:upload)
21
+ klass.upload
22
+ end
23
+ end
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,25 @@
1
+ unless String.respond_to?(:underscore)
2
+ class String
3
+ def underscore
4
+ self.gsub(/::/, '/').
5
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
6
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
7
+ tr("-", "_").
8
+ downcase
9
+ end
10
+ end
11
+ end
12
+
13
+ unless Hash.respond_to?(:deep_merge)
14
+ class ::Hash
15
+ def deep_merge(second)
16
+ merger = proc { |key, v1, v2| Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : v2 }
17
+ self.merge(second, &merger)
18
+ end
19
+
20
+ def deep_merge!(second)
21
+ merger = proc { |key, v1, v2| Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : v2 }
22
+ self.merge!(second, &merger)
23
+ end
24
+ end
25
+ end
@@ -1,3 +1,3 @@
1
1
  module ReqresRspec
2
- VERSION = '0.0.30'
2
+ VERSION = '0.1.0'
3
3
  end
data/lib/reqres_rspec.rb CHANGED
@@ -1,21 +1,21 @@
1
1
  require 'reqres_rspec/version'
2
+ require 'reqres_rspec/utils'
3
+ require 'reqres_rspec/configuration'
2
4
  require 'reqres_rspec/collector'
3
- require 'reqres_rspec/writers/html'
4
- require 'reqres_rspec/writers/json_formatter'
5
- require 'reqres_rspec/generators/pdf'
5
+ require 'reqres_rspec/formatters'
6
+ require 'reqres_rspec/formatters/base'
7
+ require 'reqres_rspec/formatters/html'
8
+ require 'reqres_rspec/formatters/json'
9
+ require 'reqres_rspec/formatters/pdf'
10
+ require 'reqres_rspec/uploaders'
11
+ require 'reqres_rspec/uploaders/amazon_s3'
6
12
 
7
13
  if defined?(RSpec) && ENV['REQRES_RSPEC'] == '1'
8
14
  collector = ReqresRspec::Collector.new
9
15
 
10
16
  RSpec.configure do |config|
11
17
  config.after(:each) do
12
- # TODO: remove boilerplate code
13
- # TODO: better options
14
-
15
18
  if defined?(Rails)
16
- ENV['REQRES_RSPEC_ROOT'] = Rails.root.to_s
17
- ENV['REQRES_RSPEC_APP'] = Rails.application.class.to_s.sub('::Application', '')
18
-
19
19
  meta_data = self.class.example.metadata
20
20
  if meta_data[:type] == :request && !meta_data[:skip_reqres] == true
21
21
  begin
@@ -25,9 +25,6 @@ if defined?(RSpec) && ENV['REQRES_RSPEC'] == '1'
25
25
  end
26
26
  end
27
27
  elsif defined?(Sinatra)
28
- raise 'REQRES_RSPEC_ROOT is not defined' if ENV['REQRES_RSPEC_ROOT'].blank?
29
- raise 'REQRES_RSPEC_APP is not defined' if ENV['REQRES_RSPEC_APP'].blank?
30
-
31
28
  begin
32
29
  collector.collect(self, self.last_request, self.last_response)
33
30
  rescue Rack::Test::Error
@@ -41,25 +38,8 @@ if defined?(RSpec) && ENV['REQRES_RSPEC'] == '1'
41
38
  config.after(:suite) do
42
39
  if collector.records.size > 0
43
40
  collector.sort
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
- #
41
+ ReqresRspec::Formatters.process(collector.records)
42
+ ReqresRspec::Uploaders.upload if ENV['REQRES_UPLOAD'] == '1'
63
43
  end
64
44
  end
65
45
  end
data/reqres_rspec.gemspec CHANGED
@@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ['lib']
20
20
 
21
21
  spec.add_dependency 'coderay'
22
+ spec.add_dependency 'aws-sdk-core', '~> 2.0'
22
23
 
23
24
  spec.add_development_dependency 'bundler', '~> 1.3'
24
25
  spec.add_development_dependency 'rake'
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.30
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - rilian
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-22 00:00:00.000000000 Z
11
+ date: 2014-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: coderay
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: aws-sdk-core
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -69,14 +83,20 @@ files:
69
83
  - Rakefile
70
84
  - lib/reqres_rspec.rb
71
85
  - lib/reqres_rspec/collector.rb
72
- - lib/reqres_rspec/generators/pdf.rb
86
+ - lib/reqres_rspec/configuration.rb
87
+ - lib/reqres_rspec/formatters.rb
88
+ - lib/reqres_rspec/formatters/base.rb
89
+ - lib/reqres_rspec/formatters/html.rb
90
+ - lib/reqres_rspec/formatters/json.rb
91
+ - lib/reqres_rspec/formatters/pdf.rb
92
+ - lib/reqres_rspec/templates/header.erb
93
+ - lib/reqres_rspec/templates/index.erb
94
+ - lib/reqres_rspec/templates/panel.erb
95
+ - lib/reqres_rspec/templates/spec.erb
96
+ - lib/reqres_rspec/uploaders.rb
97
+ - lib/reqres_rspec/uploaders/amazon_s3.rb
98
+ - lib/reqres_rspec/utils.rb
73
99
  - lib/reqres_rspec/version.rb
74
- - lib/reqres_rspec/writers/html.rb
75
- - lib/reqres_rspec/writers/json_formatter.rb
76
- - lib/reqres_rspec/writers/templates/header.erb
77
- - lib/reqres_rspec/writers/templates/index.erb
78
- - lib/reqres_rspec/writers/templates/panel.erb
79
- - lib/reqres_rspec/writers/templates/spec.erb
80
100
  - reqres_rspec.gemspec
81
101
  homepage: https://github.com/reqres-api/reqres_rspec
82
102
  licenses:
@@ -1,29 +0,0 @@
1
- module ReqresRspec
2
- module Generators
3
- class Pdf
4
- # generates PDF file from existing HTML docs
5
- # TODO: more info
6
- def generate
7
- # http://www.princexml.com/download/
8
- pdf_tool_path = 'prince'
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
-
12
- if `which #{pdf_tool_path}`.size > 0
13
- files = Dir["#{html_docs_root}/rspec_doc_*.html"]
14
- if files.size > 0
15
- files_arg = files.map { |f| f if f =~ /\/rspec_doc_\d+\.html/ }.compact.sort.join('" "')
16
-
17
- `#{pdf_tool_path} "#{files_arg}" -o "#{pdf_doc_path}"`
18
-
19
- puts "ReqresRspec::Generators::Pdf saved doc to #{pdf_doc_path}" if File.exists? pdf_doc_path
20
- else
21
- puts 'No HTML files found'
22
- end
23
- else
24
- puts "ERROR: #{pdf_tool_path} is not installed! Check README.md for more info"
25
- end
26
- end
27
- end
28
- end
29
- end
@@ -1,89 +0,0 @@
1
- require 'coderay'
2
-
3
- module ReqresRspec
4
- module Writers
5
- class Html
6
- def initialize(records)
7
- @records = records
8
- end
9
-
10
- def write
11
- recreate_doc_dir
12
- cleanup
13
- generate_header
14
- generate_specs
15
-
16
- append_index
17
- append_panel
18
- end
19
-
20
- private
21
-
22
- # recreates /doc dir if it does not exist
23
- def recreate_doc_dir
24
- doc_dir = File.join(ENV['REQRES_RSPEC_ROOT'], 'doc')
25
- unless Dir.exist?(doc_dir)
26
- Dir.mkdir(doc_dir)
27
- puts "#{doc_dir} was recreated"
28
- end
29
- end
30
-
31
- # deletes previous version of HTML docs
32
- # TODO: more info
33
- def cleanup
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
- end
38
-
39
- # generates contents of HTML docs
40
- # TODO: more info
41
- def generate_header
42
- tpl_path = File.join(File.dirname(__FILE__), 'templates', 'header.erb')
43
- rendered_doc = ERB.new(File.open(tpl_path).read).result(binding)
44
-
45
- path = File.join(ENV['REQRES_RSPEC_ROOT'], 'doc', 'rspec_doc_table_of_content.html')
46
- file = File.open(path, 'w')
47
- file.write(rendered_doc)
48
- file.close
49
- puts "Reqres::Writers::Html saved doc header to #{path}"
50
- end
51
-
52
- # generates each separate spec example doc
53
- # TODO: more info
54
- def generate_specs
55
- tpl_path = File.join(File.dirname(__FILE__), 'templates', 'spec.erb')
56
-
57
- @records.each do |record|
58
- @record = record
59
- rendered_doc = ERB.new(File.open(tpl_path).read).result(binding)
60
-
61
- path = File.join(ENV['REQRES_RSPEC_ROOT'], 'doc', "rspec_doc_#{record[:filename]}.html")
62
- file = File.open(path, 'w')
63
- file.write(rendered_doc)
64
- file.close
65
- puts "Reqres::Writers::Html saved doc spec to #{path}"
66
- end
67
- end
68
-
69
- # creates an index file with iframes if does not exists
70
- def append_index
71
- index_file = File.join(ENV['REQRES_RSPEC_ROOT'], 'doc', 'index.html')
72
- unless File.exists?(index_file)
73
- tpl_path = File.join(File.dirname(__FILE__), 'templates', 'index.erb')
74
- rendered_doc = ERB.new(File.open(tpl_path).read).result(binding)
75
- File.write index_file, rendered_doc
76
- end
77
- end
78
-
79
- def append_panel
80
- index_file = File.join(ENV['REQRES_RSPEC_ROOT'], 'doc', 'panel.html')
81
- unless File.exists?(index_file)
82
- tpl_path = File.join(File.dirname(__FILE__), 'templates', 'panel.erb')
83
- rendered_doc = ERB.new(File.open(tpl_path).read).result(binding)
84
- File.write index_file, rendered_doc
85
- end
86
- end
87
- end
88
- end
89
- end
@@ -1,37 +0,0 @@
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