reportir 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +4 -0
  5. data/CODE_OF_CONDUCT.md +13 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +81 -0
  9. data/Rakefile +6 -0
  10. data/bin/console +14 -0
  11. data/bin/setup +7 -0
  12. data/lib/reportir/static_site_template/.editorconfig +13 -0
  13. data/lib/reportir/static_site_template/.gitattributes +1 -0
  14. data/lib/reportir/static_site_template/.gitignore +2 -0
  15. data/lib/reportir/static_site_template/.htaccess +984 -0
  16. data/lib/reportir/static_site_template/404.html +60 -0
  17. data/lib/reportir/static_site_template/LICENSE.txt +19 -0
  18. data/lib/reportir/static_site_template/apple-touch-icon.png +0 -0
  19. data/lib/reportir/static_site_template/browserconfig.xml +12 -0
  20. data/lib/reportir/static_site_template/crossdomain.xml +15 -0
  21. data/lib/reportir/static_site_template/css/font/FontAwesome.otf +0 -0
  22. data/lib/reportir/static_site_template/css/font/fontawesome-webfont.eot +0 -0
  23. data/lib/reportir/static_site_template/css/font/fontawesome-webfont.svg +284 -0
  24. data/lib/reportir/static_site_template/css/font/fontawesome-webfont.ttf +0 -0
  25. data/lib/reportir/static_site_template/css/font/fontawesome-webfont.woff +0 -0
  26. data/lib/reportir/static_site_template/css/main.css +348 -0
  27. data/lib/reportir/static_site_template/css/normalize.css +424 -0
  28. data/lib/reportir/static_site_template/css/vendor/bootstrap.min.css +5 -0
  29. data/lib/reportir/static_site_template/css/vendor/font-awesome.min.css +33 -0
  30. data/lib/reportir/static_site_template/doc/TOC.md +29 -0
  31. data/lib/reportir/static_site_template/doc/css.md +162 -0
  32. data/lib/reportir/static_site_template/doc/extend.md +663 -0
  33. data/lib/reportir/static_site_template/doc/faq.md +62 -0
  34. data/lib/reportir/static_site_template/doc/html.md +223 -0
  35. data/lib/reportir/static_site_template/doc/js.md +37 -0
  36. data/lib/reportir/static_site_template/doc/misc.md +175 -0
  37. data/lib/reportir/static_site_template/doc/usage.md +130 -0
  38. data/lib/reportir/static_site_template/favicon.ico +0 -0
  39. data/lib/reportir/static_site_template/humans.txt +15 -0
  40. data/lib/reportir/static_site_template/img/.gitignore +0 -0
  41. data/lib/reportir/static_site_template/img/pagination.png +0 -0
  42. data/lib/reportir/static_site_template/index.html +78 -0
  43. data/lib/reportir/static_site_template/js/main.js +0 -0
  44. data/lib/reportir/static_site_template/js/plugins.js +24 -0
  45. data/lib/reportir/static_site_template/js/vendor/bootstrap.min.js +7 -0
  46. data/lib/reportir/static_site_template/js/vendor/jquery-1.11.3.min.js +6 -0
  47. data/lib/reportir/static_site_template/js/vendor/jquery.slides.min.js +7 -0
  48. data/lib/reportir/static_site_template/js/vendor/modernizr-2.8.3.min.js +4 -0
  49. data/lib/reportir/static_site_template/robots.txt +5 -0
  50. data/lib/reportir/static_site_template/tile-wide.png +0 -0
  51. data/lib/reportir/static_site_template/tile.png +0 -0
  52. data/lib/reportir/version.rb +3 -0
  53. data/lib/reportir.rb +109 -0
  54. data/reportir.gemspec +29 -0
  55. metadata +196 -0
data/lib/reportir.rb ADDED
@@ -0,0 +1,109 @@
1
+ require "reportir/version"
2
+ require 's3_uploader'
3
+ require 'aws-sdk'
4
+
5
+ module Reportir
6
+ @@static_site_template_path = Gem.find_files('reportir')[1] +'/static_site_template'
7
+ @@template_subdirectory_for_test_artifacts = 'test_run'
8
+ @@step = 0
9
+
10
+ def upload_result_to_s3_as_static_site
11
+ check_for_env_vars
12
+ clone_template
13
+ reset_orig_template # TODO: clone before screenshots are possible
14
+ save_final_markup_in_clone
15
+ write_ractive_models_in_clone(screenshots: screenshot_paths, nav: nav_links)
16
+ upload_clone_to_s3
17
+ delete_local_clone
18
+ end
19
+
20
+ private
21
+
22
+ def check_for_env_vars
23
+ raise Reportir::Error.new 'Missing ENV AWS_DEFAULT_BUCKET' unless ENV['AWS_DEFAULT_BUCKET']
24
+ raise Reportir::Error.new 'Missing ENV AWS_SECRET_ACCESS_KEY' unless ENV['AWS_SECRET_ACCESS_KEY']
25
+ raise Reportir::Error.new 'Missing ENV AWS_ACCESS_KEY_ID' unless ENV['AWS_ACCESS_KEY_ID']
26
+ raise Reportir::Error.new 'Missing ENV AWS_DEFAULT_REGION' unless ENV['AWS_DEFAULT_REGION']
27
+ end
28
+
29
+ def clone_template
30
+ FileUtils.cp_r "#{@@static_site_template_path}/.", clone_dir_path
31
+ end
32
+
33
+ def reset_orig_template
34
+ FileUtils.rm_rf "#{@@static_site_template_path}/#{@@template_subdirectory_for_test_artifacts}"
35
+ end
36
+
37
+ def save_final_markup_in_clone
38
+ s3_screenshot('final')
39
+ File.open("#{deletable_data_path}/final.html", 'w') {|f| f.write @browser.html }
40
+ end
41
+
42
+ def write_ractive_models_in_clone(data)
43
+ data.each do |k,v|
44
+ model = {el: "##{k}_container", template: "##{k}_template", data: {k => v}}
45
+ File.open("#{clone_dir_path}/js/main.js", "a") { |f| f.write("var #{k} = new Ractive(#{model.to_json});\n") }
46
+ end
47
+ end
48
+
49
+ def upload_clone_to_s3
50
+ puts '====== STARTING S3 UPLOAD ========='
51
+ puts ''
52
+ ::Aws::S3::Bucket.new(ENV['AWS_DEFAULT_BUCKET']).clear!
53
+ ::S3Uploader.upload_directory(clone_dir_path, ENV['AWS_DEFAULT_BUCKET'], {
54
+ :destination_dir => test_name,
55
+ :threads => 5,
56
+ s3_key: ENV['AWS_ACCESS_KEY_ID'],
57
+ s3_secret: ENV['AWS_SECRET_ACCESS_KEY'],
58
+ region: ENV['AWS_DEFAULT_REGION'] })
59
+ puts ''
60
+ puts '====== S3 UPLOAD COMPLETE ========='
61
+ puts 'URL: ' + static_site_url
62
+ puts '==================================='
63
+ end
64
+
65
+ def delete_local_clone
66
+ FileUtils.rm_rf clone_dir_path
67
+ end
68
+
69
+ def test_name
70
+ RSpec.current_example.metadata[:full_description].gsub(/[^\w\s]/,'').gsub(/\s/,'_')
71
+ end
72
+
73
+ def clone_dir_path
74
+ "./tmp/#{test_name}"
75
+ end
76
+
77
+ def static_site_url
78
+ "http://#{ENV['AWS_DEFAULT_BUCKET']}.s3-website-#{ENV['AWS_DEFAULT_REGION']}.amazonaws.com/#{test_name}"
79
+ end
80
+
81
+ def s3_screenshot(method)
82
+ @@step = @@step+=1
83
+ image_name = "#{@@step}-#{method}"
84
+ FileUtils.mkdir_p(deletable_data_path) unless Dir.exists?(deletable_data_path)
85
+ @browser.screenshot.save("#{deletable_data_path}/#{image_name}.png")
86
+ end
87
+
88
+ def deletable_data_path
89
+ "#{clone_dir_path}/#{@@template_subdirectory_for_test_artifacts}"
90
+ end
91
+
92
+ def nav_links
93
+ {'Last Page as Markup' => "#{@@template_subdirectory_for_test_artifacts}/final.html"}
94
+ end
95
+
96
+ def screenshot_paths
97
+ images = []
98
+ Dir["#{deletable_data_path}/**/*.png"].sort_by { |x| x[/\d+/].to_i }.each do |src|
99
+ images << "#{@@template_subdirectory_for_test_artifacts}/#{Pathname.new(src).basename}"
100
+ end
101
+ images
102
+ end
103
+
104
+ def clear_out_any_old_results
105
+ puts "> Cleaning out old #{deletable_data_path} directory"
106
+ FileUtils.rm_rf "#{deletable_data_path}/*"
107
+ end
108
+ class Error < ::StandardError; end
109
+ end
data/reportir.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'reportir/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "reportir"
8
+ spec.version = Reportir::VERSION
9
+ spec.authors = ["Dean Shelton"]
10
+ spec.email = ["deanshelton913@gmail.com"]
11
+
12
+ spec.summary = %q{Send screenshots to s3 as a reviewable website}
13
+ spec.description = %q{Take screenshots with capybara/watir/whatever, and upload them automatically to an AWS S3 bucket as a static website. Requires static site configuration in S3.}
14
+ spec.homepage = "http://github.com/reportir"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.10"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec"
25
+ spec.add_runtime_dependency 's3_uploader'
26
+ spec.add_runtime_dependency 'aws-sdk'
27
+ spec.add_runtime_dependency 'fileutils'
28
+ spec.add_runtime_dependency 'json'
29
+ end
metadata ADDED
@@ -0,0 +1,196 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: reportir
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Dean Shelton
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-08-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: s3_uploader
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: aws-sdk
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: fileutils
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: json
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Take screenshots with capybara/watir/whatever, and upload them automatically
112
+ to an AWS S3 bucket as a static website. Requires static site configuration in S3.
113
+ email:
114
+ - deanshelton913@gmail.com
115
+ executables: []
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - ".gitignore"
120
+ - ".rspec"
121
+ - ".travis.yml"
122
+ - CODE_OF_CONDUCT.md
123
+ - Gemfile
124
+ - LICENSE.txt
125
+ - README.md
126
+ - Rakefile
127
+ - bin/console
128
+ - bin/setup
129
+ - lib/reportir.rb
130
+ - lib/reportir/static_site_template/.editorconfig
131
+ - lib/reportir/static_site_template/.gitattributes
132
+ - lib/reportir/static_site_template/.gitignore
133
+ - lib/reportir/static_site_template/.htaccess
134
+ - lib/reportir/static_site_template/404.html
135
+ - lib/reportir/static_site_template/LICENSE.txt
136
+ - lib/reportir/static_site_template/apple-touch-icon.png
137
+ - lib/reportir/static_site_template/browserconfig.xml
138
+ - lib/reportir/static_site_template/crossdomain.xml
139
+ - lib/reportir/static_site_template/css/font/FontAwesome.otf
140
+ - lib/reportir/static_site_template/css/font/fontawesome-webfont.eot
141
+ - lib/reportir/static_site_template/css/font/fontawesome-webfont.svg
142
+ - lib/reportir/static_site_template/css/font/fontawesome-webfont.ttf
143
+ - lib/reportir/static_site_template/css/font/fontawesome-webfont.woff
144
+ - lib/reportir/static_site_template/css/main.css
145
+ - lib/reportir/static_site_template/css/normalize.css
146
+ - lib/reportir/static_site_template/css/vendor/bootstrap.min.css
147
+ - lib/reportir/static_site_template/css/vendor/font-awesome.min.css
148
+ - lib/reportir/static_site_template/doc/TOC.md
149
+ - lib/reportir/static_site_template/doc/css.md
150
+ - lib/reportir/static_site_template/doc/extend.md
151
+ - lib/reportir/static_site_template/doc/faq.md
152
+ - lib/reportir/static_site_template/doc/html.md
153
+ - lib/reportir/static_site_template/doc/js.md
154
+ - lib/reportir/static_site_template/doc/misc.md
155
+ - lib/reportir/static_site_template/doc/usage.md
156
+ - lib/reportir/static_site_template/favicon.ico
157
+ - lib/reportir/static_site_template/humans.txt
158
+ - lib/reportir/static_site_template/img/.gitignore
159
+ - lib/reportir/static_site_template/img/pagination.png
160
+ - lib/reportir/static_site_template/index.html
161
+ - lib/reportir/static_site_template/js/main.js
162
+ - lib/reportir/static_site_template/js/plugins.js
163
+ - lib/reportir/static_site_template/js/vendor/bootstrap.min.js
164
+ - lib/reportir/static_site_template/js/vendor/jquery-1.11.3.min.js
165
+ - lib/reportir/static_site_template/js/vendor/jquery.slides.min.js
166
+ - lib/reportir/static_site_template/js/vendor/modernizr-2.8.3.min.js
167
+ - lib/reportir/static_site_template/robots.txt
168
+ - lib/reportir/static_site_template/tile-wide.png
169
+ - lib/reportir/static_site_template/tile.png
170
+ - lib/reportir/version.rb
171
+ - reportir.gemspec
172
+ homepage: http://github.com/reportir
173
+ licenses:
174
+ - MIT
175
+ metadata: {}
176
+ post_install_message:
177
+ rdoc_options: []
178
+ require_paths:
179
+ - lib
180
+ required_ruby_version: !ruby/object:Gem::Requirement
181
+ requirements:
182
+ - - ">="
183
+ - !ruby/object:Gem::Version
184
+ version: '0'
185
+ required_rubygems_version: !ruby/object:Gem::Requirement
186
+ requirements:
187
+ - - ">="
188
+ - !ruby/object:Gem::Version
189
+ version: '0'
190
+ requirements: []
191
+ rubyforge_project:
192
+ rubygems_version: 2.4.6
193
+ signing_key:
194
+ specification_version: 4
195
+ summary: Send screenshots to s3 as a reviewable website
196
+ test_files: []