rspec-description_consistency 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +4 -0
- data/.rubocop.yml +22 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/LICENSE +21 -0
- data/README.md +106 -0
- data/Rakefile +12 -0
- data/lib/rspec/description_consistency/configuration.rb +46 -0
- data/lib/rspec/description_consistency/consitency_verifier.rb +94 -0
- data/lib/rspec/description_consistency/reporter.rb +35 -0
- data/lib/rspec/description_consistency/resource_manager.rb +17 -0
- data/lib/rspec/description_consistency/state.rb +24 -0
- data/lib/rspec/description_consistency/version.rb +7 -0
- data/lib/rspec/description_consistency.rb +57 -0
- data/rspec-description_consistency.gemspec +33 -0
- metadata +64 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a0f2e9e090d2bc3707eae5656451fcb48932777e8eee53d9efee4741ae04dfb2
|
4
|
+
data.tar.gz: 8f9e93d88a4e81c1d9f7c30da88747db0a14f8b629dd488d0b0b9a9390140d6b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f8e9e8cdab51a8e86bf8dc611a9c9df71bea86161d4884914908b2b558ca8d409c284d1b39e35e1cba3612b85492b1b9436a77b50306c1c9546bacfa0e6dc266
|
7
|
+
data.tar.gz: 832491c5965120ff2bdf6e4dabfa099a7b59f41b2f34860b638bfec96e676040708f9606c37681f8e601e5c84e678b6aa03a357a32bf5f7bfb88a3659afd7be4
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require:
|
2
|
+
- rubocop-rake
|
3
|
+
- rubocop-rspec
|
4
|
+
|
5
|
+
AllCops:
|
6
|
+
TargetRubyVersion: 3.0
|
7
|
+
NewCops: enable
|
8
|
+
|
9
|
+
Style/Documentation:
|
10
|
+
Enabled: false
|
11
|
+
|
12
|
+
Layout/LineLength:
|
13
|
+
Max: 120
|
14
|
+
|
15
|
+
Layout/IndentationWidth:
|
16
|
+
Enabled: false
|
17
|
+
|
18
|
+
Layout/ElseAlignment:
|
19
|
+
Enabled: false
|
20
|
+
|
21
|
+
Layout/EndAlignment:
|
22
|
+
Enabled: false
|
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
6
|
+
|
7
|
+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
|
8
|
+
|
9
|
+
## Our Standards
|
10
|
+
|
11
|
+
Examples of behavior that contributes to a positive environment for our community include:
|
12
|
+
|
13
|
+
* Demonstrating empathy and kindness toward other people
|
14
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
15
|
+
* Giving and gracefully accepting constructive feedback
|
16
|
+
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
|
17
|
+
* Focusing on what is best not just for us as individuals, but for the overall community
|
18
|
+
|
19
|
+
Examples of unacceptable behavior include:
|
20
|
+
|
21
|
+
* The use of sexualized language or imagery, and sexual attention or
|
22
|
+
advances of any kind
|
23
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
24
|
+
* Public or private harassment
|
25
|
+
* Publishing others' private information, such as a physical or email
|
26
|
+
address, without their explicit permission
|
27
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
28
|
+
professional setting
|
29
|
+
|
30
|
+
## Enforcement Responsibilities
|
31
|
+
|
32
|
+
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
|
33
|
+
|
34
|
+
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
|
35
|
+
|
36
|
+
## Scope
|
37
|
+
|
38
|
+
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
39
|
+
|
40
|
+
## Enforcement
|
41
|
+
|
42
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at TODO: Write your email address. All complaints will be reviewed and investigated promptly and fairly.
|
43
|
+
|
44
|
+
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
45
|
+
|
46
|
+
## Enforcement Guidelines
|
47
|
+
|
48
|
+
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
|
49
|
+
|
50
|
+
### 1. Correction
|
51
|
+
|
52
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
|
53
|
+
|
54
|
+
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
|
55
|
+
|
56
|
+
### 2. Warning
|
57
|
+
|
58
|
+
**Community Impact**: A violation through a single incident or series of actions.
|
59
|
+
|
60
|
+
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
|
61
|
+
|
62
|
+
### 3. Temporary Ban
|
63
|
+
|
64
|
+
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
|
65
|
+
|
66
|
+
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
|
67
|
+
|
68
|
+
### 4. Permanent Ban
|
69
|
+
|
70
|
+
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
|
71
|
+
|
72
|
+
**Consequence**: A permanent ban from any sort of public interaction within the community.
|
73
|
+
|
74
|
+
## Attribution
|
75
|
+
|
76
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
|
77
|
+
available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
78
|
+
|
79
|
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
|
80
|
+
|
81
|
+
[homepage]: https://www.contributor-covenant.org
|
82
|
+
|
83
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
84
|
+
https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2024 Iaroslav Kurbatov
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
# Rspec::DescriptionConsistency
|
2
|
+
|
3
|
+
One of the basic RSpec [best practices](https://www.betterspecs.org) advises using specific describe block descriptions if it describes a specific method:
|
4
|
+
|
5
|
+
```ruby
|
6
|
+
# star.rb
|
7
|
+
|
8
|
+
class Star
|
9
|
+
def self.build(...)
|
10
|
+
...
|
11
|
+
end
|
12
|
+
|
13
|
+
def shape
|
14
|
+
...
|
15
|
+
end
|
16
|
+
```
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
# star_spec.rb
|
20
|
+
|
21
|
+
RSpec.describe Star do
|
22
|
+
describe ".build" do
|
23
|
+
...
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "#shape" do
|
27
|
+
...
|
28
|
+
end
|
29
|
+
end
|
30
|
+
```
|
31
|
+
|
32
|
+
If your team follows this convention, you might quickly encounter inconsistencies as your system evolves: you have to make sure that renaming or moving a method is done with appropriate modification to the `describe` block description.
|
33
|
+
|
34
|
+
This gem enforces consistency by checking descriptions against the described object methods at runtime.
|
35
|
+
|
36
|
+
## Installation
|
37
|
+
|
38
|
+
TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
|
39
|
+
|
40
|
+
Install the gem and add to the application's Gemfile by executing:
|
41
|
+
|
42
|
+
$ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
|
43
|
+
|
44
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
45
|
+
|
46
|
+
$ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
|
47
|
+
|
48
|
+
## Usage
|
49
|
+
|
50
|
+
Add `RSpec::DescriptionConsistency.bind(config)` to your `spec_helper.rb`:
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
RSpec.configure do |config|
|
54
|
+
RSpec::DescriptionConsistency.bind config
|
55
|
+
end
|
56
|
+
```
|
57
|
+
|
58
|
+
You can provide additional configuration via `RSpec::DescriptionConsistency.configure`:
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
RSpec::DescriptionConsistency.configure do |config|
|
62
|
+
# Set to `false` to disable (default: `true`).
|
63
|
+
config.enabled = true
|
64
|
+
|
65
|
+
# Exit with specific code if any inconsistencies were detected (default: `0`).
|
66
|
+
# If set to `0`, RSpec's exit code will be preserved.
|
67
|
+
config.exit_code = 1
|
68
|
+
|
69
|
+
# Custom output stream (default: `Rspec.configuration.output_stream`).
|
70
|
+
config.output_stream = 'tmp/rspec-description_consistency.txt'
|
71
|
+
end
|
72
|
+
```
|
73
|
+
|
74
|
+
By default, descriptions are matched against public and protected methods. If you want to indicate that a specific `describe` refers to a private method you can add `private` flag:
|
75
|
+
|
76
|
+
```ruby
|
77
|
+
describe "#some_private_method", :private do # or `private: true`
|
78
|
+
...
|
79
|
+
end
|
80
|
+
```
|
81
|
+
|
82
|
+
You can disable consistency verification completely by specifying `description_consistency: false` for `describe` block:
|
83
|
+
|
84
|
+
```ruby
|
85
|
+
describe ".this_method_will_not_be_checked", description_consistency: false do
|
86
|
+
...
|
87
|
+
end
|
88
|
+
```
|
89
|
+
|
90
|
+
## Development
|
91
|
+
|
92
|
+
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.
|
93
|
+
|
94
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
95
|
+
|
96
|
+
## Contributing
|
97
|
+
|
98
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/viralpraxis/rspec-description_consistency. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/viralpraxis/rspec-description_consistency/blob/main/CODE_OF_CONDUCT.md).
|
99
|
+
|
100
|
+
## License
|
101
|
+
|
102
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
103
|
+
|
104
|
+
## Code of Conduct
|
105
|
+
|
106
|
+
Everyone interacting in the Rspec::DescriptionConsistency project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/viralpraxis/rspec-description_consistency/blob/main/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'tempfile'
|
4
|
+
require 'singleton'
|
5
|
+
|
6
|
+
module RSpec
|
7
|
+
module DescriptionConsistency
|
8
|
+
class Configuration
|
9
|
+
include Singleton
|
10
|
+
|
11
|
+
attr_reader :enabled, :exit_code, :output_stream
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
@exit_code = 0
|
15
|
+
@enabled = true
|
16
|
+
@output_stream = RSpec.configuration.output_stream
|
17
|
+
end
|
18
|
+
|
19
|
+
def enabled=(value)
|
20
|
+
unless value.is_a?(TrueClass) || value.is_a?(FalseClass)
|
21
|
+
raise ArgumentError, 'Expected `enabled` to be either `true` or `false`'
|
22
|
+
end
|
23
|
+
|
24
|
+
@enabled = value
|
25
|
+
end
|
26
|
+
|
27
|
+
def exit_code=(value)
|
28
|
+
unless value.is_a?(Integer) && value >= 0 && value <= 255
|
29
|
+
raise ArgumentError, 'Expected `exit_code` to be an integer between 0 and 255'
|
30
|
+
end
|
31
|
+
|
32
|
+
@exit_code = value
|
33
|
+
end
|
34
|
+
|
35
|
+
def output_stream=(value)
|
36
|
+
if value.is_a?(IO) || value.is_a?(Tempfile)
|
37
|
+
@output_stream = value
|
38
|
+
elsif value.is_a?(String)
|
39
|
+
@output_stream = File.open(value, 'w')
|
40
|
+
else
|
41
|
+
raise ArgumentError, "Unexpected `output_stream` value `#{value.inspect}`"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RSpec
|
4
|
+
module DescriptionConsistency
|
5
|
+
class ConsitencyVerifier
|
6
|
+
def self.call(...)
|
7
|
+
new(...).call
|
8
|
+
end
|
9
|
+
|
10
|
+
def initialize(context:, configuration:)
|
11
|
+
@context = context
|
12
|
+
@configuration = configuration
|
13
|
+
end
|
14
|
+
|
15
|
+
def call # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
|
16
|
+
return unless top_level_example_group?(context)
|
17
|
+
return unless (method_example_group_context = find_method_description_example_group(context))
|
18
|
+
|
19
|
+
description = method_example_group_context[:description]
|
20
|
+
|
21
|
+
klass = if context[:described_class].is_a?(String)
|
22
|
+
::Object.const_get(method_example_group_context[:described_class])
|
23
|
+
else
|
24
|
+
context[:described_class]
|
25
|
+
end
|
26
|
+
|
27
|
+
include_private = method_example_group_context[:private]
|
28
|
+
|
29
|
+
return if method_example_group_context[:description_consistency] == false
|
30
|
+
return if correct_method_example_group?(description, klass, include_private: include_private)
|
31
|
+
|
32
|
+
Thread.current[EVALUATION_PERSISTENCE_KEY].add_entry(
|
33
|
+
class_name: klass,
|
34
|
+
method_name: description,
|
35
|
+
payload: method_example_group_context[:location]
|
36
|
+
)
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
attr_reader :context, :configuration
|
42
|
+
|
43
|
+
def correct_method_example_group?(description, klass, include_private:)
|
44
|
+
method_name = description[1..].to_sym
|
45
|
+
|
46
|
+
if description.start_with?('#') && include_private
|
47
|
+
klass.method_defined?(method_name) || klass.private_method_defined?(method_name)
|
48
|
+
elsif description.start_with?('#')
|
49
|
+
klass.method_defined?(method_name)
|
50
|
+
elsif description.start_with?('.')
|
51
|
+
correct_class_method?(method_name, klass, include_private: include_private)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def correct_class_method?(method_name, klass, include_private:)
|
56
|
+
klass.singleton_class.method_defined?(method_name) ||
|
57
|
+
(include_private && klass.singleton_class.private_instance_methods.include?(method_name)) ||
|
58
|
+
activesupport_concern?(method_name, klass)
|
59
|
+
end
|
60
|
+
|
61
|
+
def activesupport_concern?(method_name, klass)
|
62
|
+
if klass.is_a?(Module) && klass.const_defined?(:ClassMethods) &&
|
63
|
+
klass.const_get(:ClassMethods).method_defined?(method_name)
|
64
|
+
true
|
65
|
+
else
|
66
|
+
Object.const_defined?(:ActiveSupport) && ::ActiveSupport.const_defined?(:Concern) &&
|
67
|
+
klass.is_a?(ActiveSupport::Concern) &&
|
68
|
+
::Object.const_get(klass.name.split('::').first).respond_to?(method_name)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def top_level_example_group?(context)
|
73
|
+
described_class = context[:described_class]
|
74
|
+
|
75
|
+
return true if described_class.is_a?(Module)
|
76
|
+
return true if described_class.is_a?(String) && ::Object.const_defined?(described_class)
|
77
|
+
|
78
|
+
false
|
79
|
+
end
|
80
|
+
|
81
|
+
def find_method_description_example_group(context)
|
82
|
+
loop do
|
83
|
+
return context if context.nil? || context[:description].start_with?('.', '#')
|
84
|
+
|
85
|
+
context = if context.key?(:example_group)
|
86
|
+
context[:example_group]
|
87
|
+
else
|
88
|
+
context[:parent_example_group]
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RSpec
|
4
|
+
module DescriptionConsistency
|
5
|
+
class Reporter
|
6
|
+
def initialize(output_stream:)
|
7
|
+
@output_stream = output_stream
|
8
|
+
end
|
9
|
+
|
10
|
+
def report(state)
|
11
|
+
return if state.data.empty?
|
12
|
+
|
13
|
+
output_stream << <<~TXT
|
14
|
+
RSpec::DescriptionConsistency detected the following potential inconsistencies:
|
15
|
+
|
16
|
+
TXT
|
17
|
+
|
18
|
+
state.data.each do |key, value|
|
19
|
+
output_stream.puts format_violation_entry(key, value)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
attr_reader :output_stream
|
26
|
+
|
27
|
+
def format_violation_entry(key, value)
|
28
|
+
value
|
29
|
+
.to_a
|
30
|
+
.map { "#{_1}: #{key[0]}#{key[1]}" }
|
31
|
+
.join("\n")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RSpec
|
4
|
+
module DescriptionConsistency
|
5
|
+
module ResourceManager
|
6
|
+
module_function
|
7
|
+
|
8
|
+
def release_io(io)
|
9
|
+
return unless io
|
10
|
+
return if [$stdout, $stderr].include?(io)
|
11
|
+
return if io.closed?
|
12
|
+
|
13
|
+
io.close
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'set'
|
4
|
+
require 'singleton'
|
5
|
+
|
6
|
+
module RSpec
|
7
|
+
module DescriptionConsistency
|
8
|
+
class State
|
9
|
+
attr_reader :data
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
@data = {}
|
13
|
+
end
|
14
|
+
|
15
|
+
def any?
|
16
|
+
@data.any?
|
17
|
+
end
|
18
|
+
|
19
|
+
def add_entry(class_name:, method_name:, payload:)
|
20
|
+
(data[[class_name, method_name]] ||= Set.new) << payload
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'description_consistency/configuration'
|
4
|
+
require_relative 'description_consistency/consitency_verifier'
|
5
|
+
require_relative 'description_consistency/reporter'
|
6
|
+
require_relative 'description_consistency/resource_manager'
|
7
|
+
require_relative 'description_consistency/state'
|
8
|
+
|
9
|
+
module RSpec
|
10
|
+
module DescriptionConsistency
|
11
|
+
EVALUATION_PERSISTENCE_KEY = :'__rspec-description_consistency'
|
12
|
+
|
13
|
+
class << self
|
14
|
+
def configuration
|
15
|
+
::RSpec::DescriptionConsistency::Configuration.instance
|
16
|
+
end
|
17
|
+
|
18
|
+
def configure
|
19
|
+
yield configuration
|
20
|
+
end
|
21
|
+
|
22
|
+
def bind(config) # rubocop:disable Metrics/MethodLength,Metrics/AbcSize
|
23
|
+
config.before(:suite) do
|
24
|
+
Thread.current[EVALUATION_PERSISTENCE_KEY] = ::RSpec::DescriptionConsistency::State.new
|
25
|
+
end
|
26
|
+
|
27
|
+
config.before do |example|
|
28
|
+
configuration = ::RSpec::DescriptionConsistency::Configuration.instance
|
29
|
+
next unless configuration.enabled
|
30
|
+
|
31
|
+
::RSpec::DescriptionConsistency::ConsitencyVerifier.call(
|
32
|
+
context: example.metadata, configuration: configuration
|
33
|
+
)
|
34
|
+
rescue StandardError => e
|
35
|
+
configuration.error_stream.puts "Encountered unexpected exception: #{e.inspect}"
|
36
|
+
end
|
37
|
+
|
38
|
+
config.after(:suite) do
|
39
|
+
configuration = ::RSpec::DescriptionConsistency::Configuration.instance
|
40
|
+
|
41
|
+
::RSpec::DescriptionConsistency::Reporter.new(
|
42
|
+
output_stream: ::RSpec::DescriptionConsistency::Configuration.instance.output_stream
|
43
|
+
).report(Thread.current[EVALUATION_PERSISTENCE_KEY])
|
44
|
+
|
45
|
+
unless [RSpec.configuration.error_stream,
|
46
|
+
RSpec.configuration.error_stream].include?(configuration.output_stream)
|
47
|
+
::RSpec::DescriptionConsistency::ResourceManager.release_io(RSpec.configuration.output_stream)
|
48
|
+
end
|
49
|
+
|
50
|
+
next unless Thread.current[EVALUATION_PERSISTENCE_KEY].any?
|
51
|
+
|
52
|
+
exit configuration.exit_code if configuration.exit_code.positive?
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'lib/rspec/description_consistency/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'rspec-description_consistency'
|
7
|
+
spec.version = Rspec::DescriptionConsistency::VERSION
|
8
|
+
spec.authors = ['Iaroslav Kurbatov']
|
9
|
+
spec.email = ['iaroslav2k@gmail.com']
|
10
|
+
|
11
|
+
spec.summary = 'RSpec extension for automatic description consistency verification'
|
12
|
+
spec.description = <<~TXT
|
13
|
+
Automatic checking of consistency of descriptions in context and describe blocks, and class or module methods.
|
14
|
+
TXT
|
15
|
+
spec.homepage = 'https://github.com/viralpraxis/rspec-description_consistency'
|
16
|
+
spec.license = 'MIT'
|
17
|
+
spec.required_ruby_version = '>= 3.0.0'
|
18
|
+
|
19
|
+
spec.metadata['homepage_uri'] = 'https://github.com/viralpraxis/rspec-description_consistency'
|
20
|
+
spec.metadata['changelog_uri'] = 'https://github.com/viralpraxis/rspec-description_consistency/blob/main/CHANGELOG.md'
|
21
|
+
|
22
|
+
# Specify which files should be added to the gem when it is released.
|
23
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
24
|
+
spec.files = Dir.chdir(__dir__) do
|
25
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
26
|
+
(File.expand_path(f) == __FILE__) ||
|
27
|
+
f.start_with?(*%w[bin/ test/ spec/ features/ .git .github appveyor Gemfile])
|
28
|
+
end
|
29
|
+
end
|
30
|
+
spec.require_paths = ['lib']
|
31
|
+
|
32
|
+
spec.metadata['rubygems_mfa_required'] = 'true'
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rspec-description_consistency
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Iaroslav Kurbatov
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-07-03 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: 'Automatic checking of consistency of descriptions in context and describe
|
14
|
+
blocks, and class or module methods.
|
15
|
+
|
16
|
+
'
|
17
|
+
email:
|
18
|
+
- iaroslav2k@gmail.com
|
19
|
+
executables: []
|
20
|
+
extensions: []
|
21
|
+
extra_rdoc_files: []
|
22
|
+
files:
|
23
|
+
- ".rspec"
|
24
|
+
- ".rubocop.yml"
|
25
|
+
- CHANGELOG.md
|
26
|
+
- CODE_OF_CONDUCT.md
|
27
|
+
- LICENSE
|
28
|
+
- README.md
|
29
|
+
- Rakefile
|
30
|
+
- lib/rspec/description_consistency.rb
|
31
|
+
- lib/rspec/description_consistency/configuration.rb
|
32
|
+
- lib/rspec/description_consistency/consitency_verifier.rb
|
33
|
+
- lib/rspec/description_consistency/reporter.rb
|
34
|
+
- lib/rspec/description_consistency/resource_manager.rb
|
35
|
+
- lib/rspec/description_consistency/state.rb
|
36
|
+
- lib/rspec/description_consistency/version.rb
|
37
|
+
- rspec-description_consistency.gemspec
|
38
|
+
homepage: https://github.com/viralpraxis/rspec-description_consistency
|
39
|
+
licenses:
|
40
|
+
- MIT
|
41
|
+
metadata:
|
42
|
+
homepage_uri: https://github.com/viralpraxis/rspec-description_consistency
|
43
|
+
changelog_uri: https://github.com/viralpraxis/rspec-description_consistency/blob/main/CHANGELOG.md
|
44
|
+
rubygems_mfa_required: 'true'
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options: []
|
47
|
+
require_paths:
|
48
|
+
- lib
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 3.0.0
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
requirements: []
|
60
|
+
rubygems_version: 3.5.3
|
61
|
+
signing_key:
|
62
|
+
specification_version: 4
|
63
|
+
summary: RSpec extension for automatic description consistency verification
|
64
|
+
test_files: []
|