reportir 0.3.3 → 0.3.4

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: 984561d1c0d5ce2d7d61d43bc6da95651679cd6c
4
- data.tar.gz: bc8caa6a3a64650fa85194017ca2551c2f02264c
3
+ metadata.gz: b1a0a872f186144298bd154d38a3203533f390e0
4
+ data.tar.gz: 76ea24f9b85688e68cff714959351038940bf861
5
5
  SHA512:
6
- metadata.gz: 05fb3a93750af32b5c528a886d868ae14be35e85b34ad52ede3517b5c9b4a9864ebbaf74293c65482bce33c75ad4b2e3f34cdbb72f0a78b72ab882fb413194c7
7
- data.tar.gz: df018eeb4a717cc113f78ea55e158df646e90248702b275156d65b5c83517b079862703472dcae19f04a59757343d5d1d76433885c7bd2b3a635e9e0a856d583
6
+ metadata.gz: 226a7bd746ce679c3ace4c4d8b92ac7ea1f5ab43d59ac5471427857bc9e67b18ad0af8d8c925d05740681fbb636a408379c74276814dc9d47e43d9508ce8c4be
7
+ data.tar.gz: dd9a43850739b4a1c9f27ed17e9cc398529deb81269f50fdb30ebfac84d1ee1140d078a47929a62a7791e7d4bc84dad5c498f8bc4be03236b8cb6c761b98b1bb
@@ -2,12 +2,25 @@ require "reportir/version"
2
2
  require 's3_uploader'
3
3
  require 'aws-sdk'
4
4
 
5
+ #TODO: RSpec::Core::Formatters.register
6
+
5
7
  module Reportir
6
8
  @@step = 0
7
9
  @@tests = [] # has to be array for front-end
8
10
 
9
11
  def upload_result_to_s3_as_static_site
10
- check_for_env_vars
12
+ return upload_everything_to_s3 if upload_to_s3_possible?
13
+ save_report_locally
14
+ end
15
+
16
+ def save_report_locally
17
+ copy_template_to_temp_dir
18
+ write_javascript_models
19
+ save_final_markup
20
+ puts "Upload to s3 not possible. Missing ENV vars. Report saved to #{local_root}"
21
+ end
22
+
23
+ def upload_everything_to_s3
11
24
  upload_template unless template_uploaded?
12
25
  clear_previous_results_from_s3
13
26
  save_final_markup
@@ -15,12 +28,24 @@ module Reportir
15
28
  upload_to_s3
16
29
  delete_tmp_files_for_this_test
17
30
  end
31
+
32
+ def s3_screenshot(method)
33
+ create_current_test #TODO: before-filter??
34
+ @@step = @@step+=1
35
+ image_name = "#{@@step}-#{method}"
36
+ local_path = "#{local_test_root}/#{image_name}.png"
37
+ FileUtils.mkdir_p(local_test_root) unless Dir.exists?(local_test_root)
38
+ @browser.screenshot.save(local_path)
39
+ current_test[:screenshots] << { name: image_name, src: "#{public_path_for_this_test}/#{image_name}.png" }
40
+ end
18
41
 
19
42
  private
20
43
 
44
+ def copy_template_to_temp_dir
45
+ FileUtils.cp_r(static_site_template_path+'/.', local_root)
46
+ end
47
+
21
48
  def upload_template
22
- puts ''
23
- puts ''
24
49
  puts '====== UPLOADING TEMPLATE ========='
25
50
  upload_directory(static_site_template_path, '')
26
51
  end
@@ -29,11 +54,27 @@ module Reportir
29
54
  bucket.object('index.html').exists?
30
55
  end
31
56
 
57
+ def upload_to_s3_possible?
58
+ check_for_env_vars
59
+ true
60
+ rescue Reportir::Error
61
+ return false
62
+ end
63
+
32
64
  def check_for_env_vars
33
- raise Reportir::Error.new 'Missing ENV AWS_DEFAULT_BUCKET' unless ENV['AWS_DEFAULT_BUCKET']
34
- raise Reportir::Error.new 'Missing ENV AWS_SECRET_ACCESS_KEY' unless ENV['AWS_SECRET_ACCESS_KEY']
35
- raise Reportir::Error.new 'Missing ENV AWS_ACCESS_KEY_ID' unless ENV['AWS_ACCESS_KEY_ID']
36
- raise Reportir::Error.new 'Missing ENV AWS_DEFAULT_REGION' unless ENV['AWS_DEFAULT_REGION']
65
+ raise Reportir::Error.new 'Missing ENV AWS_DEFAULT_BUCKET' unless aws_config[:bucket]
66
+ raise Reportir::Error.new 'Missing ENV AWS_SECRET_ACCESS_KEY' unless aws_config[:secret]
67
+ raise Reportir::Error.new 'Missing ENV AWS_ACCESS_KEY_ID' unless aws_config[:key]
68
+ raise Reportir::Error.new 'Missing ENV AWS_DEFAULT_REGION' unless aws_config[:region]
69
+ end
70
+
71
+ def aws_config
72
+ {
73
+ bucket: ENV['AWS_DEFAULT_BUCKET'],
74
+ secret: ENV['AWS_SECRET_ACCESS_KEY'],
75
+ key: ENV['AWS_ACCESS_KEY_ID'],
76
+ region: ENV['AWS_DEFAULT_REGION']
77
+ }
37
78
  end
38
79
 
39
80
  def delete_tmp_files_for_this_test
@@ -49,15 +90,15 @@ module Reportir
49
90
 
50
91
  def write_javascript_models
51
92
  string = %{
52
- var navigation = #{array_of_test_names.to_json};\n
53
- var tests = #{@@tests.to_json};\n
93
+ var navigation = #{array_of_test_names.to_json};
94
+ var tests = #{@@tests.to_json};
54
95
  }
55
96
  File.open(local_model_file_path, "w") { |f| f.write(string) }
56
97
  end
57
98
 
58
99
  def clear_previous_results_from_s3
59
100
  puts "deleting all previous test data from s3"
60
- ::Aws::S3::Bucket.new(ENV['AWS_DEFAULT_BUCKET']).delete_objects({
101
+ ::Aws::S3::Bucket.new(aws_config[:bucket]).delete_objects({
61
102
  delete: {
62
103
  objects: [{ key: "#{public_path_for_this_test}" }],
63
104
  quiet: true
@@ -66,42 +107,26 @@ module Reportir
66
107
  end
67
108
 
68
109
  def upload_to_s3
69
- puts ''
70
- puts ''
71
110
  puts '====== UPLOADING RESULTS ========='
72
111
  bucket.object('js/models.js').upload_file(local_model_file_path)
73
112
  puts "Uploading #{local_model_file_path} to /js/models.js"
74
113
  upload_directory(local_test_root, public_path_for_this_test)
75
- puts ''
76
- puts ''
77
114
  puts '====== S3 UPLOAD COMPLETE ========='
78
115
  puts 'URL: ' + static_site_url
79
116
  puts '==================================='
80
- puts ''
81
- puts ''
82
- end
83
-
84
- def s3_screenshot(method)
85
- create_current_test #TODO: before-filter??
86
- @@step = @@step+=1
87
- image_name = "#{@@step}-#{method}"
88
- local_path = "#{local_test_root}/#{image_name}.png"
89
- FileUtils.mkdir_p(local_test_root) unless Dir.exists?(local_test_root)
90
- @browser.screenshot.save(local_path)
91
- current_test[:screenshots] << { name: image_name, src: "#{public_path_for_this_test}/#{image_name}.png" }
92
117
  end
93
118
 
94
119
  def bucket
95
- @bucket ||= ::Aws::S3::Resource.new.bucket(ENV['AWS_DEFAULT_BUCKET'])
120
+ @bucket ||= ::Aws::S3::Resource.new.bucket(aws_config[:bucket])
96
121
  end
97
122
 
98
123
  def upload_directory(local, remote)
99
- ::S3Uploader.upload_directory(local, ENV['AWS_DEFAULT_BUCKET'], {
124
+ ::S3Uploader.upload_directory(local, aws_config[:bucket], {
100
125
  :destination_dir => remote,
101
126
  :threads => 5,
102
- s3_key: ENV['AWS_ACCESS_KEY_ID'],
103
- s3_secret: ENV['AWS_SECRET_ACCESS_KEY'],
104
- region: ENV['AWS_DEFAULT_REGION'] })
127
+ s3_key: aws_config[:key],
128
+ s3_secret: aws_config[:secret],
129
+ region: aws_config[:region] })
105
130
  end
106
131
 
107
132
  def static_site_template_path
@@ -123,7 +148,7 @@ module Reportir
123
148
  end
124
149
 
125
150
  def local_model_file_path
126
- "#{local_root}/models.js"
151
+ "#{local_root}/js/models.js"
127
152
  end
128
153
 
129
154
  def local_test_root
@@ -148,7 +173,7 @@ module Reportir
148
173
 
149
174
  def static_site_url
150
175
  # TODO: use aws-sdk for this.
151
- "http://#{ENV['AWS_DEFAULT_BUCKET']}.s3-website-#{ENV['AWS_DEFAULT_REGION']}.amazonaws.com"
176
+ "http://#{aws_config[:bucket]}.s3-website-#{aws_config[:region]}.amazonaws.com"
152
177
  end
153
178
 
154
179
  class Error < ::StandardError; end
@@ -1,3 +1,3 @@
1
1
  module Reportir
2
- VERSION = "0.3.3"
2
+ VERSION = "0.3.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reportir
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dean Shelton
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-08-10 00:00:00.000000000 Z
11
+ date: 2015-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler