rubocop-openproject 0.1.0 → 0.3.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 +4 -4
- data/CHANGELOG.md +9 -0
- data/README.md +9 -0
- data/config/default.yml +5 -0
- data/lib/rubocop/cop/open_project/no_sleep_in_feature_specs.rb +65 -0
- data/lib/rubocop/cop/open_project_cops.rb +1 -1
- data/lib/rubocop/open_project/version.rb +1 -1
- metadata +4 -4
- data/lib/rubocop/cop/open_project/no_do_end_block_with_rspec_capybara_matcher_in_expect.rb +0 -89
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 216a0869e29d95a92306d0d02e2bc340b7914733f86d56c4f27cce5fbcf8e466
|
4
|
+
data.tar.gz: d3ca3bc8f408a56843a5cbd7f8d69a8a1eadc6bda76c5ea8139201181a1e0de8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7041d99b3774a92ae145c93bf64ec52628aee9b04ebd08b04a3803c2d662f956404893306d8274762d0b1050c2f6787b135cc15f58d514e0d508bc8673487881
|
7
|
+
data.tar.gz: 989852deeca12ee26502f448d85e660f6539fca125cd5f174650acf2646da07eef463db5aa025c30d46976484730d2bc0cd363d9953af42fb25f688e24fd3541
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.3.0] - 2025-07-11
|
4
|
+
|
5
|
+
- Remove redundant NoDoEndBlockWithRSpecCapybaraMatcherInExpect cop
|
6
|
+
|
7
|
+
## [0.2.0] - 2024-10-18
|
8
|
+
|
9
|
+
- Add `OpenProject/NoSleepInFeatureSpecs` cop to check that `sleep` calls in
|
10
|
+
feature specs are not greater than 1 second.
|
11
|
+
|
3
12
|
## [0.1.0] - 2024-07-05
|
4
13
|
|
5
14
|
- Initial release
|
data/README.md
CHANGED
@@ -26,6 +26,15 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
|
26
26
|
|
27
27
|
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).
|
28
28
|
|
29
|
+
## Releasing
|
30
|
+
|
31
|
+
1. Update the version in `lib/rubocop/open_project/version.rb`
|
32
|
+
2. Update the changelog in `CHANGELOG.md`
|
33
|
+
3. Run `bundle install` to update `Gemfile.lock`
|
34
|
+
4. Run `rake` to check everything is fine and fix any issues
|
35
|
+
5. Commit your changes (`git commit -am 'Prepare release X.Y.Z'`)
|
36
|
+
6. Run `bundle exec rake release`
|
37
|
+
|
29
38
|
## Contributing
|
30
39
|
|
31
40
|
Bug reports and pull requests are welcome on GitHub at https://github.com/opf/rubocop-openproject.
|
data/config/default.yml
CHANGED
@@ -8,6 +8,11 @@ OpenProject/NoDoEndBlockWithRSpecCapybaraMatcherInExpect:
|
|
8
8
|
Enabled: true
|
9
9
|
VersionAdded: '0.1.0'
|
10
10
|
|
11
|
+
OpenProject/NoSleepInFeatureSpecs:
|
12
|
+
Description: 'Avoid using `sleep` greater than 1 second in feature specs.'
|
13
|
+
Enabled: true
|
14
|
+
VersionAdded: '0.1.0'
|
15
|
+
|
11
16
|
OpenProject/UseServiceResultFactoryMethods:
|
12
17
|
Description: 'Use ServiceResult factory methods instead of ServiceResult.new.'
|
13
18
|
Enabled: true
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module OpenProject
|
6
|
+
# Checks that feature specs do not use `sleep` greater than 1 second.
|
7
|
+
#
|
8
|
+
# Relying on `sleep` for synchronization reduces overall performance of
|
9
|
+
# the test suite. Consider using Capybara `have_*` matchers or
|
10
|
+
# rspec-wait `wait_for` method instead.
|
11
|
+
#
|
12
|
+
# @example
|
13
|
+
#
|
14
|
+
# # bad
|
15
|
+
# sleep 20
|
16
|
+
#
|
17
|
+
# # bad
|
18
|
+
# sleep 1.5
|
19
|
+
#
|
20
|
+
# # bad
|
21
|
+
# delay = 15
|
22
|
+
# sleep delay
|
23
|
+
#
|
24
|
+
# # good (use sparingly)
|
25
|
+
# sleep 1
|
26
|
+
#
|
27
|
+
# # good
|
28
|
+
# expect(page).not_to have_text("please wait")
|
29
|
+
#
|
30
|
+
# # good
|
31
|
+
# expect(page).to have_text("success")
|
32
|
+
#
|
33
|
+
# good
|
34
|
+
# wait_for { work_package.reload.subject }.to eq("Updated name")
|
35
|
+
class NoSleepInFeatureSpecs < Base
|
36
|
+
MSG = "Avoid using `sleep` greater than 1 second in feature specs. " \
|
37
|
+
"It will reduce overall performance of the test suite. " \
|
38
|
+
"Consider using Capybara `have_*` matchers or rspec-wait " \
|
39
|
+
"`wait_for` method instead."
|
40
|
+
|
41
|
+
def_node_matcher :on_sleep_call, "(send nil? :sleep $...)"
|
42
|
+
|
43
|
+
def on_send(node)
|
44
|
+
return unless feature_spec?(processed_source)
|
45
|
+
|
46
|
+
on_sleep_call(node) do |args|
|
47
|
+
add_offense(node, message: MSG) if sleeping_too_much?(args[0])
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def sleeping_too_much?(arg)
|
54
|
+
return false if arg&.numeric_type? && arg.value.between?(0, 1)
|
55
|
+
|
56
|
+
true
|
57
|
+
end
|
58
|
+
|
59
|
+
def feature_spec?(source)
|
60
|
+
source.file_path.include?("_spec.rb") && source.file_path.include?("features/")
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative "open_project/add_preview_for_view_component"
|
4
|
-
require_relative "open_project/no_do_end_block_with_rspec_capybara_matcher_in_expect"
|
5
4
|
require_relative "open_project/use_service_result_factory_methods"
|
5
|
+
require_relative "open_project/no_sleep_in_feature_specs"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop-openproject
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- OpenProject GmbH
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-07-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|
@@ -40,7 +40,7 @@ files:
|
|
40
40
|
- config/default.yml
|
41
41
|
- lib/rubocop-openproject.rb
|
42
42
|
- lib/rubocop/cop/open_project/add_preview_for_view_component.rb
|
43
|
-
- lib/rubocop/cop/open_project/
|
43
|
+
- lib/rubocop/cop/open_project/no_sleep_in_feature_specs.rb
|
44
44
|
- lib/rubocop/cop/open_project/use_service_result_factory_methods.rb
|
45
45
|
- lib/rubocop/cop/open_project_cops.rb
|
46
46
|
- lib/rubocop/open_project.rb
|
@@ -69,7 +69,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
69
69
|
- !ruby/object:Gem::Version
|
70
70
|
version: '0'
|
71
71
|
requirements: []
|
72
|
-
rubygems_version: 3.5.
|
72
|
+
rubygems_version: 3.5.11
|
73
73
|
signing_key:
|
74
74
|
specification_version: 4
|
75
75
|
summary: RuboCop cops for OpenProject
|
@@ -1,89 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RuboCop
|
4
|
-
module Cop
|
5
|
-
module OpenProject
|
6
|
-
# As +do .. end+ block has less precedence than method call, a +do .. end+
|
7
|
-
# block at the end of a rspec matcher will be an argument to the +to+ method,
|
8
|
-
# which is not handled by Capybara matchers (teamcapybara/capybara/#2616).
|
9
|
-
#
|
10
|
-
# @example
|
11
|
-
#
|
12
|
-
# # bad
|
13
|
-
# expect(page).to have_selector("input") do |input|
|
14
|
-
# input.value == "hello world"
|
15
|
-
# end
|
16
|
-
#
|
17
|
-
# # good
|
18
|
-
# expect(page).to have_selector("input") { |input| input.value == "hello world" }
|
19
|
-
#
|
20
|
-
# # good
|
21
|
-
# expect(page).to have_selector("input", value: "hello world")
|
22
|
-
#
|
23
|
-
# # good
|
24
|
-
# match_input_with_hello_world = have_selector("input") do |input|
|
25
|
-
# input.value == "hello world"
|
26
|
-
# end
|
27
|
-
# expect(page).to match_input_with_hello_world
|
28
|
-
#
|
29
|
-
# # good
|
30
|
-
# expect(foo).to have_received(:bar) do |arg|
|
31
|
-
# arg == :baz
|
32
|
-
# end
|
33
|
-
#
|
34
|
-
class NoDoEndBlockWithRSpecCapybaraMatcherInExpect < Base
|
35
|
-
CAPYBARA_MATCHER_METHODS = %w[selector css xpath text title current_path link button
|
36
|
-
field checked_field unchecked_field select table
|
37
|
-
sibling ancestor].flat_map do |matcher_type|
|
38
|
-
["have_#{matcher_type}", "have_no_#{matcher_type}"]
|
39
|
-
end
|
40
|
-
|
41
|
-
MSG = "The `do .. end` block is associated with `to` and not with Capybara matcher `%<matcher_method>s`."
|
42
|
-
|
43
|
-
def_node_matcher :expect_to_with_block?, <<~PATTERN
|
44
|
-
# ruby-parse output
|
45
|
-
(block
|
46
|
-
(send
|
47
|
-
(send nil? :expect ...)
|
48
|
-
:to
|
49
|
-
...
|
50
|
-
)
|
51
|
-
...
|
52
|
-
)
|
53
|
-
PATTERN
|
54
|
-
|
55
|
-
def_node_matcher :rspec_matcher, <<~PATTERN
|
56
|
-
(send
|
57
|
-
(send nil? :expect...)
|
58
|
-
:to
|
59
|
-
(:send nil? $_matcher_method ...)
|
60
|
-
)
|
61
|
-
PATTERN
|
62
|
-
|
63
|
-
def on_block(node)
|
64
|
-
return unless expect_to_with_block?(node)
|
65
|
-
return unless capybara_matcher?(node)
|
66
|
-
|
67
|
-
add_offense(offense_range(node), message: offense_message(node))
|
68
|
-
end
|
69
|
-
|
70
|
-
private
|
71
|
-
|
72
|
-
def capybara_matcher?(node)
|
73
|
-
matcher_name = node.send_node.arguments.first.method_name.to_s
|
74
|
-
CAPYBARA_MATCHER_METHODS.include?(matcher_name)
|
75
|
-
end
|
76
|
-
|
77
|
-
def offense_range(node)
|
78
|
-
node.send_node.loc.selector.join(node.loc.end)
|
79
|
-
end
|
80
|
-
|
81
|
-
def offense_message(node)
|
82
|
-
rspec_matcher(node.send_node) do |matcher_method|
|
83
|
-
format(MSG, matcher_method:)
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|