rscout 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/bin/rscout +8 -1
  3. data/lib/rscout/version.rb +1 -1
  4. data/lib/rscout.rb +122 -110
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 09a165d2b395eb9e4db65ab07c24e2ec29d3d9e8
4
- data.tar.gz: 8b5075d608401440fd30e2cb466cb47556779d0c
3
+ metadata.gz: 45f571e06d7a70225b4405cf9c83e7f89b5b5acf
4
+ data.tar.gz: a0002b5ccd2e9f0e2d7219d3e224b3ee236a8180
5
5
  SHA512:
6
- metadata.gz: 29c8f182a81acdbaf51840142d627735bc161e627f432e4fd9c161c7d3c1172c1c09289174ba778e04c2b5d837abe97266f2045e73c9ca43f8f8fb4ac8ea4dab
7
- data.tar.gz: 09a3f88d2d69a5c4cc07a619598fa49b06593abfef35dbdd13ea3d7582de257935bfaf704dc02f131feb7d008cd5809284aa27e7d63e8c39871cd4f4c21d15e3
6
+ metadata.gz: 320b3c8f5fa0ec3e76e94492d24f84183705d8835a5ca8f08457e91ddac4ebb71fa655f0bbd77aa67beb1f6d059a71197156cf0b93db7c54ffefd4346c238ad6
7
+ data.tar.gz: bf383251be2a6da418f0247087f1fab031040e0d7c7e448adff283215a41c2ea9f3f00568e93253dd3ae41b5fa2e5f217049ae8848f750dc8abed7ddf79a1503
data/bin/rscout CHANGED
@@ -3,6 +3,7 @@
3
3
  require 'rubygems'
4
4
  require 'thor'
5
5
  require 'dotenv'
6
+ require 'logger'
6
7
  require 'rscout'
7
8
  require 'mail'
8
9
 
@@ -14,6 +15,8 @@ class RscoutCommand < Thor
14
15
  method_option :verbose, type: :boolean, aliases: [:v], default: false, lazy_default: true, desc: 'Show verbose messaging.'
15
16
  def test
16
17
  Mail.defaults do
18
+ from ENV['RSCOUT_EMAIL']
19
+
17
20
  smtp = {}
18
21
 
19
22
  smtp[:user_name] = ENV['SMTP_USERNAME'] if ENV['SMTP_USERNAME']
@@ -27,7 +30,11 @@ class RscoutCommand < Thor
27
30
  delivery_method :smtp, smtp
28
31
  end
29
32
 
30
- RScout.run_suite Dir.pwd, options.env
33
+ RScout.options[:logger] = Logger.new(ENV['RSCOUT_LOG']) if ENV['RSCOUT_LOG']
34
+ RScout.options[:env] = options.env
35
+ RScout.options[:verbose] = options.verbose
36
+
37
+ RScout.run_suite Dir.pwd
31
38
  end
32
39
  end
33
40
 
@@ -1,3 +1,3 @@
1
1
  module Rscout
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/rscout.rb CHANGED
@@ -13,136 +13,148 @@ require 'rspec/core/formatters/documentation_formatter'
13
13
  require 'rspec/core/formatters/html_formatter'
14
14
 
15
15
  module RScout
16
- def self.logger
17
- @@LOGGER ||= begin
18
- logger = Logger.new STDOUT
19
- logger.level = Logger::ERROR
20
- logger
16
+ DEFAULT_LOGGER = Logger.new(STDOUT)
17
+ DEFAULT_OPTIONS = {
18
+ logger: DEFAULT_LOGGER,
19
+ verbose: false,
20
+ env: 'development'
21
+ }
22
+
23
+ class << self
24
+ def options
25
+ @@options ||= DEFAULT_OPTIONS.clone
21
26
  end
22
- end
23
-
24
- def self.run_suite(dir, env)
25
- verbose = false
26
- gemfile = File.join(dir, 'Gemfile')
27
- configfile = File.join(dir, 'config', 'rscout.yml')
28
-
29
- Bundler.with_clean_env do
30
- Dir.chdir(dir) do
31
- yaml = Hashie::Mash.new(YAML.load_file configfile)
32
- config = yaml[env]
33
-
34
- output = Hashie::Mash.new({
35
- txt: StringIO.new,
36
- html: StringIO.new,
37
- json: StringIO.new,
38
- stdout: nil,
39
- results: nil,
40
- error: Hashie::Mash.new({backtrace:[], message:nil})
41
- })
42
-
43
- failed = false
44
- begin
45
- html_formatter = RSpec::Core::Formatters::HtmlFormatter.new output.html
46
- txt_formatter = RSpec::Core::Formatters::DocumentationFormatter.new output.txt
47
- json_formatter = RSpec::Core::Formatters::JsonFormatter.new output.json
48
-
49
- reporter = RSpec::Core::Reporter.new(json_formatter, txt_formatter, html_formatter)
50
27
 
51
- rspec = RSpec.configuration
52
- rspec.instance_variable_set(:@reporter, reporter)
28
+ def log(msg)
29
+ options[:logger].add(options[:severity]) { msg }
30
+ end
53
31
 
54
- tests = Dir.glob File.join(dir, 'spec/**/*_spec.rb')
32
+ def logger
33
+ options[:logger]
34
+ end
55
35
 
56
- rspec_task = lambda { RSpec::Core::Runner.run tests }
36
+ def env
37
+ options[:env]
38
+ end
57
39
 
58
- if verbose
59
- rspec_task.call
60
- else
61
- output.stdout = RScout.capture_stdout &rspec_task
40
+ def run_suite(dir)
41
+ verbose = options[:verbose]
42
+ gemfile = File.join(dir, 'Gemfile')
43
+ configfile = File.join(dir, 'config', 'rscout.yml')
44
+
45
+ Bundler.with_clean_env do
46
+ Dir.chdir(dir) do
47
+ yaml = Hashie::Mash.new(YAML.load_file configfile)
48
+ config = yaml[env]
49
+
50
+ output = Hashie::Mash.new({
51
+ txt: StringIO.new,
52
+ html: StringIO.new,
53
+ json: StringIO.new,
54
+ stdout: nil,
55
+ results: nil,
56
+ error: Hashie::Mash.new({backtrace:[], message:nil})
57
+ })
58
+
59
+ failed = false
60
+ begin
61
+ html_formatter = RSpec::Core::Formatters::HtmlFormatter.new output.html
62
+ txt_formatter = RSpec::Core::Formatters::DocumentationFormatter.new output.txt
63
+ json_formatter = RSpec::Core::Formatters::JsonFormatter.new output.json
64
+
65
+ reporter = RSpec::Core::Reporter.new(json_formatter, txt_formatter, html_formatter)
66
+
67
+ rspec = RSpec.configuration
68
+ rspec.instance_variable_set(:@reporter, reporter)
69
+
70
+ tests = Dir.glob File.join(dir, 'spec/**/*_spec.rb')
71
+
72
+ rspec_task = lambda { RSpec::Core::Runner.run tests }
73
+
74
+ if verbose
75
+ rspec_task.call
76
+ else
77
+ output.stdout = capture_stdout &rspec_task
78
+ end
79
+
80
+ output.results = json_formatter.output_hash
81
+
82
+ failed = output.results[:summary][:failure_count] > 0
83
+ failure_count = output.results[:summary][:failure_count].to_s
84
+ rescue => e
85
+ failed = true
86
+ logger.error "Exception encountered while running RSpec: #{e.message}"
87
+ logger.error e.backtrace
88
+ output.error = e
89
+ ensure
90
+ output.txt.close unless output.txt.closed?
91
+ output.html.close unless output.html.closed?
92
+ output.json.close unless output.json.closed?
62
93
  end
63
94
 
64
- output.results = json_formatter.output_hash
95
+ if failed
96
+ logger.info "Tests failed."
97
+ send_failure_notifications config, env, output
98
+ end
65
99
 
66
- failed = output.results[:summary][:failure_count] > 0
67
- failure_count = output.results[:summary][:failure_count].to_s
68
- rescue => e
69
- failed = true
70
- RScout.logger.error "Exception encountered while running RSpec: #{e.message}"
71
- RScout.logger.error e.backtrace
72
- output.error = e
73
- ensure
74
- output.txt.close unless output.txt.closed?
75
- output.html.close unless output.html.closed?
76
- output.json.close unless output.json.closed?
100
+ failed
77
101
  end
102
+ end
78
103
 
79
- if failed
80
- RScout.logger.info "Tests failed."
81
- RScout.send_failure_notifications config, env, output
82
- end
104
+ def send_failure_notifications(config, env, output)
105
+ email_body = [output.txt.string, output.error.backtrace.join("\n")].join("\n")
106
+ if config.email_enabled && config.email
107
+ logger.info "Sending emails alert to #{config.email}"
108
+ begin
109
+ mail = Mail.new do
110
+ to config.email
111
+ subject "RScout Alert: Tests failing on #{config.name.to_s.humanize.titleize} (#{env})"
112
+ add_file filename: 'results.html', content: output.html.string
83
113
 
84
- failed
85
- end
86
- end
87
- end
114
+ header["X-Priority"] = "1 (Highest)"
115
+ header["X-MSMail-Priority"] = "High"
116
+ header["Importance"] = "High"
88
117
 
89
- def self.send_failure_notifications(config, env, output)
90
- email_body = [output.txt.string, output.error.backtrace.join("\n")].join("\n")
91
- if config.email_enabled && config.email
92
- RScout.logger.info "Sending emails alert to #{config.email}"
93
- begin
94
- mail = Mail.new do
95
- from 'Scout <platform+scout@evertrue.com>'
96
- to config.email
97
- subject "Scout Alert: Tests failing on #{config.name.to_s.humanize.titleize} (#{env})"
98
- add_file filename: 'results.html', content: output.html.string
99
-
100
- header["X-Priority"] = "1 (Highest)"
101
- header["X-MSMail-Priority"] = "High"
102
- header["Importance"] = "High"
103
-
104
- text_part do
105
- body email_body
118
+ text_part do
119
+ body email_body
120
+ end
106
121
  end
107
- end
108
122
 
109
- mail.deliver!
110
- rescue => e
111
- RScout.logger.error "Failed to send email alert!"
112
- RScout.logger.error e.message + "\n " + e.backtrace.join("\n ")
123
+ mail.deliver!
124
+ rescue => e
125
+ logger.error "Failed to send email alert!"
126
+ logger.error e.message + "\n " + e.backtrace.join("\n ")
127
+ end
113
128
  end
114
- end
115
129
 
116
- if config.pagerduty_enabled && config.pagerduty_service_key
117
- RScout.logger.info "Triggering PagerDuty incident to #{config.pagerduty_service_key}"
118
- begin
119
- if config.pagerduty_service_key.match(/@(.*)pagerduty.com$/)
120
- mail = Mail.new do
121
- from 'RScout <platform+rscout@evertrue.com>'
122
- to config.pagerduty_service_key
123
- subject "DOWN alert: RScout tests failing on #{config.name.to_s.humanize.titleize} (#{env})"
124
- body email_body
130
+ if config.pagerduty_enabled && config.pagerduty_service_key
131
+ logger.info "Triggering PagerDuty incident to #{config.pagerduty_service_key}"
132
+ begin
133
+ if config.pagerduty_service_key.match(/@(.*)pagerduty.com$/)
134
+ mail = Mail.new do
135
+ to config.pagerduty_service_key
136
+ subject "DOWN alert: RScout tests failing on #{config.name.to_s.humanize.titleize} (#{env})"
137
+ body email_body
138
+ end
139
+
140
+ mail.deliver!
141
+ else
142
+ p = Pagerduty.new config.pagerduty_service_key, ['scout', env].join('_')
143
+ incident = p.trigger 'RScout tests failing!', output.results
125
144
  end
126
-
127
- mail.deliver!
128
- else
129
- p = Pagerduty.new config.pagerduty_service_key, ['scout', env].join('_')
130
- incident = p.trigger 'RScout tests failing!', output.results
145
+ rescue => e
146
+ logger.error "Failed to send PagerDuty alert!"
147
+ logger.error e.message + "\n " + e.backtrace.join("\n ")
131
148
  end
132
- rescue => e
133
- RScout.logger.error "Failed to send PagerDuty alert!"
134
- RScout.logger.error e.message + "\n " + e.backtrace.join("\n ")
135
149
  end
136
150
  end
137
- end
138
151
 
139
- def self.capture_stdout(&block)
140
- RScout.logger.debug "Starting stdout capture…"
141
- previous_stdout, $stdout = $stdout, StringIO.new
142
- yield
143
- $stdout.string
144
- ensure
145
- $stdout = previous_stdout
146
- RScout.logger.debug "Ended stdout capture."
152
+ def capture_stdout(&block)
153
+ previous_stdout, $stdout = $stdout, StringIO.new
154
+ yield
155
+ $stdout.string
156
+ ensure
157
+ $stdout = previous_stdout
158
+ end
147
159
  end
148
160
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rscout
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Hammond (@andrhamm)
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-09 00:00:00.000000000 Z
11
+ date: 2014-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json