rscout 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0a199aefeb4ee4e5c194b886370a2559f00b748f
4
+ data.tar.gz: 501ec0f44aca8336752435ce11cadb26b5c651f0
5
+ SHA512:
6
+ metadata.gz: 7608d23bf7aabcd9020e6368783429950bed01a6ffe0c5c6f45d3e4d306667bf9370c39d7bc8dc68044ea0dc0a21d341ba5cea8dc418dae04f131ae0226dcefe
7
+ data.tar.gz: c3182dbb2052068285f4e000702e39aaad7545528cc88e77759e608a842d6a269bace44e470cc3037230072e017acb356d9c883be1946a848eb85c6d67a752d0
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .env
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rscout.gemspec
4
+ gem 'byebug'
5
+
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Andrew Hammond
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,88 @@
1
+ Run integration tests on your live APIs. Write tests in RSpec and get email and/or PagerDuty notifications when tests are failing.
2
+
3
+ At EverTrue, we run a dedicated server we call Scout, which has many projects' RScout tests deployed to it. Our Scout server is a Sinatra web app which has a REST API which leverages RScout to run the many test suites for our various REST APIs.
4
+
5
+ ## Features
6
+
7
+ * Sends email notifications with details of failing tests
8
+ * Sends PagerDuty notifications
9
+ * YAML configuration supports multiple environments
10
+ * Simple command-line interface
11
+
12
+ ## Installation
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ gem 'rscout'
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install rscout
25
+
26
+ ## Configuration
27
+
28
+ Recommended directory structure:
29
+
30
+ ```
31
+ myproject
32
+ | rscout_tests
33
+ | | config
34
+ | | | rscout.yml
35
+ | | spec
36
+ | | | myfirsttest_spec.rb
37
+ | | | spec_helper.rb
38
+ | | Gemfile
39
+ ```
40
+
41
+ We keep our RScout tests separate from our main tests, for consistency accross all our projects. You'll be running the `rscout` command from the `rscout_tests` directory (name not important) and the relation of the `Gemfile`, `config/rscout.yml` and `spec/` are important.
42
+
43
+ Example `rscout.yml` file:
44
+
45
+ ```
46
+ default: &default
47
+ name: myproject
48
+ pagerduty_id: PM3WJQN
49
+ pagerduty_service_key: my-api@myteam.pagerduty.com
50
+ pagerduty_enabled: false
51
+ email: andrew@example.com
52
+ email_enabled: true
53
+
54
+ development:
55
+ <<: *default
56
+
57
+ staging:
58
+ <<: *default
59
+
60
+ production:
61
+ <<: *default
62
+ pagerduty_enabled: true
63
+ ```
64
+
65
+ Note: For PagerDuty configurations, you should use their REST API to determine the values for `pagerduty_id` and `pagerduty_service_key`. Only one is necessary. If your PagerDuty service is setup with a "service_key" then RScout will send the notification to that email address since their REST API does not support REST notifications for these service configurations. For us, this was based on if the given service was integrated with Pingdom.
66
+
67
+ ## Usage
68
+
69
+ The `rscout` command should be run from the directory where you keep your RScout test Gemfile. See Configuration section above.
70
+
71
+ $ cd myproject
72
+ $ SMTP_ADDRESS=localhost SMTP_PORT=1025 bundle exec rscout test --env production`
73
+
74
+ Supply the rscout command with the necessary SMTP ENV keys if applicable.
75
+
76
+ ## TODO
77
+
78
+ * Abstract notification modules, support other services
79
+ * Pingdom integration
80
+ * Slack/HipChat integration
81
+
82
+ ## Contributing
83
+
84
+ 1. Fork it
85
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
86
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
87
+ 4. Push to the branch (`git push origin my-new-feature`)
88
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/rscout ADDED
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'thor'
5
+ require 'dotenv'
6
+ require 'rscout'
7
+ require 'mail'
8
+
9
+ Dotenv.load
10
+
11
+ class RscoutCommand < Thor
12
+ desc 'test', 'Run tests'
13
+ # method_option :suite, required: :true, type: :string, aliases: [:s], desc: 'The name of the test suite to run.'
14
+ method_option :env, required: :true, type: :string, aliases: [:e], desc: 'The environment to run the test suite on.'
15
+ method_option :verbose, type: :boolean, aliases: [:v], default: false, lazy_default: true, desc: 'Show verbose messaging.'
16
+ def test
17
+ Mail.defaults do
18
+ smtp = {}
19
+
20
+ smtp[:user_name] = ENV['SMTP_USERNAME'] if ENV['SMTP_USERNAME']
21
+ smtp[:password] = ENV['SMTP_PASSWORD'] if ENV['SMTP_PASSWORD']
22
+ smtp[:domain] = ENV['SMTP_DOMAIN'] if ENV['SMTP_DOMAIN']
23
+ smtp[:address] = ENV['SMTP_ADDRESS'] if ENV['SMTP_ADDRESS']
24
+ smtp[:port] = ENV['SMTP_PORT'] if ENV['SMTP_PORT']
25
+ smtp[:authentication] = ENV['SMTP_AUTHENTICATION'] if ENV['SMTP_AUTHENTICATION']
26
+ smtp[:enable_starttls_auto] = ENV['SMTP_ENABLESTARTTLS_AUTO'] if ENV['SMTP_ENABLESTARTTLS_AUTO']
27
+
28
+ delivery_method :smtp, smtp
29
+ end
30
+
31
+ RScout.run_suite Dir.pwd, options.env
32
+ end
33
+ end
34
+
35
+ RscoutCommand.start
data/lib/rscout.rb ADDED
@@ -0,0 +1,148 @@
1
+ require 'rscout/version'
2
+ require 'yaml'
3
+ require 'hashie'
4
+ require 'pagerduty'
5
+ require 'mail'
6
+ require 'logger'
7
+ require 'active_support/core_ext/string'
8
+
9
+ require 'rspec'
10
+ require 'rspec/core'
11
+ require 'rspec/core/formatters/json_formatter'
12
+ require 'rspec/core/formatters/documentation_formatter'
13
+ require 'rspec/core/formatters/html_formatter'
14
+
15
+ module RScout
16
+ def self.logger
17
+ @@LOGGER ||= begin
18
+ logger = Logger.new STDOUT
19
+ logger.level = Logger::ERROR
20
+ logger
21
+ 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
+
51
+ rspec = RSpec.configuration
52
+ rspec.instance_variable_set(:@reporter, reporter)
53
+
54
+ tests = Dir.glob File.join(dir, 'spec/**/*_spec.rb')
55
+
56
+ rspec_task = lambda { RSpec::Core::Runner.run tests }
57
+
58
+ if verbose
59
+ rspec_task.call
60
+ else
61
+ output.stdout = RScout.capture_stdout &rspec_task
62
+ end
63
+
64
+ output.results = json_formatter.output_hash
65
+
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?
77
+ end
78
+
79
+ if failed
80
+ RScout.logger.info "Tests failed."
81
+ RScout.send_failure_notifications config, env, output
82
+ end
83
+
84
+ failed
85
+ end
86
+ end
87
+ end
88
+
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
106
+ end
107
+ end
108
+
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 ")
113
+ end
114
+ end
115
+
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
125
+ 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
131
+ 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
+ end
136
+ end
137
+ end
138
+
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."
147
+ end
148
+ end
@@ -0,0 +1,3 @@
1
+ module Rscout
2
+ VERSION = "0.0.1"
3
+ end
data/rscout.gemspec ADDED
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rscout/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rscout"
8
+ spec.version = Rscout::VERSION
9
+ spec.authors = ["Andrew Hammond (@andrhamm)"]
10
+ spec.email = ["andrew@tremorlab.com"]
11
+ spec.description = %q{Integration tests with Rspec}
12
+ spec.summary = %q{Integration tests with Rspec}
13
+ spec.homepage = "https://github.com/andrhamm"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency 'json'
22
+ spec.add_dependency 'dotenv-rails'
23
+ spec.add_dependency 'thor'
24
+ spec.add_dependency 'rspec', '~> 2.14.1'
25
+ spec.add_dependency 'dotenv'
26
+ spec.add_dependency 'hashie'
27
+ spec.add_dependency 'pagerduty'
28
+ spec.add_dependency 'syntax'
29
+ spec.add_dependency 'mail'
30
+ spec.add_dependency 'activesupport', '~> 4.0', '>= 4.0.2'
31
+
32
+ spec.add_development_dependency "byebug"
33
+ spec.add_development_dependency "bundler", "~> 1.3"
34
+ spec.add_development_dependency "rake"
35
+ end
metadata ADDED
@@ -0,0 +1,243 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rscout
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Andrew Hammond (@andrhamm)
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: json
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: dotenv-rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: thor
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
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: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 2.14.1
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 2.14.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: dotenv
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: hashie
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: pagerduty
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
+ - !ruby/object:Gem::Dependency
112
+ name: syntax
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: mail
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: activesupport
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '4.0'
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ version: 4.0.2
149
+ type: :runtime
150
+ prerelease: false
151
+ version_requirements: !ruby/object:Gem::Requirement
152
+ requirements:
153
+ - - "~>"
154
+ - !ruby/object:Gem::Version
155
+ version: '4.0'
156
+ - - ">="
157
+ - !ruby/object:Gem::Version
158
+ version: 4.0.2
159
+ - !ruby/object:Gem::Dependency
160
+ name: byebug
161
+ requirement: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - ">="
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ type: :development
167
+ prerelease: false
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ requirements:
170
+ - - ">="
171
+ - !ruby/object:Gem::Version
172
+ version: '0'
173
+ - !ruby/object:Gem::Dependency
174
+ name: bundler
175
+ requirement: !ruby/object:Gem::Requirement
176
+ requirements:
177
+ - - "~>"
178
+ - !ruby/object:Gem::Version
179
+ version: '1.3'
180
+ type: :development
181
+ prerelease: false
182
+ version_requirements: !ruby/object:Gem::Requirement
183
+ requirements:
184
+ - - "~>"
185
+ - !ruby/object:Gem::Version
186
+ version: '1.3'
187
+ - !ruby/object:Gem::Dependency
188
+ name: rake
189
+ requirement: !ruby/object:Gem::Requirement
190
+ requirements:
191
+ - - ">="
192
+ - !ruby/object:Gem::Version
193
+ version: '0'
194
+ type: :development
195
+ prerelease: false
196
+ version_requirements: !ruby/object:Gem::Requirement
197
+ requirements:
198
+ - - ">="
199
+ - !ruby/object:Gem::Version
200
+ version: '0'
201
+ description: Integration tests with Rspec
202
+ email:
203
+ - andrew@tremorlab.com
204
+ executables:
205
+ - rscout
206
+ extensions: []
207
+ extra_rdoc_files: []
208
+ files:
209
+ - ".gitignore"
210
+ - Gemfile
211
+ - LICENSE.txt
212
+ - README.md
213
+ - Rakefile
214
+ - bin/rscout
215
+ - lib/rscout.rb
216
+ - lib/rscout/version.rb
217
+ - rscout.gemspec
218
+ homepage: https://github.com/andrhamm
219
+ licenses:
220
+ - MIT
221
+ metadata: {}
222
+ post_install_message:
223
+ rdoc_options: []
224
+ require_paths:
225
+ - lib
226
+ required_ruby_version: !ruby/object:Gem::Requirement
227
+ requirements:
228
+ - - ">="
229
+ - !ruby/object:Gem::Version
230
+ version: '0'
231
+ required_rubygems_version: !ruby/object:Gem::Requirement
232
+ requirements:
233
+ - - ">="
234
+ - !ruby/object:Gem::Version
235
+ version: '0'
236
+ requirements: []
237
+ rubyforge_project:
238
+ rubygems_version: 2.2.0
239
+ signing_key:
240
+ specification_version: 4
241
+ summary: Integration tests with Rspec
242
+ test_files: []
243
+ has_rdoc: