speccloak 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ddb8dc293bcb7703d940b98d579d87e6d5e8a73f49cf2618a36b9899e3e77807
4
+ data.tar.gz: 7458ecc9f2262c7564e758b82bf85b12a12d5fbcb1dc22656dd1c4eacfe33876
5
+ SHA512:
6
+ metadata.gz: a3f1a829d4fe5f3e30f1f401d2460cc9bd15ce6ec8e2ca435577785b401d08ddb2ab04da89a60fb026b11838b832f96311d7f216cac0fc75be4502ee40fc203b
7
+ data.tar.gz: 41813f074ded62cf322c9ceec58c63c5f9f0729c0393a72a9bf152ba1eae7201584ad132bd818a1ef5a3860981c0f4ef17dbb26830a97777846e6102fa3a0ffb
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,298 @@
1
+ plugins:
2
+ - rubocop-rake
3
+ AllCops:
4
+ SuggestExtensions: false
5
+ Exclude:
6
+ - 'bin/console'
7
+ - 'exe/speccloak'
8
+ Style/StringLiterals:
9
+ EnforcedStyle: double_quotes
10
+
11
+ Style/StringLiteralsInInterpolation:
12
+ EnforcedStyle: double_quotes
13
+ Metrics/ClassLength:
14
+ Max: 150
15
+ Metrics/BlockLength:
16
+ Exclude:
17
+ - 'spec/**/*_spec.rb'
18
+ Max: 100
19
+ Style/Documentation:
20
+ Enabled: false
21
+ Style/YAMLFileRead:
22
+ Enabled: false
23
+ Gemspec/AddRuntimeDependency:
24
+ Enabled: false
25
+ Gemspec/AttributeAssignment:
26
+ Enabled: false
27
+ Gemspec/DeprecatedAttributeAssignment:
28
+ Enabled: false
29
+ Gemspec/DevelopmentDependencies:
30
+ Enabled: false
31
+ Gemspec/RequireMFA:
32
+ Enabled: false
33
+ Layout/LineContinuationLeadingSpace:
34
+ Enabled: false
35
+ Layout/LineContinuationSpacing:
36
+ Enabled: false
37
+ Layout/LineEndStringConcatenationIndentation:
38
+ Enabled: false
39
+ Layout/SpaceBeforeBrackets:
40
+ Enabled: false
41
+ Lint/AmbiguousAssignment:
42
+ Enabled: false
43
+ Lint/AmbiguousOperatorPrecedence:
44
+ Enabled: false
45
+ Lint/AmbiguousRange:
46
+ Enabled: false
47
+ Lint/ArrayLiteralInRegexp:
48
+ Enabled: false
49
+ Lint/ConstantOverwrittenInRescue:
50
+ Enabled: false
51
+ Lint/ConstantReassignment:
52
+ Enabled: false
53
+ Lint/CopDirectiveSyntax:
54
+ Enabled: false
55
+ Lint/DeprecatedConstants:
56
+ Enabled: false
57
+ Lint/DuplicateBranch:
58
+ Enabled: false
59
+ Lint/DuplicateMagicComment:
60
+ Enabled: false
61
+ Lint/DuplicateMatchPattern:
62
+ Enabled: false
63
+ Lint/DuplicateRegexpCharacterClassElement:
64
+ Enabled: false
65
+ Lint/DuplicateSetElement:
66
+ Enabled: false
67
+ Lint/EmptyBlock:
68
+ Enabled: false
69
+ Lint/EmptyClass:
70
+ Enabled: false
71
+ Lint/EmptyInPattern:
72
+ Enabled: false
73
+ Lint/HashNewWithKeywordArgumentsAsDefault:
74
+ Enabled: false
75
+ Lint/IncompatibleIoSelectWithFiberScheduler:
76
+ Enabled: false
77
+ Lint/ItWithoutArgumentsInBlock:
78
+ Enabled: false
79
+ Lint/LambdaWithoutLiteralBlock:
80
+ Enabled: false
81
+ Lint/LiteralAssignmentInCondition:
82
+ Enabled: false
83
+ Lint/MixedCaseRange:
84
+ Enabled: false
85
+ Lint/NoReturnInBeginEndBlocks:
86
+ Enabled: false
87
+ Lint/NonAtomicFileOperation:
88
+ Enabled: false
89
+ Lint/NumberedParameterAssignment:
90
+ Enabled: false
91
+ Lint/NumericOperationWithConstantResult:
92
+ Enabled: false
93
+ Lint/OrAssignmentToConstant:
94
+ Enabled: false
95
+ Lint/RedundantDirGlobSort:
96
+ Enabled: false
97
+ Lint/RedundantRegexpQuantifiers:
98
+ Enabled: false
99
+ Lint/RedundantTypeConversion:
100
+ Enabled: false
101
+ Lint/RefinementImportMethods:
102
+ Enabled: false
103
+ Lint/RequireRangeParentheses:
104
+ Enabled: false
105
+ Lint/RequireRelativeSelfPath:
106
+ Enabled: false
107
+ Lint/SharedMutableDefault:
108
+ Enabled: false
109
+ Lint/SuppressedExceptionInNumberConversion:
110
+ Enabled: false
111
+ Lint/SymbolConversion:
112
+ Enabled: false
113
+ Lint/ToEnumArguments:
114
+ Enabled: false
115
+ Lint/TripleQuotes:
116
+ Enabled: false
117
+ Lint/UnescapedBracketInRegexp:
118
+ Enabled: false
119
+ Lint/UnexpectedBlockArity:
120
+ Enabled: false
121
+ Lint/UnmodifiedReduceAccumulator:
122
+ Enabled: false
123
+ Lint/UselessConstantScoping:
124
+ Enabled: false
125
+ Lint/UselessDefaultValueArgument:
126
+ Enabled: false
127
+ Lint/UselessDefined:
128
+ Enabled: false
129
+ Lint/UselessNumericOperation:
130
+ Enabled: false
131
+ Lint/UselessOr:
132
+ Enabled: false
133
+ Lint/UselessRescue:
134
+ Enabled: false
135
+ Lint/UselessRuby2Keywords:
136
+ Enabled: false
137
+ Metrics/CollectionLiteralLength:
138
+ Enabled: false
139
+ Naming/BlockForwarding:
140
+ Enabled: false
141
+ Naming/PredicateMethod:
142
+ Enabled: false
143
+ Security/CompoundHash:
144
+ Enabled: false
145
+ Security/IoMethods:
146
+ Enabled: false
147
+ Style/AmbiguousEndlessMethodDefinition:
148
+ Enabled: false
149
+ Style/ArgumentsForwarding:
150
+ Enabled: false
151
+ Style/ArrayIntersect:
152
+ Enabled: false
153
+ Style/BitwisePredicate:
154
+ Enabled: false
155
+ Style/CollectionCompact:
156
+ Enabled: false
157
+ Style/CollectionQuerying:
158
+ Enabled: false
159
+ Style/CombinableDefined:
160
+ Enabled: false
161
+ Style/ComparableBetween:
162
+ Enabled: false
163
+ Style/ComparableClamp:
164
+ Enabled: false
165
+ Style/ConcatArrayLiterals:
166
+ Enabled: false
167
+ Style/DataInheritance:
168
+ Enabled: false
169
+ Style/DigChain:
170
+ Enabled: false
171
+ Style/DirEmpty:
172
+ Enabled: false
173
+ Style/DocumentDynamicEvalDefinition:
174
+ Enabled: false
175
+ Style/EmptyHeredoc:
176
+ Enabled: false
177
+ Style/EmptyStringInsideInterpolation:
178
+ Enabled: false
179
+ Style/EndlessMethod:
180
+ Enabled: false
181
+ Style/EnvHome:
182
+ Enabled: false
183
+ Style/ExactRegexpMatch:
184
+ Enabled: false
185
+ Style/FetchEnvVar:
186
+ Enabled: false
187
+ Style/FileEmpty:
188
+ Enabled: false
189
+ Style/FileNull:
190
+ Enabled: false
191
+ Style/FileRead:
192
+ Enabled: false
193
+ Style/FileTouch:
194
+ Enabled: false
195
+ Style/FileWrite:
196
+ Enabled: false
197
+ Style/HashConversion:
198
+ Enabled: false
199
+ Style/HashExcept:
200
+ Enabled: false
201
+ Style/HashFetchChain:
202
+ Enabled: false
203
+ Style/HashSlice:
204
+ Enabled: false
205
+ Style/IfWithBooleanLiteralBranches:
206
+ Enabled: false
207
+ Style/InPatternThen:
208
+ Enabled: false
209
+ Style/ItAssignment:
210
+ Enabled: false
211
+ Style/ItBlockParameter:
212
+ Enabled: false
213
+ Style/KeywordArgumentsMerging:
214
+ Enabled: false
215
+ Style/MagicCommentFormat:
216
+ Enabled: false
217
+ Style/MapCompactWithConditionalBlock:
218
+ Enabled: false
219
+ Style/MapIntoArray:
220
+ Enabled: false
221
+ Style/MapToHash:
222
+ Enabled: false
223
+ Style/MapToSet:
224
+ Enabled: false
225
+ Style/MinMaxComparison:
226
+ Enabled: false
227
+ Style/MultilineInPatternThen:
228
+ Enabled: false
229
+ Style/NegatedIfElseCondition:
230
+ Enabled: false
231
+ Style/NestedFileDirname:
232
+ Enabled: false
233
+ Style/NilLambda:
234
+ Enabled: false
235
+ Style/NumberedParameters:
236
+ Enabled: false
237
+ Style/NumberedParametersLimit:
238
+ Enabled: false
239
+ Style/ObjectThen:
240
+ Enabled: false
241
+ Style/OpenStructUse:
242
+ Enabled: false
243
+ Style/OperatorMethodCall:
244
+ Enabled: false
245
+ Style/QuotedSymbols:
246
+ Enabled: false
247
+ Style/RedundantArgument:
248
+ Enabled: false
249
+ Style/RedundantArrayConstructor:
250
+ Enabled: false
251
+ Style/RedundantArrayFlatten:
252
+ Enabled: false
253
+ Style/RedundantConstantBase:
254
+ Enabled: false
255
+ Style/RedundantCurrentDirectoryInPath:
256
+ Enabled: false
257
+ Style/RedundantDoubleSplatHashBraces:
258
+ Enabled: false
259
+ Style/RedundantEach:
260
+ Enabled: false
261
+ Style/RedundantFilterChain:
262
+ Enabled: false
263
+ Style/RedundantFormat:
264
+ Enabled: false
265
+ Style/RedundantHeredocDelimiterQuotes:
266
+ Enabled: false
267
+ Style/RedundantInitialize:
268
+ Enabled: false
269
+ Style/RedundantInterpolationUnfreeze:
270
+ Enabled: false
271
+ Style/RedundantLineContinuation:
272
+ Enabled: false
273
+ Style/RedundantRegexpArgument:
274
+ Enabled: false
275
+ Style/RedundantRegexpConstructor:
276
+ Enabled: false
277
+ Style/RedundantSelfAssignmentBranch:
278
+ Enabled: false
279
+ Style/RedundantStringEscape:
280
+ Enabled: false
281
+ Style/ReturnNilInPredicateMethodDefinition:
282
+ Enabled: false
283
+ Style/SafeNavigationChainLength:
284
+ Enabled: false
285
+ Style/SelectByRegexp:
286
+ Enabled: false
287
+ Style/SendWithLiteralMethodName:
288
+ Enabled: false
289
+ Style/SingleLineDoEndBlock:
290
+ Enabled: false
291
+ Style/StringChars:
292
+ Enabled: false
293
+ Style/SuperArguments:
294
+ Enabled: false
295
+ Style/SuperWithArgsParentheses:
296
+ Enabled: false
297
+ Style/SwapValues:
298
+ Enabled: false
data/.speccloak.yml ADDED
@@ -0,0 +1,6 @@
1
+ base: origin/main
2
+ format:
3
+ exclude:
4
+ - "config/routes.rb"
5
+ - "db/schema.rb"
6
+ - "lib/tasks/"
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2025-06-22
4
+
5
+ - Initial release
@@ -0,0 +1,132 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, caste, color, religion, or sexual
10
+ identity and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the overall
26
+ community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or advances of
31
+ any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
33
+ * Public or private harassment
34
+ * Publishing others' private information, such as a physical or email address,
35
+ without their explicit permission
36
+ * Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official email address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement at
63
+ [INSERT CONTACT METHOD].
64
+ All complaints will be reviewed and investigated promptly and fairly.
65
+
66
+ All community leaders are obligated to respect the privacy and security of the
67
+ reporter of any incident.
68
+
69
+ ## Enforcement Guidelines
70
+
71
+ Community leaders will follow these Community Impact Guidelines in determining
72
+ the consequences for any action they deem in violation of this Code of Conduct:
73
+
74
+ ### 1. Correction
75
+
76
+ **Community Impact**: Use of inappropriate language or other behavior deemed
77
+ unprofessional or unwelcome in the community.
78
+
79
+ **Consequence**: A private, written warning from community leaders, providing
80
+ clarity around the nature of the violation and an explanation of why the
81
+ behavior was inappropriate. A public apology may be requested.
82
+
83
+ ### 2. Warning
84
+
85
+ **Community Impact**: A violation through a single incident or series of
86
+ actions.
87
+
88
+ **Consequence**: A warning with consequences for continued behavior. No
89
+ interaction with the people involved, including unsolicited interaction with
90
+ those enforcing the Code of Conduct, for a specified period of time. This
91
+ includes avoiding interactions in community spaces as well as external channels
92
+ like social media. Violating these terms may lead to a temporary or permanent
93
+ ban.
94
+
95
+ ### 3. Temporary Ban
96
+
97
+ **Community Impact**: A serious violation of community standards, including
98
+ sustained inappropriate behavior.
99
+
100
+ **Consequence**: A temporary ban from any sort of interaction or public
101
+ communication with the community for a specified period of time. No public or
102
+ private interaction with the people involved, including unsolicited interaction
103
+ with those enforcing the Code of Conduct, is allowed during this period.
104
+ Violating these terms may lead to a permanent ban.
105
+
106
+ ### 4. Permanent Ban
107
+
108
+ **Community Impact**: Demonstrating a pattern of violation of community
109
+ standards, including sustained inappropriate behavior, harassment of an
110
+ individual, or aggression toward or disparagement of classes of individuals.
111
+
112
+ **Consequence**: A permanent ban from any sort of public interaction within the
113
+ community.
114
+
115
+ ## Attribution
116
+
117
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
+ version 2.1, available at
119
+ [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
120
+
121
+ Community Impact Guidelines were inspired by
122
+ [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
123
+
124
+ For answers to common questions about this code of conduct, see the FAQ at
125
+ [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
126
+ [https://www.contributor-covenant.org/translations][translations].
127
+
128
+ [homepage]: https://www.contributor-covenant.org
129
+ [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
130
+ [Mozilla CoC]: https://github.com/mozilla/diversity
131
+ [FAQ]: https://www.contributor-covenant.org/faq
132
+ [translations]: https://www.contributor-covenant.org/translations
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 nitinrajkumarparuchuri
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.
data/README.md ADDED
@@ -0,0 +1,156 @@
1
+ # Speccloak
2
+
3
+ **Speccloak** is a lightweight CLI tool that checks if the lines you've changed in your Git branch are covered by your test suite. ...
4
+
5
+ **Speccloak** is a lightweight CLI tool that checks if the lines you've changed in your Git branch are covered by your test suite. It helps you prevent untested changes from creeping into the codebase — effortlessly.
6
+
7
+ ---
8
+
9
+ ## What It Does
10
+
11
+ * Compares your current branch with a base branch (e.g. `origin/main`)
12
+ * Analyzes which lines have changed
13
+ * Uses SimpleCov's `.resultset.json` to verify test coverage for those lines
14
+ * Highlights which changed lines are not covered
15
+ * Supports `.speccloak.yml` config file and CLI overrides
16
+ * Outputs results in `text` or `json`
17
+
18
+ ---
19
+
20
+ ## Installation
21
+
22
+ ### From RubyGems (after publishing)
23
+
24
+ ```bash
25
+ gem install speccloak
26
+ ```
27
+
28
+ ### From local gem build
29
+
30
+ ```bash
31
+ git clone https://github.com/alpinesarecool/speccloak.git
32
+ cd speccloak
33
+ gem build speccloak.gemspec
34
+ gem install ./speccloak-0.1.0.gem
35
+ ```
36
+
37
+ ---
38
+
39
+ ## Configuration
40
+
41
+ Create a `.speccloak.yml` in your project root:
42
+
43
+ ```yaml
44
+ base: origin/main # The branch to diff against
45
+ format: text # text or json
46
+ exclude: # Exclude these path from checking the coverage
47
+ - db/migrate
48
+ - spec/
49
+ - config/initializers
50
+ ```
51
+
52
+ You can override these via CLI options as well.
53
+
54
+ ---
55
+
56
+ ## Usage
57
+
58
+ ### Basic command
59
+
60
+ ```bash
61
+ speccloak
62
+ ```
63
+
64
+ ### With CLI options
65
+
66
+ ```bash
67
+ speccloak --base origin/develop --format json --exclude []
68
+ ```
69
+
70
+ ### Show help
71
+
72
+ ```bash
73
+ speccloak --help
74
+ ```
75
+
76
+ ```
77
+ Usage: speccloak [options]
78
+ --base BRANCH Specify the base branch (default: origin/main)
79
+ --format FORMAT Output format (text or json)
80
+ -h, --help Display help information
81
+ ```
82
+
83
+ ---
84
+
85
+ ## Output
86
+
87
+ ### When everything is covered
88
+
89
+ ```
90
+ File: app/models/user.rb
91
+ Changed lines: 12, 13
92
+ All changed lines are covered!
93
+
94
+ BRANCH COVERAGE REPORT SUMMARY
95
+ ----------------------------------------
96
+ Total changed lines: 2
97
+ Covered changed lines: 2
98
+ Coverage percentage: 100%
99
+ ```
100
+
101
+ ### When lines are uncovered
102
+
103
+ ```
104
+ Uncovered lines by file:
105
+ app/services/payment_handler.rb:
106
+ Line 42: call_external_api
107
+
108
+ Coverage check failed: Above lines are not covered by specs.
109
+ ```
110
+
111
+ ---
112
+
113
+ ## Development
114
+
115
+ To run the CLI directly from source:
116
+
117
+ ```bash
118
+ bundle exec exe/speccloak
119
+ ```
120
+
121
+ ---
122
+
123
+ ## Releasing
124
+
125
+ After bumping the version in `lib/speccloak/version.rb`:
126
+
127
+ ```bash
128
+ gem build speccloak.gemspec
129
+ gem push speccloak-<version>.gem
130
+ ```
131
+
132
+ ---
133
+
134
+ ## License
135
+
136
+ MIT © [Nitin Rajkumar Paruchuri](https://github.com/alpinesarecool)
137
+
138
+
139
+ ## Development
140
+
141
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
142
+
143
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
144
+
145
+ ## Contributing
146
+
147
+ Bug reports and pull requests are welcome on GitHub at https://github.com/alpinesarecool/speccloak. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
148
+
149
+ ## License
150
+
151
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
152
+
153
+ ## Code of Conduct
154
+
155
+ Everyone interacting in the Speccloak project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/alpinesarecool/speccloak/blob/master/CODE_OF_CONDUCT.md).
156
+
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/exe/speccloak ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "speccloak"
5
+ require "speccloak/cli"
6
+
7
+ Speccloak::CLI.start(ARGV)
@@ -0,0 +1,197 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+ require_relative "changed_lines_extractor"
5
+ require_relative "file_coverage_analyzer"
6
+ require_relative "coverage_reporter"
7
+ require_relative "file_finder"
8
+ require_relative "helpers"
9
+
10
+ # Main namespace for Speccloak branch coverage analysis and reporting tools.
11
+ module Speccloak
12
+ RSPEC_COVERAGE_KEY = "RSpec"
13
+ UNIT_TESTS_COVERAGE_KEY = "unit_tests_0"
14
+
15
+ RUBY_FILE_EXTENSION = ".rb"
16
+ RESULTSET_FILE = ".resultset.json"
17
+
18
+ DEFAULT_EXCLUDED_PATTERNS = [
19
+ ".bundle/",
20
+ "db/schema.rb",
21
+ "db/migrate",
22
+ "config/routes.rb",
23
+ "config/initializers",
24
+ "db/seeds.rb",
25
+ "spec.rb",
26
+ "spec/",
27
+ "^(?!.*\\.rb$).*"
28
+ ].map { |pattern| /#{pattern}/ }
29
+
30
+ def self.excluded_patterns
31
+ if ENV["SPECLOAK_EXCLUDE"]
32
+ ENV["SPECLOAK_EXCLUDE"].split(",").map { |pattern| /#{pattern.strip}/ }
33
+ else
34
+ DEFAULT_EXCLUDED_PATTERNS
35
+ end
36
+ end
37
+
38
+ # Checks and reports branch coverage for changed/untracked files in a project.
39
+ class BranchCoverageChecker
40
+ include Helpers
41
+ def initialize(
42
+ base: "origin/main",
43
+ format: "text",
44
+ exclude_patterns: [],
45
+ cmd_runner: ->(cmd) { `#{cmd}` },
46
+ file_reader: ->(path) { File.read(path) }
47
+ )
48
+ @base = base
49
+ @format = format
50
+ @uncovered_lines = []
51
+ @total_changed_lines = 0
52
+ @covered_changed_lines = 0
53
+ @exclude_patterns = exclude_patterns.map { |p| /#{p}/ }
54
+ @untracked_files = []
55
+ @cmd_runner = cmd_runner
56
+ @file_reader = file_reader
57
+ end
58
+
59
+ def run
60
+ coverage_file = find_coverage_file
61
+ return exit_with_status("Coverage file not found.", ExitCodes::FAILURE) unless coverage_file
62
+
63
+ changed_files = find_changed_files
64
+ return exit_with_status("No Ruby files changed in this branch.", ExitCodes::SUCCESS) if changed_files.empty?
65
+
66
+ analyze_files(changed_files, coverage_file)
67
+ report_results
68
+ end
69
+
70
+ private
71
+
72
+ def log(message)
73
+ puts message
74
+ end
75
+
76
+ def exit_with_status(message, code = ExitCodes::SUCCESS)
77
+ log(message)
78
+ exit(code)
79
+ end
80
+
81
+ def report_results
82
+ CoverageReporter.new(
83
+ @uncovered_lines,
84
+ @total_changed_lines,
85
+ @covered_changed_lines,
86
+ @format
87
+ ).report_results
88
+ end
89
+
90
+ def find_coverage_file
91
+ coverage_file = File.join(build_coverage_dir, RESULTSET_FILE)
92
+ return coverage_file if File.exist?(coverage_file)
93
+
94
+ log("Coverage file not found: #{coverage_file}")
95
+ nil
96
+ end
97
+
98
+ def build_coverage_dir
99
+ "coverage"
100
+ end
101
+
102
+ def find_changed_files
103
+ finder = Speccloak::FileFinder.new(@cmd_runner, @base)
104
+ changed_files = finder.changed_files
105
+
106
+ changed_files.reject! { |file| excluded_file?(file) }
107
+
108
+ log("\n\nChanged files: \n#{changed_files.join("\n")}") unless changed_files.empty?
109
+ log("\n")
110
+ changed_files
111
+ end
112
+
113
+ def analyze_files(changed_files, coverage_file)
114
+ coverage_data = JSON.parse(@file_reader.call(coverage_file))
115
+ file_coverage = extract_file_coverage(coverage_data)
116
+
117
+ changed_files.each do |file|
118
+ analyze_file(file, file_coverage)
119
+ end
120
+ rescue JSON::ParserError => e
121
+ log("Error parsing coverage file: #{e.message}")
122
+ end
123
+
124
+ def analyze_file(file, file_coverage)
125
+ changed_lines = extract_changed_lines(file)
126
+ return if changed_lines.empty?
127
+
128
+ print_file_change_info(file, changed_lines)
129
+
130
+ absolute_path = File.expand_path(file)
131
+ if file_coverage[absolute_path]
132
+ check_file_coverage(file, file_coverage[absolute_path], changed_lines)
133
+ else
134
+ log("No coverage data found for this file!")
135
+ end
136
+ end
137
+
138
+ def extract_file_coverage(coverage_data)
139
+ [RSPEC_COVERAGE_KEY, UNIT_TESTS_COVERAGE_KEY]
140
+ .map { |key| coverage_data.dig(key, "coverage") }
141
+ .find { |coverage| coverage } || {}
142
+ end
143
+
144
+ def excluded_file?(file)
145
+ (@exclude_patterns + DEFAULT_EXCLUDED_PATTERNS).any? { |pattern| file.match?(pattern) }
146
+ end
147
+
148
+ def print_file_change_info(file, changed_lines)
149
+ log("\nFile: #{file}")
150
+ log("Changed lines: #{changed_lines.join(", ")}")
151
+ end
152
+
153
+ def extract_changed_lines(file)
154
+ return all_line_numbers(file) if untracked_file?(file)
155
+
156
+ changed_lines_from_diff(file)
157
+ end
158
+
159
+ def all_line_numbers(file)
160
+ @file_reader.call(file).each_line.with_index.map { |_, i| i + 1 }
161
+ end
162
+
163
+ def changed_lines_from_diff(file)
164
+ changed_lines = []
165
+ diff_output = @cmd_runner.call("git diff -U0 #{@base} -- #{file}")
166
+ ChangedLinesExtractor.parse(diff_output, changed_lines)
167
+ changed_lines
168
+ end
169
+
170
+ def untracked_file?(file)
171
+ @untracked_files.include?(file)
172
+ end
173
+
174
+ def check_file_coverage(file, file_coverage_data, changed_lines)
175
+ lines_data = file_coverage_data["lines"]
176
+ analyzer = FileCoverageAnalyzer.new(lines_data, changed_lines)
177
+
178
+ uncovered_lines = analyzer.uncovered_lines
179
+ covered_count = analyzer.covered_count
180
+
181
+ update_coverage_statistics(uncovered_lines.size, covered_count)
182
+ record_file_coverage_results(file, uncovered_lines)
183
+ end
184
+
185
+ def update_coverage_statistics(uncovered_count, covered_count)
186
+ @total_changed_lines += (uncovered_count + covered_count)
187
+ @covered_changed_lines += covered_count
188
+ end
189
+
190
+ def record_file_coverage_results(file, uncovered_lines)
191
+ return log("#{Colors::GREEN}All changed lines are covered!#{Colors::RESET}") if uncovered_lines.empty?
192
+
193
+ @uncovered_lines << { file: file, lines: uncovered_lines }
194
+ log("Uncovered lines: #{Colors::RED}#{uncovered_lines.join(", ")}#{Colors::RESET}")
195
+ end
196
+ end
197
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Speccloak
4
+ module ChangedLinesExtractor
5
+ def self.parse(diff_output, changed_lines)
6
+ diff_output.each_line do |line|
7
+ next unless line.start_with?("@@")
8
+
9
+ match = line.match(Speccloak::GitCommands::DIFF_HUNK_HEADER_REGEX)
10
+ next unless match
11
+
12
+ start_line = match[1].to_i
13
+ line_count = match[2] ? match[2].delete(",").to_i : 1
14
+ (start_line...(start_line + line_count)).each { |line_num| changed_lines << line_num }
15
+ end
16
+ changed_lines
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "optparse"
4
+ require "yaml"
5
+ require_relative "branch_coverage_checker"
6
+
7
+ module Speccloak
8
+ class CLI
9
+ def self.start(argv)
10
+ config = default_config
11
+ config.merge!(load_yaml_config) if File.exist?(".speccloak.yml")
12
+ parse_options(argv, config)
13
+ run_checker(config)
14
+ end
15
+
16
+ def self.default_config
17
+ {
18
+ base: "origin/main",
19
+ format: "text",
20
+ exclude: []
21
+ }
22
+ end
23
+
24
+ def self.load_yaml_config
25
+ YAML.load_file(".speccloak.yml").transform_keys(&:to_sym)
26
+ end
27
+
28
+ def self.parse_options(argv, config)
29
+ parser = OptionParser.new do |opts|
30
+ opts.banner = "Usage: speccloak [options]"
31
+ define_options(opts, config)
32
+ end
33
+ parser.parse!(argv)
34
+ end
35
+
36
+ def self.define_options(opts, config)
37
+ opts.on("--base BRANCH", "Specify the base branch (default: origin/main)") do |branch|
38
+ config[:base] = branch
39
+ end
40
+
41
+ opts.on("--format FORMAT", "Output format (text or json)") do |format|
42
+ config[:format] = format
43
+ end
44
+
45
+ opts.on("-h", "--help", "Display help information") do
46
+ puts opts
47
+ exit
48
+ end
49
+ end
50
+
51
+ def self.run_checker(config)
52
+ checker = BranchCoverageChecker.new(
53
+ base: config[:base],
54
+ format: config[:format],
55
+ exclude_patterns: config[:exclude] || []
56
+ )
57
+ checker.run
58
+ end
59
+
60
+ private_class_method :default_config, :load_yaml_config, :parse_options, :run_checker, :define_options
61
+ end
62
+ end
@@ -0,0 +1,115 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "helpers"
4
+
5
+ module Speccloak
6
+ # Reports branch coverage results in summary or JSON format.
7
+ class CoverageReporter
8
+ include Helpers
9
+
10
+ def initialize(uncovered_lines, total_changed_lines, covered_changed_lines, format)
11
+ @uncovered_lines = uncovered_lines
12
+ @total_changed_lines = total_changed_lines
13
+ @covered_changed_lines = covered_changed_lines
14
+ @format = format
15
+ end
16
+
17
+ def report_results
18
+ @format == "json" ? handle_json_report : handle_summary_report
19
+ end
20
+
21
+ private
22
+
23
+ def handle_json_report
24
+ print_json_report
25
+ end
26
+
27
+ def handle_summary_report
28
+ print_summary
29
+ if uncovered?
30
+ print_uncovered_details
31
+ coverage_status(:failure)
32
+ else
33
+ coverage_status(:success)
34
+ end
35
+ end
36
+
37
+ def uncovered?
38
+ @uncovered_lines.any?
39
+ end
40
+
41
+ def coverage_status(type)
42
+ if type == :failure
43
+ log("\n#{Colors::RED}Coverage check failed: Above lines are not covered by specs.#{Colors::RESET}")
44
+ exit_with_status("", ExitCodes::FAILURE)
45
+ else
46
+ log("\n#{Colors::GREEN}Coverage check passed: All changed lines are covered by tests.#{Colors::RESET}")
47
+ exit_with_status("", ExitCodes::SUCCESS)
48
+ end
49
+ end
50
+
51
+ def print_json_report
52
+ result = {
53
+ total_changed_lines: @total_changed_lines,
54
+ covered_changed_lines: @covered_changed_lines,
55
+ coverage_percent: coverage_percent,
56
+ uncovered_files: @uncovered_lines.map { |item| { file: item[:file], lines: item[:lines] } }
57
+ }
58
+
59
+ log(JSON.pretty_generate(result))
60
+ coverage_status(uncovered? ? :failure : :success)
61
+ end
62
+
63
+ def print_summary
64
+ log("\n\n")
65
+ log("----------------------------------------")
66
+ log("BRANCH COVERAGE REPORT SUMMARY")
67
+ log("----------------------------------------")
68
+ log("Total changed lines: #{@total_changed_lines}")
69
+ log("Covered changed lines: #{@covered_changed_lines}")
70
+ log("Coverage percentage: #{coverage_color}#{coverage_percent}%#{Colors::RESET}")
71
+ end
72
+
73
+ def coverage_percent
74
+ @total_changed_lines.positive? ? (@covered_changed_lines.to_f / @total_changed_lines * 100).round(2) : 100
75
+ end
76
+
77
+ def coverage_color
78
+ coverage_percent == 100 ? Colors::GREEN : Colors::RED
79
+ end
80
+
81
+ def print_uncovered_details
82
+ log("\nUncovered lines by file:")
83
+ @uncovered_lines.each { |item| print_file_uncovered_lines(item[:file], item[:lines]) }
84
+ end
85
+
86
+ def print_file_uncovered_lines(file, lines)
87
+ log("\n#{Colors::YELLOW}#{file}#{Colors::RESET}:")
88
+ if File.exist?(file)
89
+ print_existing_file_lines(file, lines)
90
+ else
91
+ print_missing_file_lines(lines)
92
+ end
93
+ end
94
+
95
+ def print_existing_file_lines(file, lines)
96
+ file_lines = File.readlines(file)
97
+ lines.each do |line_num|
98
+ if line_num <= file_lines.size
99
+ code = file_lines[line_num - 1].chomp.strip
100
+ log("#{Colors::RED}#{Colors::BOLD}Line #{line_num}#{Colors::RESET}: #{code}")
101
+ else
102
+ print_line_not_found(line_num)
103
+ end
104
+ end
105
+ end
106
+
107
+ def print_missing_file_lines(lines)
108
+ lines.each { |line_num| log("#{Colors::RED}#{Colors::BOLD}Line #{line_num}#{Colors::RESET} not covered by tests") }
109
+ end
110
+
111
+ def print_line_not_found(line_num)
112
+ log(" #{Colors::RED}#{Colors::BOLD}Line #{line_num}#{Colors::RESET}: (line not found in file)")
113
+ end
114
+ end
115
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Speccloak
4
+ class FileCoverageAnalyzer
5
+ def initialize(lines_data, changed_lines)
6
+ @lines_data = lines_data
7
+ @changed_lines = changed_lines
8
+ end
9
+
10
+ def uncovered_lines
11
+ @changed_lines.select do |line_num|
12
+ line_num - 1 < @lines_data.size &&
13
+ !@lines_data[line_num - 1].nil? &&
14
+ @lines_data[line_num - 1].zero?
15
+ end
16
+ end
17
+
18
+ def covered_count
19
+ @changed_lines.count do |line_num|
20
+ line_num - 1 < @lines_data.size &&
21
+ !@lines_data[line_num - 1].nil? &&
22
+ @lines_data[line_num - 1].positive?
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Speccloak
4
+ class FileFinder
5
+ def initialize(cmd_runner, base)
6
+ @cmd_runner = cmd_runner
7
+ @base = base
8
+ end
9
+
10
+ def changed_files
11
+ tracked = @cmd_runner.call("git diff --name-only #{@base}").split("\n")
12
+ untracked = @cmd_runner.call("git ls-files --others --exclude-standard").split("\n")
13
+ (tracked + untracked).uniq
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Speccloak
4
+ module Helpers
5
+ def log(message)
6
+ puts message
7
+ end
8
+
9
+ def exit_with_status(message, code = ExitCodes::SUCCESS)
10
+ log(message)
11
+ exit(code)
12
+ end
13
+ end
14
+
15
+ module Colors
16
+ RED = "\e[31m"
17
+ GREEN = "\e[32m"
18
+ YELLOW = "\e[33m"
19
+ RESET = "\e[0m"
20
+ BOLD = "\e[1m"
21
+ end
22
+
23
+ module ExitCodes
24
+ SUCCESS = 0
25
+ FAILURE = 1
26
+ end
27
+
28
+ module GitCommands
29
+ CHANGED_FILES_CMD = "git diff --name-only origin/main"
30
+ CHANGED_LINES_CMD_PREF = "git diff -U0 origin/main -- "
31
+ DIFF_HUNK_HEADER_REGEX = /@@ -\d+,?\d* \+(\d+)(,\d+)?/
32
+ end
33
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Speccloak
4
+ VERSION = "0.1.0"
5
+ end
data/lib/speccloak.rb ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "speccloak/version"
4
+ require_relative "speccloak/branch_coverage_checker"
5
+ require_relative "speccloak/cli"
6
+
7
+ module Speccloak
8
+ class Error < StandardError; end
9
+ # Your code goes here...
10
+ end
data/sig/speccloak.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Speccloak
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: speccloak
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - nitinrajkumarparuchuri
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: json
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '2.0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '2.0'
26
+ - !ruby/object:Gem::Dependency
27
+ name: optparse
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '0.1'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '0.1'
40
+ - !ruby/object:Gem::Dependency
41
+ name: yaml
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '0.1'
47
+ type: :runtime
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '0.1'
54
+ description: Speccloak is a CLI tool that reports whether the changed lines in your
55
+ Git branch are covered by specs, using SimpleCov’s JSON output.
56
+ email:
57
+ - nitinrajkumar502@gmail.com
58
+ executables:
59
+ - speccloak
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".rspec"
64
+ - ".rubocop.yml"
65
+ - ".speccloak.yml"
66
+ - CHANGELOG.md
67
+ - CODE_OF_CONDUCT.md
68
+ - LICENSE.txt
69
+ - README.md
70
+ - Rakefile
71
+ - exe/speccloak
72
+ - lib/speccloak.rb
73
+ - lib/speccloak/branch_coverage_checker.rb
74
+ - lib/speccloak/changed_lines_extractor.rb
75
+ - lib/speccloak/cli.rb
76
+ - lib/speccloak/coverage_reporter.rb
77
+ - lib/speccloak/file_coverage_analyzer.rb
78
+ - lib/speccloak/file_finder.rb
79
+ - lib/speccloak/helpers.rb
80
+ - lib/speccloak/version.rb
81
+ - sig/speccloak.rbs
82
+ homepage: https://github.com/alpinesarecool/speccloak
83
+ licenses:
84
+ - MIT
85
+ metadata:
86
+ homepage_uri: https://github.com/alpinesarecool/speccloak
87
+ source_code_uri: https://github.com/alpinesarecool/speccloak
88
+ changelog_uri: https://github.com/alpinesarecool/speccloak/blob/main/CHANGELOG.md
89
+ rubygems_mfa_required: 'true'
90
+ rdoc_options: []
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: 3.1.0
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ requirements: []
104
+ rubygems_version: 3.6.9
105
+ specification_version: 4
106
+ summary: Check coverage of changed lines in your branch with a single command.
107
+ test_files: []