File tree Expand file tree Collapse file tree 4 files changed +19
-5
lines changed
lib/rubocop/cop/rspec/factory_bot
spec/rubocop/cop/rspec/factory_bot Expand file tree Collapse file tree 4 files changed +19
-5
lines changed Original file line number Diff line number Diff line change 22
33## Master (Unreleased)
44
5+ * Improve message and description of ` FactoryBot/FactoryClassName ` . ([ @ybiquitous ] [ ] )
6+
57## 1.37.0 (2019-11-25)
68
79* Implement ` RSpec/DescribedClassModuleWrapping ` to disallow RSpec statements within a module. ([ @kellysutton ] [ ] )
@@ -466,3 +468,4 @@ Compatibility release so users can upgrade RuboCop to 0.51.0. No new features.
466468[ @kellysutton ] : https://github.com/kellysutton
467469[ @mkrawc ] : https://github.com/mkrawc
468470[ @jfragoulis ] : https://github.com/jfragoulis
471+ [ @ybiquitous ] : https://github.com/ybiquitous
Original file line number Diff line number Diff line change @@ -6,6 +6,11 @@ module RSpec
66 module FactoryBot
77 # Use string value when setting the class attribute explicitly.
88 #
9+ # This cop would promote faster tests by lazy-loading of
10+ # application files. Also, this could help you suppress potential bugs
11+ # in combination with external libraries by avoiding a preload of
12+ # application files from the factory files.
13+ #
914 # @example
1015 # # bad
1116 # factory :foo, class: Foo do
@@ -15,7 +20,8 @@ module FactoryBot
1520 # factory :foo, class: 'Foo' do
1621 # end
1722 class FactoryClassName < Cop
18- MSG = "Pass '%<class_name>s' instead of %<class_name>s."
23+ MSG = "Pass '%<class_name>s' string instead of `%<class_name>s` " \
24+ 'constant.'
1925
2026 def_node_matcher :class_name , <<~PATTERN
2127 (send _ :factory _ (hash <(pair (sym :class) $(const ...)) ...>))
Original file line number Diff line number Diff line change @@ -86,6 +86,11 @@ Enabled | Yes
8686
8787Use string value when setting the class attribute explicitly.
8888
89+ This cop would promote faster tests by lazy-loading of
90+ application files. Also, this could help you suppress potential bugs
91+ in combination with external libraries by avoiding a preload of
92+ application files from the factory files.
93+
8994### Examples
9095
9196``` ruby
Original file line number Diff line number Diff line change 77 it 'flags passing a class' do
88 expect_offense ( <<~RUBY )
99 factory :foo, class: Foo do
10- ^^^ Pass 'Foo' instead of Foo.
10+ ^^^ Pass 'Foo' string instead of ` Foo` constant .
1111 end
1212 RUBY
1313
2020 it 'flags passing a class from global namespace' do
2121 expect_offense ( <<~RUBY )
2222 factory :foo, class: ::Foo do
23- ^^^^^ Pass 'Foo' instead of Foo.
23+ ^^^^^ Pass 'Foo' string instead of ` Foo` constant .
2424 end
2525 RUBY
2626
3333 it 'flags passing a subclass' do
3434 expect_offense ( <<~RUBY )
3535 factory :foo, class: Foo::Bar do
36- ^^^^^^^^ Pass 'Foo::Bar' instead of Foo::Bar.
36+ ^^^^^^^^ Pass 'Foo::Bar' string instead of ` Foo::Bar` constant .
3737 end
3838 RUBY
3939
5555 it 'flags passing a class' do
5656 expect_offense ( <<~RUBY )
5757 factory :foo, class: Foo
58- ^^^ Pass 'Foo' instead of Foo.
58+ ^^^ Pass 'Foo' string instead of ` Foo` constant .
5959 RUBY
6060
6161 expect_correction ( <<~RUBY )
You can’t perform that action at this time.
0 commit comments