quarantini 0.1.0

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
+ SHA256:
3
+ metadata.gz: 6ec96ce7df969c893d2b8d8fae9c051894b7a298d80c0b59f9f1a88c31ec0d6d
4
+ data.tar.gz: a34f4253edeae3bbf24d6ee505493f47fff2fa2bb657f9cae8f9d126dbb53d0a
5
+ SHA512:
6
+ metadata.gz: b5959da1f23d40469c41972f95d96ac618e4306c71a6c3ca720dc774f251261f4247204d3e7e10e1366180463dd15a97ea69f11f5264dfaba74314153133b34c
7
+ data.tar.gz: 94a604e4a6812707affd9b434ffdbdd3e1f1f9e90d024e0d750bb5405ce23ac48e39cb119105b28a1ebadb4d33e7a9af01d03a2fe86ff6e938a57013e5d97d5c
data/.rubocop.yml ADDED
@@ -0,0 +1,35 @@
1
+ require:
2
+ - rubocop-performance
3
+ - rubocop-rake
4
+ - rubocop-rspec
5
+
6
+ inherit_from: .rubocop_todo.yml
7
+
8
+ AllCops:
9
+ TargetRubyVersion: 3.1
10
+ NewCops: enable
11
+
12
+ Gemspec/DevelopmentDependencies:
13
+ EnforcedStyle: gemspec
14
+
15
+ Style/Documentation:
16
+ Enabled: false
17
+
18
+ # Will lean on CodeClimate for these
19
+ Metrics/AbcSize:
20
+ Enabled: false
21
+
22
+ Metrics/MethodLength:
23
+ Enabled: false
24
+
25
+ Metrics/ModuleLength:
26
+ Enabled: false
27
+
28
+ Layout/LineLength:
29
+ Enabled: false
30
+
31
+ Metrics/CyclomaticComplexity:
32
+ Enabled: false
33
+
34
+ Metrics/PerceivedComplexity:
35
+ Enabled: false
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,7 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2023-10-03 21:34:50 UTC using RuboCop version 1.56.4.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in quarantini.gemspec
6
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2023 Phil Phillips
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/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require 'rubocop/rake_task'
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'quarantini'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -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,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'date'
4
+
5
+ module Quarantini
6
+ class Released
7
+ def skip?
8
+ false
9
+ end
10
+ end
11
+
12
+ RELEASED = Released.new
13
+
14
+ class Quarantine
15
+ class << self
16
+ def skip?(quarantine_data)
17
+ quarantine = mix_quarantini(quarantine_data)
18
+ quarantine.skip?
19
+ end
20
+
21
+ def mix_quarantini(quarantine_data)
22
+ if quarantine_data.nil?
23
+ RELEASED
24
+ elsif quarantine_data == true
25
+ new
26
+ else
27
+ new(quarantine_data)
28
+ end
29
+ end
30
+ end
31
+
32
+ def initialize(attributes = {})
33
+ attributes.each do |name, value|
34
+ send("#{name}=", value)
35
+ end
36
+ end
37
+
38
+ def skip?
39
+ !Quarantini.config.run_all && expires_at >= Date.today
40
+ end
41
+
42
+ def expires_at
43
+ case @expires_at
44
+ when nil
45
+ Date.today.next
46
+ when String
47
+ Date.parse(@expires_at)
48
+ when Date
49
+ @expires_at
50
+ else
51
+ raise ArgumentError, "Unknown expiry type #{@expires_at.class.name}. Expecting one of (nil|String|Date)"
52
+ end
53
+ end
54
+
55
+ private
56
+
57
+ attr_writer :expires_at
58
+ end
59
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ if defined? Minitest
4
+ module Quarantini
5
+ module Reporters
6
+ class MinitestReporter < Minitest::Reporters::BaseReporter
7
+ def initialize(options = {})
8
+ super
9
+ @quarantine_results = []
10
+ reports_dir = options.fetch(:reports_dir)
11
+ output_filename = options.fetch(:output_filename)
12
+ @reports_path = File.absolute_path(reports_dir)
13
+ @output_file_path = File.join(@reports_path, output_filename)
14
+ end
15
+
16
+ def record(test)
17
+ super
18
+
19
+ if test.error? || test.failure
20
+ register_result(test, false)
21
+ elsif test.skipped?
22
+ register_result(test, nil)
23
+ elsif test.passed?
24
+ register_result(test, true)
25
+ end
26
+ end
27
+
28
+ def report
29
+ super
30
+ FileUtils.mkdir_p(@reports_path)
31
+ File.write(@output_file_path, @quarantine_results.to_json)
32
+ end
33
+
34
+ private
35
+
36
+ def register_result(test, passed)
37
+ test_metadata = (Kernel.const_get(test.klass).test_metadata || {}).dig(test.name.to_sym, :quarantine)
38
+ return unless test_metadata
39
+
40
+ @quarantine_results << QuarantineResult.new(name: test.name, test_path: test.location, passes: passed, date: Time.now.utc)
41
+ end
42
+ end
43
+ end
44
+ end
45
+
46
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'dry-struct'
4
+ require_relative '../types'
5
+
6
+ module Quarantini
7
+ module Reporters
8
+ class QuarantineResult < Dry::Struct
9
+ # {
10
+ # "name": "some test",
11
+ # "passes": false,
12
+ # "testPath": "/path/to/spec.rb",
13
+ # "date": "2022-01-30T19:20:40.950Z"
14
+ # }
15
+ attribute :name, Quarantini::Types::String
16
+ attribute :passes, Quarantini::Types::Bool.optional
17
+ attribute :test_path, Quarantini::Types::String
18
+ attribute :date, Quarantini::Types::Time
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ if defined? RSpec
4
+ require 'rspec/core/formatters/base_formatter'
5
+ require_relative 'quarantine_result'
6
+
7
+ module Quarantini
8
+ module Reporters
9
+ class RspecReporter < ::RSpec::Core::Formatters::BaseFormatter
10
+ ::RSpec::Core::Formatters.register self, :close, :example_passed, :example_failed, :example_pending
11
+
12
+ def initialize(output)
13
+ super
14
+ @quarantine_results = []
15
+ end
16
+
17
+ def example_passed(passed)
18
+ example = passed.example
19
+ register_result(example, true) if example.metadata[:quarantine]
20
+ end
21
+
22
+ def example_pending(skipped)
23
+ example = skipped.example
24
+ register_result(example, nil) if example.metadata[:quarantine]
25
+ end
26
+
27
+ def example_failed(failure)
28
+ example = failure.example
29
+ register_result(example, false) if example.metadata[:quarantine]
30
+ end
31
+
32
+ def close(_notification)
33
+ output.write @quarantine_results.to_json
34
+ end
35
+
36
+ private
37
+
38
+ def register_result(example, passed)
39
+ @quarantine_results << QuarantineResult.new(name: example.full_description, test_path: example.file_path, passes: passed,
40
+ date: Time.now.utc)
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'dry-types'
4
+ module Quarantini
5
+ module Types
6
+ include Dry.Types()
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Quarantini
4
+ VERSION = '0.1.0'
5
+ end
data/lib/quarantini.rb ADDED
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'dry-configurable'
4
+ require_relative 'quarantini/version'
5
+ require_relative 'quarantini/quarantine'
6
+ require_relative 'quarantini/reporters/rspec_reporter'
7
+ require_relative 'quarantini/reporters/minitest_reporter'
8
+
9
+ module Quarantini
10
+ class Error < StandardError; end
11
+
12
+ extend Dry::Configurable
13
+ setting :run_all, default: false
14
+ end
metadata ADDED
@@ -0,0 +1,187 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: quarantini
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Phil Phillips
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-10-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: dry-configurable
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: dry-struct
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: dry-types
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 13.0.6
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 13.0.6
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '='
74
+ - !ruby/object:Gem::Version
75
+ version: 3.12.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '='
81
+ - !ruby/object:Gem::Version
82
+ version: 3.12.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '='
88
+ - !ruby/object:Gem::Version
89
+ version: '1.56'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '='
95
+ - !ruby/object:Gem::Version
96
+ version: '1.56'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop-performance
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '='
102
+ - !ruby/object:Gem::Version
103
+ version: 1.19.1
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '='
109
+ - !ruby/object:Gem::Version
110
+ version: 1.19.1
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop-rake
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '='
116
+ - !ruby/object:Gem::Version
117
+ version: 0.6.0
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '='
123
+ - !ruby/object:Gem::Version
124
+ version: 0.6.0
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop-rspec
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '='
130
+ - !ruby/object:Gem::Version
131
+ version: 2.24.1
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '='
137
+ - !ruby/object:Gem::Version
138
+ version: 2.24.1
139
+ description:
140
+ email:
141
+ - irving.phillips@gmail.com
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - ".rubocop.yml"
147
+ - ".rubocop_todo.yml"
148
+ - Gemfile
149
+ - LICENSE
150
+ - Rakefile
151
+ - bin/console
152
+ - bin/setup
153
+ - lib/quarantini.rb
154
+ - lib/quarantini/quarantine.rb
155
+ - lib/quarantini/reporters/minitest_reporter.rb
156
+ - lib/quarantini/reporters/quarantine_result.rb
157
+ - lib/quarantini/reporters/rspec_reporter.rb
158
+ - lib/quarantini/types.rb
159
+ - lib/quarantini/version.rb
160
+ homepage: https://github.com/irphilli/quarantini
161
+ licenses:
162
+ - MIT
163
+ metadata:
164
+ homepage_uri: https://github.com/irphilli/quarantini
165
+ source_code_uri: https://github.com/irphilli/quarantini
166
+ changelog_uri: https://github.com/irphilli/quarantini/releases
167
+ rubygems_mfa_required: 'true'
168
+ post_install_message:
169
+ rdoc_options: []
170
+ require_paths:
171
+ - lib
172
+ required_ruby_version: !ruby/object:Gem::Requirement
173
+ requirements:
174
+ - - ">="
175
+ - !ruby/object:Gem::Version
176
+ version: '3.1'
177
+ required_rubygems_version: !ruby/object:Gem::Requirement
178
+ requirements:
179
+ - - ">="
180
+ - !ruby/object:Gem::Version
181
+ version: '0'
182
+ requirements: []
183
+ rubygems_version: 3.3.7
184
+ signing_key:
185
+ specification_version: 4
186
+ summary: A set of tools to remove tests from circulation
187
+ test_files: []