rubocop-rspec 1.19.0 → 1.20.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 +5 -5
- data/CHANGELOG.md +15 -0
- data/README.md +1 -5
- data/config/default.yml +11 -3
- data/lib/rubocop-rspec.rb +3 -2
- data/lib/rubocop/cop/rspec/context_wording.rb +63 -0
- data/lib/rubocop/cop/rspec/{factory_girl → factory_bot}/dynamic_attribute_defined_statically.rb +1 -1
- data/lib/rubocop/cop/rspec/return_from_stub.rb +1 -1
- data/lib/rubocop/cop/rspec/subject_stub.rb +12 -1
- data/lib/rubocop/rspec/config_formatter.rb +1 -1
- data/lib/rubocop/rspec/factory_bot.rb +7 -0
- data/lib/rubocop/rspec/version.rb +1 -1
- data/spec/project/default_config_spec.rb +2 -2
- data/spec/rubocop/cop/rspec/context_wording_spec.rb +62 -0
- data/spec/rubocop/cop/rspec/factory_bot/dynamic_attribute_defined_statically_spec.rb +91 -0
- data/spec/rubocop/cop/rspec/return_from_stub_spec.rb +9 -0
- data/spec/rubocop/cop/rspec/shared_context_spec.rb +2 -2
- data/spec/rubocop/cop/rspec/subject_stub_spec.rb +11 -0
- data/spec/rubocop/rspec/example_spec.rb +1 -1
- data/spec/rubocop/rspec/language/selector_set_spec.rb +5 -5
- metadata +10 -7
- data/lib/rubocop/rspec/factory_girl.rb +0 -7
- data/spec/rubocop/cop/rspec/factory_girl/dynamic_attribute_defined_statically_spec.rb +0 -87
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 75a86e91f1a68118254233b1bc1f34b78c8b96ce3e0f807bde3dc7a3450db2b8
|
4
|
+
data.tar.gz: 956ce60a540a49bf96425aeb3a856028600bff19a482dc5e90198e0419879b83
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bb066d3c753eb46efffb2acd402f9747a6673af7d8c7748c7c9f7ddec23d67533902dc851315d8750a97f194a8b2266b05c84835c41ff768f3240aa88c8b077d
|
7
|
+
data.tar.gz: 040ec718d9a63756636881881b6f8002ed40f04e1eb2a50efd5c2def669487b9d4184e430e9ecf45b39781f5593d064e1604c5b4549689f9fc575afbe0282c25
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,17 @@
|
|
2
2
|
|
3
3
|
## Master (Unreleased)
|
4
4
|
|
5
|
+
## 1.20.0 (2017-11-09)
|
6
|
+
|
7
|
+
* Rename namespace `FactoryGirl` to `FactoryBot` following original library update. ([@walf443][])
|
8
|
+
* Fix exception in `RSpec/ReturnFromStub` on empty block. ([@yevhene][])
|
9
|
+
* Add `RSpec/ContextWording` cop. ([@pirj][], [@telmofcosta][])
|
10
|
+
* Fix `RSpec/SubjectStub` cop matches receive message inside all matcher. ([@walf443][])
|
11
|
+
|
12
|
+
## 1.19.0 (2017-10-18)
|
13
|
+
|
14
|
+
Compatibility release so users can upgrade RuboCop to 0.51.0. No new features.
|
15
|
+
|
5
16
|
## 1.18.0 (2017-09-29)
|
6
17
|
|
7
18
|
* Fix false positive in `Capybara/FeatureMethods`. ([@Darhazer][])
|
@@ -255,3 +266,7 @@
|
|
255
266
|
[@bmorrall]: https:/github.com/bmorrall
|
256
267
|
[@zverok]: https:/github.com/zverok
|
257
268
|
[@timrogers]: https://github.com/timrogers
|
269
|
+
[@yevhene]: https://github.com/yevhene
|
270
|
+
[@walf443]: https://github.com/walf443
|
271
|
+
[@pirj]: https://github.com/pirj
|
272
|
+
[@telmofcosta]: https://github.com/telmofcosta
|
data/README.md
CHANGED
@@ -98,11 +98,7 @@ RSpec/FilePath:
|
|
98
98
|
|
99
99
|
## Contributing
|
100
100
|
|
101
|
-
|
102
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
103
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
104
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
105
|
-
5. Create new Pull Request
|
101
|
+
Checkout the [contribution guidelines](.github/CONTRIBUTING.md)
|
106
102
|
|
107
103
|
## License
|
108
104
|
|
data/config/default.yml
CHANGED
@@ -4,7 +4,7 @@ AllCops:
|
|
4
4
|
Patterns:
|
5
5
|
- _spec.rb
|
6
6
|
- "(?:^|/)spec/"
|
7
|
-
RSpec/
|
7
|
+
RSpec/FactoryBot:
|
8
8
|
Patterns:
|
9
9
|
- spec/factories/**/*.rb
|
10
10
|
- features/support/factories/**/*.rb
|
@@ -43,6 +43,14 @@ RSpec/BeforeAfterAll:
|
|
43
43
|
- spec/support/**/*.rb
|
44
44
|
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/BeforeAfterAll
|
45
45
|
|
46
|
+
RSpec/ContextWording:
|
47
|
+
Description: "`context` block descriptions should start with 'when', or 'with'."
|
48
|
+
Enabled: true
|
49
|
+
Prefixes:
|
50
|
+
- when
|
51
|
+
- with
|
52
|
+
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ContextWording
|
53
|
+
|
46
54
|
RSpec/DescribeClass:
|
47
55
|
Description: Check that the first argument to the top level describe is a constant.
|
48
56
|
Enabled: true
|
@@ -335,7 +343,7 @@ Capybara/FeatureMethods:
|
|
335
343
|
Enabled: true
|
336
344
|
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Capybara/FeatureMethods
|
337
345
|
|
338
|
-
|
346
|
+
FactoryBot/DynamicAttributeDefinedStatically:
|
339
347
|
Description: Prefer declaring dynamic attribute values in a block.
|
340
348
|
Enabled: true
|
341
|
-
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/
|
349
|
+
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/FactoryBot/DynamicAttributeDefinedStatically
|
data/lib/rubocop-rspec.rb
CHANGED
@@ -18,7 +18,7 @@ require 'rubocop/rspec/hook'
|
|
18
18
|
require 'rubocop/cop/rspec/cop'
|
19
19
|
require 'rubocop/rspec/align_let_brace'
|
20
20
|
require 'rubocop/rspec/capybara'
|
21
|
-
require 'rubocop/rspec/
|
21
|
+
require 'rubocop/rspec/factory_bot'
|
22
22
|
|
23
23
|
RuboCop::RSpec::Inject.defaults!
|
24
24
|
|
@@ -31,6 +31,7 @@ require 'rubocop/cop/rspec/be_eql'
|
|
31
31
|
require 'rubocop/cop/rspec/before_after_all'
|
32
32
|
require 'rubocop/cop/rspec/capybara/current_path_expectation'
|
33
33
|
require 'rubocop/cop/rspec/capybara/feature_methods'
|
34
|
+
require 'rubocop/cop/rspec/context_wording'
|
34
35
|
require 'rubocop/cop/rspec/describe_class'
|
35
36
|
require 'rubocop/cop/rspec/describe_method'
|
36
37
|
require 'rubocop/cop/rspec/describe_symbol'
|
@@ -43,7 +44,7 @@ require 'rubocop/cop/rspec/example_wording'
|
|
43
44
|
require 'rubocop/cop/rspec/expect_actual'
|
44
45
|
require 'rubocop/cop/rspec/expect_in_hook'
|
45
46
|
require 'rubocop/cop/rspec/expect_output'
|
46
|
-
require 'rubocop/cop/rspec/
|
47
|
+
require 'rubocop/cop/rspec/factory_bot/dynamic_attribute_defined_statically'
|
47
48
|
require 'rubocop/cop/rspec/file_path'
|
48
49
|
require 'rubocop/cop/rspec/focus'
|
49
50
|
require 'rubocop/cop/rspec/hook_argument'
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module RSpec
|
6
|
+
# `context` block descriptions should start with 'when', or 'with'.
|
7
|
+
#
|
8
|
+
# @see https://github.com/reachlocal/rspec-style-guide#context-descriptions
|
9
|
+
# @see http://www.betterspecs.org/#contexts
|
10
|
+
#
|
11
|
+
# @example `Prefixes` configuration option, defaults: 'when', and 'with'
|
12
|
+
# Prefixes:
|
13
|
+
# - when
|
14
|
+
# - with
|
15
|
+
# - without
|
16
|
+
#
|
17
|
+
# @example
|
18
|
+
# # bad
|
19
|
+
# context 'the display name not present' do
|
20
|
+
# ...
|
21
|
+
# end
|
22
|
+
#
|
23
|
+
# # good
|
24
|
+
# context 'when the display name is not present' do
|
25
|
+
# ...
|
26
|
+
# end
|
27
|
+
class ContextWording < Cop
|
28
|
+
MSG = 'Start context description with %<prefixes>s.'.freeze
|
29
|
+
|
30
|
+
def_node_matcher :context_wording, <<-PATTERN
|
31
|
+
(block (send _ { :context :shared_context } $(str #bad_prefix?)) ...)
|
32
|
+
PATTERN
|
33
|
+
|
34
|
+
def on_block(node)
|
35
|
+
context_wording(node) do |context|
|
36
|
+
add_offense(context, message: message)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def bad_prefix?(description)
|
43
|
+
!prefixes.include?(description.split.first)
|
44
|
+
end
|
45
|
+
|
46
|
+
def prefixes
|
47
|
+
cop_config['Prefixes'] || []
|
48
|
+
end
|
49
|
+
|
50
|
+
def message
|
51
|
+
format(MSG, prefixes: joined_prefixes)
|
52
|
+
end
|
53
|
+
|
54
|
+
def joined_prefixes
|
55
|
+
quoted = prefixes.map { |prefix| "'#{prefix}'" }
|
56
|
+
return quoted.first if quoted.size == 1
|
57
|
+
quoted << "or #{quoted.pop}"
|
58
|
+
quoted.join(', ')
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -55,15 +55,26 @@ module RuboCop
|
|
55
55
|
# expect(foo).to receive(:bar)
|
56
56
|
# expect(foo).to receive(:bar).with(1)
|
57
57
|
# expect(foo).to receive(:bar).with(1).and_return(2)
|
58
|
+
#
|
59
|
+
# @example source that not matches
|
60
|
+
# expect(foo).to all(receive(:bar))
|
61
|
+
#
|
58
62
|
def_node_matcher :message_expectation?, <<-PATTERN
|
59
63
|
{
|
60
64
|
(send nil? :allow (send nil? %))
|
61
|
-
(send (send nil? :expect (send nil? %)) :to #
|
65
|
+
(send (send nil? :expect (send nil? %)) :to #expectation?)
|
62
66
|
}
|
63
67
|
PATTERN
|
64
68
|
|
69
|
+
def_node_matcher :all_matcher?, '(send nil? :all ...)'
|
70
|
+
|
65
71
|
def_node_search :receive_message?, '(send nil? :receive ...)'
|
66
72
|
|
73
|
+
def expectation?(node)
|
74
|
+
return if all_matcher?(node)
|
75
|
+
receive_message?(node)
|
76
|
+
end
|
77
|
+
|
67
78
|
def on_block(node)
|
68
79
|
return unless example_group?(node)
|
69
80
|
|
@@ -4,7 +4,7 @@ module RuboCop
|
|
4
4
|
module RSpec
|
5
5
|
# Builds a YAML config file from two config hashes
|
6
6
|
class ConfigFormatter
|
7
|
-
NAMESPACES = /^(#{Regexp.union('RSpec', 'Capybara', '
|
7
|
+
NAMESPACES = /^(#{Regexp.union('RSpec', 'Capybara', 'FactoryBot')})/
|
8
8
|
STYLE_GUIDE_BASE_URL = 'http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/'.freeze
|
9
9
|
|
10
10
|
def initialize(config, descriptions)
|
@@ -7,10 +7,10 @@ RSpec.describe 'config/default.yml' do
|
|
7
7
|
namespaces = {
|
8
8
|
'rspec' => 'RSpec',
|
9
9
|
'capybara' => 'Capybara',
|
10
|
-
'
|
10
|
+
'factory_bot' => 'FactoryBot'
|
11
11
|
}
|
12
12
|
glob = SpecHelper::ROOT.join('lib', 'rubocop', 'cop',
|
13
|
-
'rspec', '{capybara/,,
|
13
|
+
'rspec', '{capybara/,,factory_bot/}*.rb')
|
14
14
|
cop_names =
|
15
15
|
Pathname.glob(glob).map do |file|
|
16
16
|
file_name = file.basename('.rb').to_s
|
@@ -0,0 +1,62 @@
|
|
1
|
+
RSpec.describe RuboCop::Cop::RSpec::ContextWording, :config do
|
2
|
+
subject(:cop) { described_class.new(config) }
|
3
|
+
|
4
|
+
let(:cop_config) { { 'Prefixes' => %w[when with] } }
|
5
|
+
|
6
|
+
it 'skips describe blocks' do
|
7
|
+
expect_no_offenses(<<-RUBY)
|
8
|
+
describe 'the display name not present' do
|
9
|
+
end
|
10
|
+
RUBY
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'finds context without `when` at the beginning' do
|
14
|
+
expect_offense(<<-RUBY)
|
15
|
+
context 'the display name not present' do
|
16
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Start context description with 'when', or 'with'.
|
17
|
+
end
|
18
|
+
RUBY
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'finds shared_context without `when` at the beginning' do
|
22
|
+
expect_offense(<<-RUBY)
|
23
|
+
shared_context 'the display name not present' do
|
24
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Start context description with 'when', or 'with'.
|
25
|
+
end
|
26
|
+
RUBY
|
27
|
+
end
|
28
|
+
|
29
|
+
it "skips descriptions beginning with 'when'" do
|
30
|
+
expect_no_offenses(<<-RUBY)
|
31
|
+
context 'when the display name is not present' do
|
32
|
+
end
|
33
|
+
RUBY
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'finds context without separate `when` at the beginning' do
|
37
|
+
expect_offense(<<-RUBY)
|
38
|
+
context 'whenever you do' do
|
39
|
+
^^^^^^^^^^^^^^^^^ Start context description with 'when', or 'with'.
|
40
|
+
end
|
41
|
+
RUBY
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'when configured' do
|
45
|
+
let(:cop_config) { { 'Prefixes' => %w[without] } }
|
46
|
+
|
47
|
+
it 'finds context without whitelisted prefixes at the beginning' do
|
48
|
+
expect_offense(<<-RUBY)
|
49
|
+
context 'when display name is present' do
|
50
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Start context description with 'without'.
|
51
|
+
end
|
52
|
+
RUBY
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'skips descriptions with whitelisted prefixes at the beginning' do
|
56
|
+
expect_no_offenses(<<-RUBY)
|
57
|
+
context 'without a display name' do
|
58
|
+
end
|
59
|
+
RUBY
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# rubocop:disable Metrics/LineLength
|
4
|
+
RSpec.describe RuboCop::Cop::RSpec::FactoryBot::DynamicAttributeDefinedStatically do
|
5
|
+
subject(:cop) { described_class.new(config) }
|
6
|
+
|
7
|
+
let(:config) { RuboCop::Config.new }
|
8
|
+
|
9
|
+
%w[FactoryBot FactoryGirl].each do |factory_bot|
|
10
|
+
context "when using #{factory_bot}" do
|
11
|
+
it 'registers an offense for offending code' do
|
12
|
+
expect_offense(<<-RUBY)
|
13
|
+
#{factory_bot}.define do
|
14
|
+
factory :post do
|
15
|
+
published_at 1.day.from_now
|
16
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use a block to set a dynamic value to an attribute.
|
17
|
+
status [:draft, :published].sample
|
18
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use a block to set a dynamic value to an attribute.
|
19
|
+
created_at 1.day.ago
|
20
|
+
^^^^^^^^^^^^^^^^^^^^ Use a block to set a dynamic value to an attribute.
|
21
|
+
end
|
22
|
+
end
|
23
|
+
RUBY
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'registers an offense in a trait' do
|
27
|
+
expect_offense(<<-RUBY)
|
28
|
+
#{factory_bot}.define do
|
29
|
+
factory :post do
|
30
|
+
title "Something"
|
31
|
+
trait :published do
|
32
|
+
published_at 1.day.from_now
|
33
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use a block to set a dynamic value to an attribute.
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
RUBY
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'accepts' do
|
41
|
+
expect_no_offenses(<<-RUBY)
|
42
|
+
#{factory_bot}.define do
|
43
|
+
factory :post do
|
44
|
+
trait :published do
|
45
|
+
published_at { 1.day.from_now }
|
46
|
+
end
|
47
|
+
created_at { 1.day.ago }
|
48
|
+
status :draft
|
49
|
+
comments_count 0
|
50
|
+
title "Static"
|
51
|
+
description { FFaker::Lorem.paragraph(10) }
|
52
|
+
tag Tag::MAGIC
|
53
|
+
end
|
54
|
+
end
|
55
|
+
RUBY
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'does not add offense if out of factory girl block' do
|
59
|
+
expect_no_offenses(<<-RUBY)
|
60
|
+
status [:draft, :published].sample
|
61
|
+
published_at 1.day.from_now
|
62
|
+
created_at 1.day.ago
|
63
|
+
RUBY
|
64
|
+
end
|
65
|
+
|
66
|
+
bad = <<-RUBY
|
67
|
+
#{factory_bot}.define do
|
68
|
+
factory :post do
|
69
|
+
status([:draft, :published].sample)
|
70
|
+
published_at 1.day.from_now
|
71
|
+
created_at(1.day.ago)
|
72
|
+
updated_at Time.current
|
73
|
+
end
|
74
|
+
end
|
75
|
+
RUBY
|
76
|
+
|
77
|
+
corrected = <<-RUBY
|
78
|
+
#{factory_bot}.define do
|
79
|
+
factory :post do
|
80
|
+
status { [:draft, :published].sample }
|
81
|
+
published_at { 1.day.from_now }
|
82
|
+
created_at { 1.day.ago }
|
83
|
+
updated_at { Time.current }
|
84
|
+
end
|
85
|
+
end
|
86
|
+
RUBY
|
87
|
+
|
88
|
+
include_examples 'autocorrect', bad, corrected
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -17,6 +17,15 @@ RSpec.describe RuboCop::Cop::RSpec::ReturnFromStub, :config do
|
|
17
17
|
RUBY
|
18
18
|
end
|
19
19
|
|
20
|
+
it 'finds empty values returned from block' do
|
21
|
+
expect_offense(<<-RUBY)
|
22
|
+
it do
|
23
|
+
allow(Foo).to receive(:bar) {}
|
24
|
+
^^^^^^^^^^^^^ Use `and_return` for static values.
|
25
|
+
end
|
26
|
+
RUBY
|
27
|
+
end
|
28
|
+
|
20
29
|
it 'finds array with only static values returned from block' do
|
21
30
|
expect_offense(<<-RUBY)
|
22
31
|
it do
|
@@ -1,7 +1,7 @@
|
|
1
1
|
RSpec.describe RuboCop::Cop::RSpec::SharedContext do
|
2
2
|
subject(:cop) { described_class.new }
|
3
3
|
|
4
|
-
|
4
|
+
describe 'shared_context' do
|
5
5
|
it 'does not register an offense for empty contexts' do
|
6
6
|
expect_no_offenses(<<-RUBY)
|
7
7
|
shared_context 'empty' do
|
@@ -55,7 +55,7 @@ RSpec.describe RuboCop::Cop::RSpec::SharedContext do
|
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
|
-
|
58
|
+
describe 'shared_examples' do
|
59
59
|
it 'does not register an offense for empty examples' do
|
60
60
|
expect_no_offenses(<<-RUBY)
|
61
61
|
shared_examples 'empty' do
|
@@ -59,6 +59,17 @@ RSpec.describe RuboCop::Cop::RSpec::SubjectStub do
|
|
59
59
|
RUBY
|
60
60
|
end
|
61
61
|
|
62
|
+
it 'ignores stub when inside all matcher' do
|
63
|
+
expect_no_offenses(<<-RUBY)
|
64
|
+
describe Foo do
|
65
|
+
subject(:foo) { [Object.new] }
|
66
|
+
it 'tries to trick rubocop-rspec' do
|
67
|
+
expect(foo).to all(receive(:baz))
|
68
|
+
end
|
69
|
+
end
|
70
|
+
RUBY
|
71
|
+
end
|
72
|
+
|
62
73
|
it 'flags nested subject stubs when nested subject uses same name' do
|
63
74
|
expect_offense(<<-RUBY)
|
64
75
|
describe Foo do
|
@@ -36,7 +36,7 @@ RSpec.describe RuboCop::RSpec::Example do
|
|
36
36
|
expect(described_class.new(node).to_node).to be(node)
|
37
37
|
end
|
38
38
|
|
39
|
-
|
39
|
+
describe 'value object semantics' do
|
40
40
|
it 'compares by value' do
|
41
41
|
aggregate_failures 'equality semantics' do
|
42
42
|
expect(example('it("foo")')).to eq(example('it("foo")'))
|
@@ -11,7 +11,7 @@ RSpec.describe RuboCop::RSpec::Language::SelectorSet do
|
|
11
11
|
expect(selector_set).not_to eq(described_class.new(%i[foo bar baz]))
|
12
12
|
end
|
13
13
|
|
14
|
-
|
14
|
+
describe '#include?' do
|
15
15
|
it 'returns false for selectors not in the set' do
|
16
16
|
expect(selector_set.include?(:baz)).to be(false)
|
17
17
|
end
|
@@ -21,25 +21,25 @@ RSpec.describe RuboCop::RSpec::Language::SelectorSet do
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
|
24
|
+
describe '#node_pattern' do
|
25
25
|
it 'builds a node pattern' do
|
26
26
|
expect(selector_set.node_pattern).to eql(':foo :bar')
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
|
30
|
+
describe '#node_pattern_union' do
|
31
31
|
it 'builds a node pattern union' do
|
32
32
|
expect(selector_set.node_pattern_union).to eql('{:foo :bar}')
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
-
|
36
|
+
describe '#send_pattern' do
|
37
37
|
it 'builds a send matching pattern' do
|
38
38
|
expect(selector_set.send_pattern).to eql('(send _ {:foo :bar} ...)')
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
|
-
|
42
|
+
describe '#block_pattern' do
|
43
43
|
it 'builds a block matching pattern' do
|
44
44
|
expect(selector_set.block_pattern).to eql(
|
45
45
|
'(block (send _ {:foo :bar} ...) ...)'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop-rspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.20.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Backus
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2017-
|
13
|
+
date: 2017-11-09 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rubocop
|
@@ -110,6 +110,7 @@ files:
|
|
110
110
|
- lib/rubocop/cop/rspec/before_after_all.rb
|
111
111
|
- lib/rubocop/cop/rspec/capybara/current_path_expectation.rb
|
112
112
|
- lib/rubocop/cop/rspec/capybara/feature_methods.rb
|
113
|
+
- lib/rubocop/cop/rspec/context_wording.rb
|
113
114
|
- lib/rubocop/cop/rspec/cop.rb
|
114
115
|
- lib/rubocop/cop/rspec/describe_class.rb
|
115
116
|
- lib/rubocop/cop/rspec/describe_method.rb
|
@@ -123,7 +124,7 @@ files:
|
|
123
124
|
- lib/rubocop/cop/rspec/expect_actual.rb
|
124
125
|
- lib/rubocop/cop/rspec/expect_in_hook.rb
|
125
126
|
- lib/rubocop/cop/rspec/expect_output.rb
|
126
|
-
- lib/rubocop/cop/rspec/
|
127
|
+
- lib/rubocop/cop/rspec/factory_bot/dynamic_attribute_defined_statically.rb
|
127
128
|
- lib/rubocop/cop/rspec/file_path.rb
|
128
129
|
- lib/rubocop/cop/rspec/focus.rb
|
129
130
|
- lib/rubocop/cop/rspec/hook_argument.rb
|
@@ -165,7 +166,7 @@ files:
|
|
165
166
|
- lib/rubocop/rspec/description_extractor.rb
|
166
167
|
- lib/rubocop/rspec/example.rb
|
167
168
|
- lib/rubocop/rspec/example_group.rb
|
168
|
-
- lib/rubocop/rspec/
|
169
|
+
- lib/rubocop/rspec/factory_bot.rb
|
169
170
|
- lib/rubocop/rspec/hook.rb
|
170
171
|
- lib/rubocop/rspec/inject.rb
|
171
172
|
- lib/rubocop/rspec/language.rb
|
@@ -186,6 +187,7 @@ files:
|
|
186
187
|
- spec/rubocop/cop/rspec/before_after_all_spec.rb
|
187
188
|
- spec/rubocop/cop/rspec/capybara/current_path_expectation_spec.rb
|
188
189
|
- spec/rubocop/cop/rspec/capybara/feature_methods_spec.rb
|
190
|
+
- spec/rubocop/cop/rspec/context_wording_spec.rb
|
189
191
|
- spec/rubocop/cop/rspec/cop_spec.rb
|
190
192
|
- spec/rubocop/cop/rspec/describe_class_spec.rb
|
191
193
|
- spec/rubocop/cop/rspec/describe_method_spec.rb
|
@@ -199,7 +201,7 @@ files:
|
|
199
201
|
- spec/rubocop/cop/rspec/expect_actual_spec.rb
|
200
202
|
- spec/rubocop/cop/rspec/expect_in_hook_spec.rb
|
201
203
|
- spec/rubocop/cop/rspec/expect_output_spec.rb
|
202
|
-
- spec/rubocop/cop/rspec/
|
204
|
+
- spec/rubocop/cop/rspec/factory_bot/dynamic_attribute_defined_statically_spec.rb
|
203
205
|
- spec/rubocop/cop/rspec/file_path_spec.rb
|
204
206
|
- spec/rubocop/cop/rspec/focus_spec.rb
|
205
207
|
- spec/rubocop/cop/rspec/hook_argument_spec.rb
|
@@ -265,7 +267,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
265
267
|
version: '0'
|
266
268
|
requirements: []
|
267
269
|
rubyforge_project:
|
268
|
-
rubygems_version: 2.
|
270
|
+
rubygems_version: 2.7.2
|
269
271
|
signing_key:
|
270
272
|
specification_version: 4
|
271
273
|
summary: Code style checking for RSpec files
|
@@ -281,6 +283,7 @@ test_files:
|
|
281
283
|
- spec/rubocop/cop/rspec/before_after_all_spec.rb
|
282
284
|
- spec/rubocop/cop/rspec/capybara/current_path_expectation_spec.rb
|
283
285
|
- spec/rubocop/cop/rspec/capybara/feature_methods_spec.rb
|
286
|
+
- spec/rubocop/cop/rspec/context_wording_spec.rb
|
284
287
|
- spec/rubocop/cop/rspec/cop_spec.rb
|
285
288
|
- spec/rubocop/cop/rspec/describe_class_spec.rb
|
286
289
|
- spec/rubocop/cop/rspec/describe_method_spec.rb
|
@@ -294,7 +297,7 @@ test_files:
|
|
294
297
|
- spec/rubocop/cop/rspec/expect_actual_spec.rb
|
295
298
|
- spec/rubocop/cop/rspec/expect_in_hook_spec.rb
|
296
299
|
- spec/rubocop/cop/rspec/expect_output_spec.rb
|
297
|
-
- spec/rubocop/cop/rspec/
|
300
|
+
- spec/rubocop/cop/rspec/factory_bot/dynamic_attribute_defined_statically_spec.rb
|
298
301
|
- spec/rubocop/cop/rspec/file_path_spec.rb
|
299
302
|
- spec/rubocop/cop/rspec/focus_spec.rb
|
300
303
|
- spec/rubocop/cop/rspec/hook_argument_spec.rb
|
@@ -1,87 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# rubocop:disable Metrics/LineLength
|
4
|
-
RSpec.describe RuboCop::Cop::RSpec::FactoryGirl::DynamicAttributeDefinedStatically do
|
5
|
-
subject(:cop) { described_class.new(config) }
|
6
|
-
|
7
|
-
let(:config) { RuboCop::Config.new }
|
8
|
-
|
9
|
-
it 'registers an offense for offending code' do
|
10
|
-
expect_offense(<<-RUBY)
|
11
|
-
FactoryGirl.define do
|
12
|
-
factory :post do
|
13
|
-
published_at 1.day.from_now
|
14
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use a block to set a dynamic value to an attribute.
|
15
|
-
status [:draft, :published].sample
|
16
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use a block to set a dynamic value to an attribute.
|
17
|
-
created_at 1.day.ago
|
18
|
-
^^^^^^^^^^^^^^^^^^^^ Use a block to set a dynamic value to an attribute.
|
19
|
-
end
|
20
|
-
end
|
21
|
-
RUBY
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'registers an offense in a trait' do
|
25
|
-
expect_offense(<<-RUBY)
|
26
|
-
FactoryGirl.define do
|
27
|
-
factory :post do
|
28
|
-
title "Something"
|
29
|
-
trait :published do
|
30
|
-
published_at 1.day.from_now
|
31
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use a block to set a dynamic value to an attribute.
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
RUBY
|
36
|
-
end
|
37
|
-
|
38
|
-
it 'accepts' do
|
39
|
-
expect_no_offenses(<<-RUBY)
|
40
|
-
FactoryGirl.define do
|
41
|
-
factory :post do
|
42
|
-
trait :published do
|
43
|
-
published_at { 1.day.from_now }
|
44
|
-
end
|
45
|
-
created_at { 1.day.ago }
|
46
|
-
status :draft
|
47
|
-
comments_count 0
|
48
|
-
title "Static"
|
49
|
-
description { FFaker::Lorem.paragraph(10) }
|
50
|
-
tag Tag::MAGIC
|
51
|
-
end
|
52
|
-
end
|
53
|
-
RUBY
|
54
|
-
end
|
55
|
-
|
56
|
-
it 'does not add offense if out of factory girl block' do
|
57
|
-
expect_no_offenses(<<-RUBY)
|
58
|
-
status [:draft, :published].sample
|
59
|
-
published_at 1.day.from_now
|
60
|
-
created_at 1.day.ago
|
61
|
-
RUBY
|
62
|
-
end
|
63
|
-
|
64
|
-
bad = <<-RUBY
|
65
|
-
FactoryGirl.define do
|
66
|
-
factory :post do
|
67
|
-
status([:draft, :published].sample)
|
68
|
-
published_at 1.day.from_now
|
69
|
-
created_at(1.day.ago)
|
70
|
-
updated_at Time.current
|
71
|
-
end
|
72
|
-
end
|
73
|
-
RUBY
|
74
|
-
|
75
|
-
corrected = <<-RUBY
|
76
|
-
FactoryGirl.define do
|
77
|
-
factory :post do
|
78
|
-
status { [:draft, :published].sample }
|
79
|
-
published_at { 1.day.from_now }
|
80
|
-
created_at { 1.day.ago }
|
81
|
-
updated_at { Time.current }
|
82
|
-
end
|
83
|
-
end
|
84
|
-
RUBY
|
85
|
-
|
86
|
-
include_examples 'autocorrect', bad, corrected
|
87
|
-
end
|