rubocop-openproject 0.1.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 32626e1f367406ced02e2379b7a390a9c8d9012ce29174a7aefa3cfae33375d9
4
- data.tar.gz: 31d990582ddf0efa6ae5f3905d2024bb4dc525160061315a983ea510f45f9fe2
3
+ metadata.gz: 1b7762dbbe159ef129537b0da6ca121fde8f6417a92ae9d55acff9af82002456
4
+ data.tar.gz: f1193f7c4cf3b908b52a29649927a6e73a5f39376a79e69e0c0540461600ed01
5
5
  SHA512:
6
- metadata.gz: 2b488bcfd9c6dd063ef385c69afe15ba12e5a7ea0419065796e392e8564d1c42e02ca9f78288e9f7b6fcb7c8ed0e81ea03a179c886f0742faf42ca4dd8346d43
7
- data.tar.gz: 0b913ebb1d53d3c90f9faa66cc21c044d4b076d23495dbd37042c5b91c78e9d41b212db7972b38502c7cf09dd7040104d15774094c312819eec15c379e1a8ff7
6
+ metadata.gz: 8d78e20f34afc1d1ac0ffcafa68a1a0953e49b7952d62e0ced2f78866500c43708294f5131796e0e2583c0aa0eab031fdfe818f063184313ef5747642ffcca21
7
+ data.tar.gz: 0d590796e0332ab1679f46062f967d4ab0bee76a97f7f7dc85617dc1186e60437e08071c4c1b6e6981a17fd2262e834fcd9294eb53c1751f9c31d81f1d85a5ff
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.2.0] - 2024-10-18
4
+
5
+ - Add `OpenProject/NoSleepInFeatureSpecs` cop to check that `sleep` calls in
6
+ feature specs are not greater than 1 second.
7
+
3
8
  ## [0.1.0] - 2024-07-05
4
9
 
5
10
  - Initial release
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
@@ -3,3 +3,4 @@
3
3
  require_relative "open_project/add_preview_for_view_component"
4
4
  require_relative "open_project/no_do_end_block_with_rspec_capybara_matcher_in_expect"
5
5
  require_relative "open_project/use_service_result_factory_methods"
6
+ require_relative "open_project/no_sleep_in_feature_specs"
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RuboCop
4
4
  module OpenProject
5
- VERSION = "0.1.0"
5
+ VERSION = "0.2.0"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-openproject
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - OpenProject GmbH
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2024-07-05 00:00:00.000000000 Z
10
+ date: 2024-10-18 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: rubocop
@@ -41,6 +40,7 @@ files:
41
40
  - lib/rubocop-openproject.rb
42
41
  - lib/rubocop/cop/open_project/add_preview_for_view_component.rb
43
42
  - lib/rubocop/cop/open_project/no_do_end_block_with_rspec_capybara_matcher_in_expect.rb
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
@@ -54,7 +54,6 @@ metadata:
54
54
  source_code_uri: https://github.com/opf/rubocop-openproject
55
55
  changelog_uri: https://github.com/opf/rubocop-openproject/blob/main/CHANGELOG.md
56
56
  rubygems_mfa_required: 'true'
57
- post_install_message:
58
57
  rdoc_options: []
59
58
  require_paths:
60
59
  - lib
@@ -69,8 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
69
68
  - !ruby/object:Gem::Version
70
69
  version: '0'
71
70
  requirements: []
72
- rubygems_version: 3.5.14
73
- signing_key:
71
+ rubygems_version: 3.6.0.dev
74
72
  specification_version: 4
75
73
  summary: RuboCop cops for OpenProject
76
74
  test_files: []