insanity 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: 214015507baf0c53a4449036bd5f0f570746f615
4
+ data.tar.gz: ae74f8c92eef6526d71c4fd24e6f03e8424e4dc7
5
+ SHA512:
6
+ metadata.gz: 290d36e718a5f81c5f477bb7fc16449a1e40e08b1d56cc25088eea78a7dc1a74543d5a824c37ea57e68800e60cef0de5057b296c8ec3ae97a5dfbe7b7193b138
7
+ data.tar.gz: 8cec5b7c2e0655e3a6b5f1d70e1cf5a3e2f10c3b6a647382c9b23cb3773d6c1aa337fff050d54a4da59352de78ae61d1e5e86e3d8d93c45c069ed9e3703080ad
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.0
4
+ before_install: gem install bundler -v 1.11.2
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in insanity.gemspec
4
+ gemspec
5
+ gem 'aruba', '~> 0.14.1'
@@ -0,0 +1,46 @@
1
+ # Insanity
2
+
3
+ Run a command repeatedly to check for differences. Handy for discovering flaky tests or verifying a change doesn't lead to instability.
4
+
5
+ Output currently includes a summary of the exit statuses.
6
+
7
+ ## Usage
8
+
9
+ Running the following:
10
+
11
+ ```
12
+ insanity 'rspec ./spec/my_flaky_spec.rb' -i 10
13
+ ```
14
+
15
+ Will run the command 10 times and output something like:
16
+
17
+ ```
18
+ ..........
19
+
20
+ 10 iterations complete.
21
+
22
+ Status 0 | 8 times
23
+ Status 1 | 2 times
24
+ ```
25
+
26
+ ## Installation
27
+
28
+ Install the gem directly:
29
+
30
+ ```
31
+ gem install insanity
32
+ ```
33
+
34
+ Don't forget to run `rebenv rehash` if you use Rbenv.
35
+
36
+ Alternatively add the following to your Gemfile:
37
+
38
+ ```
39
+ gem 'insanity'
40
+ ```
41
+
42
+ And run `bundle install`.
43
+
44
+ ## Development notes
45
+
46
+ - `rake` runs the [Aruba](https://github.com/cucumber/aruba/) and [RSpec](http://rspec.info/) tests
@@ -0,0 +1,11 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+ require "cucumber/rake/task"
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ Cucumber::Rake::Task.new(:features) do |t|
8
+ t.cucumber_opts = "features --format pretty"
9
+ end
10
+
11
+ task :default => [:spec, :features]
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "insanity"
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
@@ -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,7 @@
1
+ require 'rspec'
2
+
3
+ describe 'Flaky spec' do
4
+ it 'passes, sometimes' do
5
+ expect([1, 1, 2].sample).to eq 1
6
+ end
7
+ end
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'insanity'
4
+ require 'optparse'
5
+
6
+ options = {iterations: 100}
7
+
8
+ parser = OptionParser.new do|opts|
9
+ opts.banner = "Usage: insanity [options] 'your command'"
10
+
11
+ opts.on('-i N', '--iterations N', OptionParser::DecimalInteger, 'Number of iterations') do |iterations|
12
+ options[:iterations] = iterations
13
+ end
14
+
15
+ opts.on('-h', '--help', 'Displays Help') do
16
+ puts opts
17
+ exit
18
+ end
19
+ end
20
+
21
+ parser.parse!
22
+ command = ARGF.argv[0]
23
+
24
+ Insanity::Runner
25
+ .new(command: command, iterations: options[:iterations])
26
+ .commence!
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'insanity/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "insanity"
8
+ spec.version = Insanity::VERSION
9
+ spec.authors = ["odlp"]
10
+ spec.email = ["oliverp@gmail.com"]
11
+
12
+ spec.summary = "Run a command repeatedly to check for differences."
13
+ spec.description = "Handy for discovering flaky tests or verifying a change doesn't lead to instability."
14
+ spec.homepage = "https://github.com/odlp/insanity"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.11"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec", "~> 3.0"
24
+ spec.add_development_dependency "aruba", "~> 0.14"
25
+ spec.add_development_dependency "cucumber", "~> 2.3", ">= 2.3.3"
26
+ end
@@ -0,0 +1,37 @@
1
+ require 'insanity/version'
2
+ require 'insanity/printer'
3
+ require 'open3'
4
+
5
+ module Insanity
6
+ class Runner
7
+
8
+ def initialize(command:, iterations:, printer: Printer.new)
9
+ @command = command
10
+ @iterations = iterations
11
+ @printer = printer
12
+ @results = []
13
+ end
14
+
15
+ def commence!
16
+ iterations.times do |i|
17
+ _, status = Open3.capture2e(command)
18
+ add_result(status)
19
+ printer.update_progress(status)
20
+ end
21
+
22
+ printer.print_summary(iterations, results)
23
+ end
24
+
25
+ Result = Struct.new(:status)
26
+
27
+ private
28
+
29
+ attr_reader :command, :iterations, :printer
30
+ attr_accessor :results
31
+
32
+ def add_result(status)
33
+ results << Result.new(status)
34
+ end
35
+
36
+ end
37
+ end
@@ -0,0 +1,35 @@
1
+ module Insanity
2
+ class Printer
3
+ def update_progress(status)
4
+ if status.success?
5
+ print green_dot
6
+ else
7
+ print red_dot
8
+ end
9
+ end
10
+
11
+ def print_summary(iterations, results)
12
+ puts "\n\n#{iterations} iterations complete.\n\n"
13
+ print_count_by_exit_code(results)
14
+ end
15
+
16
+ private
17
+
18
+ def red_dot
19
+ "\e[31m.\e[0m".freeze
20
+ end
21
+
22
+ def green_dot
23
+ "\e[32m.\e[0m".freeze
24
+ end
25
+
26
+ def print_count_by_exit_code(results)
27
+ count_by_status = Hash.new { 0 }
28
+ results.each {|r| count_by_status[r.status.exitstatus] += 1 }
29
+
30
+ count_by_status
31
+ .sort { |a,b| b[1] <=> a[1] }
32
+ .each { |i| puts "Status #{i[0]}\t| #{i[1]} times" }
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,3 @@
1
+ module Insanity
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,135 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: insanity
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - odlp
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-03-28 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.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
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: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: aruba
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.14'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.14'
69
+ - !ruby/object:Gem::Dependency
70
+ name: cucumber
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '2.3'
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: 2.3.3
79
+ type: :development
80
+ prerelease: false
81
+ version_requirements: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - "~>"
84
+ - !ruby/object:Gem::Version
85
+ version: '2.3'
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: 2.3.3
89
+ description: Handy for discovering flaky tests or verifying a change doesn't lead
90
+ to instability.
91
+ email:
92
+ - oliverp@gmail.com
93
+ executables:
94
+ - insanity
95
+ extensions: []
96
+ extra_rdoc_files: []
97
+ files:
98
+ - ".gitignore"
99
+ - ".rspec"
100
+ - ".travis.yml"
101
+ - Gemfile
102
+ - README.md
103
+ - Rakefile
104
+ - bin/console
105
+ - bin/setup
106
+ - examples/flaky_spec.rb
107
+ - exe/insanity
108
+ - insanity.gemspec
109
+ - lib/insanity.rb
110
+ - lib/insanity/printer.rb
111
+ - lib/insanity/version.rb
112
+ homepage: https://github.com/odlp/insanity
113
+ licenses: []
114
+ metadata: {}
115
+ post_install_message:
116
+ rdoc_options: []
117
+ require_paths:
118
+ - lib
119
+ required_ruby_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ required_rubygems_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ requirements: []
130
+ rubyforge_project:
131
+ rubygems_version: 2.5.1
132
+ signing_key:
133
+ specification_version: 4
134
+ summary: Run a command repeatedly to check for differences.
135
+ test_files: []