turtle_hunter 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f9365dc057a040b08ffdeffa2688e526908c5d16
4
+ data.tar.gz: 35e84f42ff8fb7dc1fb5229752e8554ec6f3587c
5
+ SHA512:
6
+ metadata.gz: 586c721345bba12363b863b0cf32094255afebe226113d47bbeed48db5784fc2843bf570e472d8b507f4ab8291a9855b451f9b573f258329ca5ca7582ecc29b0
7
+ data.tar.gz: 4ca469d45f61182e8f36f632595211f842dc85e0bd520ae7c09795171cb3d142e50cdc51bd857ec176a49da290373da11421dc870f50ccfa110075b30cb6d015
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in turtle_hunter.gemspec
4
+ gemspec
@@ -0,0 +1,35 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ turtle_hunter (0.1.0)
5
+ rspec (~> 3.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ diff-lcs (1.3)
11
+ rake (10.5.0)
12
+ rspec (3.5.0)
13
+ rspec-core (~> 3.5.0)
14
+ rspec-expectations (~> 3.5.0)
15
+ rspec-mocks (~> 3.5.0)
16
+ rspec-core (3.5.4)
17
+ rspec-support (~> 3.5.0)
18
+ rspec-expectations (3.5.0)
19
+ diff-lcs (>= 1.2.0, < 2.0)
20
+ rspec-support (~> 3.5.0)
21
+ rspec-mocks (3.5.0)
22
+ diff-lcs (>= 1.2.0, < 2.0)
23
+ rspec-support (~> 3.5.0)
24
+ rspec-support (3.5.0)
25
+
26
+ PLATFORMS
27
+ ruby
28
+
29
+ DEPENDENCIES
30
+ bundler (~> 1.14)
31
+ rake (~> 10.0)
32
+ turtle_hunter!
33
+
34
+ BUNDLED WITH
35
+ 1.14.6
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Chris Woodrich
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,62 @@
1
+ # TurtleHunter
2
+
3
+ ![relevant gif](https://media.tenor.co/images/06d50ee7fa70b2fd636d1916a23063c7/tenor.gif)
4
+
5
+ Turtle Hunter (https://github.com/doximity/turtle_hunter) is a gem that enforces speed requirements on RSpec specs. Any spec that takes longer than its allowed threshold will be failed. Thresholds can be more lenient in CI. This reduces/eliminates the possibility that a spec passed on your local machine but failed in CI due to hardware/software/latency differences.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem "turtle_hunter", github: "doximity/turtle_hunter"
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install turtle_hunter
22
+
23
+ Set `FAIL_SLOW` to `true`, run specs.
24
+
25
+ ## Configuration
26
+
27
+ * `FAIL_SLOW`
28
+ * default: nil
29
+ * set this to `true` to invoke turtle hunter
30
+
31
+
32
+ The following `test` ENV vars can be setup for turtle_hunter, overriding turtle_hunter's defaults. All times are in milliseconds.
33
+
34
+ * `SKIP_FLAG`
35
+ * default: `:allowed_slow_test`
36
+ * The name of the flag you give specs you want turtle_hunter to skip over
37
+ * `MODEL_THRESHOLD`
38
+ * default: `2000`
39
+ * Threshold at which model specs will fail.
40
+ * `CONTROLLER_THRESHOLD`
41
+ * default: `5000`
42
+ * Threshold at which controller specs will fail.
43
+ * `FEATURE_THRESHOLD`
44
+ * default: `20000`
45
+ * Threshold at which feature specs will fail.
46
+ * `ELSE_THRESHOLD`
47
+ * default: `5000`
48
+ * Threshold at which all type other specs will fail.
49
+ * `LENIENCE_FLAG`
50
+ * default: `nil`
51
+ * If set to an environment variable that will be present in CI, ie `ENV['CIRCLECI']`, this flag will enable "lenient" turtle_hunting.
52
+ * `LENIENCE_LEVEL`
53
+ * default: `2.0`
54
+ * If enabled via `LENIENCE_FLAG`, the factor at which specs are leniently watched. A `LENIENCE_LEVEL` of 2 and `LENIENCE_FLAG` of `'CIRCLECI'` will enlarge the allowed threshold by 2x of all specs that run on CircleCI.## Contributing
55
+
56
+ Bug reports and pull requests are welcome on GitHub at https://github.com/doximity/turtle_hunter.
57
+
58
+
59
+ ## License
60
+
61
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
62
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "turtle_hunter"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,6 @@
1
+ require "turtle_hunter/version"
2
+ require "turtle_hunter/rspec_init"
3
+
4
+ module TurtleHunter
5
+ RspecInit.hunt
6
+ end
@@ -0,0 +1,11 @@
1
+ module DerivedConstants
2
+ SKIP_FLAG = :allowed_slow_test
3
+
4
+ MODEL_THRESHOLD = ENV.fetch("TH_MODEL_THRESHOLD", 2000).to_i
5
+ CONTROLLER_THRESHOLD = ENV.fetch("TH_CONTROLLER_THRESHOLD", 5000).to_i
6
+ FEATURE_THRESHOLD = ENV.fetch("TH_FEATURE_THRESHOLD", 20000).to_i
7
+ ELSE_THRESHOLD = ENV.fetch("TH_ELSE_THRESHOLD", 5000).to_i
8
+
9
+ LENIENCE_FLAG = ENV.fetch("TH_LENIENCE_FLAG", nil)
10
+ LENIENCE_LEVEL = ENV.fetch("TH_LENIENCE_LEVEL", 2).to_f
11
+ end
@@ -0,0 +1,11 @@
1
+ require "turtle_hunter/util"
2
+
3
+ class RspecInit
4
+ def self.hunt
5
+ RSpec.configure do |config|
6
+ config.after do |example|
7
+ Util.guard_against_slow_spec(example)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,53 @@
1
+ require_relative 'derived_constants'
2
+
3
+ module Util
4
+ include DerivedConstants
5
+
6
+ def self.guard_against_slow_spec(example)
7
+ @example = example
8
+ return unless passes_preconditions?
9
+
10
+ fail_after = set_defaults
11
+ started_at = example.metadata[:execution_result].started_at
12
+ now = Time.now
13
+ runtime = (now - started_at) * 1000
14
+
15
+ if runtime > fail_after
16
+ message = <<-HEREDOC
17
+ Expected spec to run within #{fail_after} milliseconds but it took #{runtime} milliseconds.
18
+ Lenience was set to `#{lenience?}`
19
+
20
+ If you want to disable turtle_hunter for this run, set `ENV["FAIL_SLOW"]=false` while you run specs.
21
+
22
+ If you want to skip turtle_hunter for this spec, add `#{SKIP_FLAG}: true` to the example.
23
+ HEREDOC
24
+ fail message
25
+ end
26
+ end
27
+
28
+ private
29
+
30
+ def self.passes_preconditions?
31
+ return if @example.nil?
32
+ return if @example.metadata[SKIP_FLAG.to_sym] == true
33
+ return if ENV["FAIL_SLOW"] != "true"
34
+ true
35
+ end
36
+
37
+ def self.set_defaults
38
+ spec_type = @example.metadata[:type]
39
+ time = case spec_type
40
+ when :model then MODEL_THRESHOLD
41
+ when :controller then CONTROLLER_THRESHOLD
42
+ when :feature then FEATURE_THRESHOLD
43
+ else ELSE_THRESHOLD
44
+ end
45
+
46
+ time *= LENIENCE_LEVEL.to_f if lenience?
47
+ time
48
+ end
49
+
50
+ def self.lenience?
51
+ LENIENCE_FLAG.present? && ENV[LENIENCE_FLAG].present?
52
+ end
53
+ end
@@ -0,0 +1,3 @@
1
+ module TurtleHunter
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'turtle_hunter/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "turtle_hunter"
8
+ spec.version = TurtleHunter::VERSION
9
+ spec.authors = ["Chris Woodrich"]
10
+ spec.email = ["cwoodrich@doximity.com"]
11
+
12
+ spec.summary = %q{Fails slow specs}
13
+ spec.description = %q{Fails slow specs}
14
+ spec.homepage = "https://github.com/doximity/turtle_hunter"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "gemfury"
25
+ spec.add_development_dependency "bundler", "~> 1.14"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_dependency "rspec", "~> 3.0"
28
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: turtle_hunter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Chris Woodrich
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-05-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: gemfury
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
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: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.14'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.14'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.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: '3.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description: Fails slow specs
70
+ email:
71
+ - cwoodrich@doximity.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - Gemfile
77
+ - Gemfile.lock
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - bin/console
82
+ - bin/setup
83
+ - lib/turtle_hunter.rb
84
+ - lib/turtle_hunter/derived_constants.rb
85
+ - lib/turtle_hunter/rspec_init.rb
86
+ - lib/turtle_hunter/util.rb
87
+ - lib/turtle_hunter/version.rb
88
+ - turtle_hunter.gemspec
89
+ homepage: https://github.com/doximity/turtle_hunter
90
+ licenses:
91
+ - MIT
92
+ metadata: {}
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 2.4.5.1
110
+ signing_key:
111
+ specification_version: 4
112
+ summary: Fails slow specs
113
+ test_files: []