diff --git a/.rubocop.yml b/.rubocop.yml index d62b7f2..65e4510 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,5 +1,8 @@ inherit_from: - https://raw.githubusercontent.com/thoughtbot/guides/master/style/ruby/.rubocop.yml +AllCops: + Exclude: + - 'gemfiles/*' # TODO: # This configuration was generated by @@ -10,91 +13,6 @@ inherit_from: # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 4 -# Cop supports --auto-correct. -# Configuration parameters: Include, TreatCommentsAsGroupSeparators. -# Include: **/*.gemfile, **/Gemfile, **/gems.rb -Bundler/OrderedGems: - Exclude: - - 'gemfiles/4.2.gemfile' - - 'gemfiles/5.0.gemfile' - - 'gemfiles/5.1.gemfile' - - 'gemfiles/5.2.gemfile' - -# Offense count: 1 -# Cop supports --auto-correct. -Layout/ElseAlignment: - Exclude: - - 'lib/factory_bot/factory.rb' - -# Offense count: 3 -# Cop supports --auto-correct. -# Configuration parameters: AllowAdjacentOneLineDefs, NumberOfEmptyLines. -Layout/EmptyLineBetweenDefs: - Exclude: - - 'lib/factory_bot/null_factory.rb' - -# Offense count: 8 -# Cop supports --auto-correct. -Layout/EmptyLinesAroundAccessModifier: - Exclude: - - 'lib/factory_bot/callback.rb' - - 'lib/factory_bot/declaration.rb' - - 'lib/factory_bot/declaration/association.rb' - - 'lib/factory_bot/declaration/dynamic.rb' - - 'lib/factory_bot/declaration/implicit.rb' - - 'lib/factory_bot/trait.rb' - - 'spec/acceptance/attribute_existing_on_object_spec.rb' - - 'spec/acceptance/private_attributes_spec.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: empty_lines, no_empty_lines -Layout/EmptyLinesAroundBlockBody: - Exclude: - - 'spec/acceptance/activesupport_instrumentation_spec.rb' - - 'spec/factory_bot/definition_proxy_spec.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines, beginning_only, ending_only -Layout/EmptyLinesAroundClassBody: - Exclude: - - 'lib/factory_bot/linter.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines -Layout/EmptyLinesAroundModuleBody: - Exclude: - - 'lib/factory_bot/sequence.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyleAlignWith, AutoCorrect, Severity. -# SupportedStylesAlignWith: keyword, variable, start_of_line -Layout/EndAlignment: - Exclude: - - 'lib/factory_bot/factory.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: AllowForAlignment, ForceEqualSignAlignment. -Layout/ExtraSpacing: - Exclude: - - 'spec/acceptance/attribute_existing_on_object_spec.rb' - - 'spec/acceptance/parent_spec.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: IndentationWidth. -Layout/IndentAssignment: - Exclude: - - 'lib/factory_bot/linter.rb' - # Offense count: 3 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle. @@ -104,51 +22,6 @@ Layout/IndentHeredoc: - 'lib/factory_bot/linter.rb' - 'spec/acceptance/lint_spec.rb' -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: Width, IgnoredPatterns. -Layout/IndentationWidth: - Exclude: - - 'lib/factory_bot/factory.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -Layout/LeadingCommentSpace: - Exclude: - - 'spec/acceptance/parent_spec.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: space, no_space -Layout/SpaceAroundEqualsInParameterDefault: - Exclude: - - 'lib/factory_bot/null_object.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBrackets. -# SupportedStyles: space, no_space, compact -# SupportedStylesForEmptyBrackets: space, no_space -Layout/SpaceInsideArrayLiteralBrackets: - Exclude: - - 'spec/acceptance/traits_spec.rb' - -# Offense count: 8 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters. -# SupportedStyles: space, no_space -# SupportedStylesForEmptyBraces: space, no_space -Layout/SpaceInsideBlockBraces: - Exclude: - - 'lib/factory_bot/attribute.rb' - - 'lib/factory_bot/definition.rb' - - 'spec/acceptance/parent_spec.rb' - - 'spec/acceptance/traits_spec.rb' - - 'spec/acceptance/transient_attributes_spec.rb' - - 'spec/factory_bot/attribute/dynamic_spec.rb' - - 'spec/factory_bot/definition_proxy_spec.rb' - # Offense count: 1 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyleForEmptyBraces. @@ -157,20 +30,6 @@ Layout/SpaceInsideBlockBraces: Layout/SpaceInsideHashLiteralBraces: EnforcedStyle: space -# Offense count: 1 -# Cop supports --auto-correct. -Layout/SpaceInsideParens: - Exclude: - - 'spec/factory_bot/attribute/dynamic_spec.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: final_newline, final_blank_line -Layout/TrailingBlankLines: - Exclude: - - 'Rakefile' - # Offense count: 1 Lint/RescueException: Exclude: @@ -293,10 +152,6 @@ Style/FormatStringToken: Style/HashSyntax: Exclude: - 'Rakefile' - - 'gemfiles/4.2.gemfile' - - 'gemfiles/5.0.gemfile' - - 'gemfiles/5.1.gemfile' - - 'gemfiles/5.2.gemfile' - 'spec/acceptance/build_stubbed_spec.rb' - 'spec/acceptance/nested_attributes_spec.rb' - 'spec/acceptance/transient_attributes_spec.rb' diff --git a/Rakefile b/Rakefile index a55a5f0..9f10af8 100644 --- a/Rakefile +++ b/Rakefile @@ -33,4 +33,3 @@ end YARD::Rake::YardocTask.new do |t| end - diff --git a/lib/factory_bot/attribute.rb b/lib/factory_bot/attribute.rb index f878679..6cf0754 100644 --- a/lib/factory_bot/attribute.rb +++ b/lib/factory_bot/attribute.rb @@ -14,7 +14,7 @@ module FactoryBot end def to_proc - -> { } + -> {} end def association? diff --git a/lib/factory_bot/callback.rb b/lib/factory_bot/callback.rb index fce422c..80c9dcb 100644 --- a/lib/factory_bot/callback.rb +++ b/lib/factory_bot/callback.rb @@ -22,6 +22,7 @@ module FactoryBot end protected + attr_reader :block private diff --git a/lib/factory_bot/declaration.rb b/lib/factory_bot/declaration.rb index 1e05ce7..bd39558 100644 --- a/lib/factory_bot/declaration.rb +++ b/lib/factory_bot/declaration.rb @@ -17,6 +17,7 @@ module FactoryBot end protected + attr_reader :ignored end end diff --git a/lib/factory_bot/declaration/association.rb b/lib/factory_bot/declaration/association.rb index cbe4d2f..4407a73 100644 --- a/lib/factory_bot/declaration/association.rb +++ b/lib/factory_bot/declaration/association.rb @@ -15,6 +15,7 @@ module FactoryBot end protected + attr_reader :options private diff --git a/lib/factory_bot/declaration/dynamic.rb b/lib/factory_bot/declaration/dynamic.rb index ec05dfb..3446a9e 100644 --- a/lib/factory_bot/declaration/dynamic.rb +++ b/lib/factory_bot/declaration/dynamic.rb @@ -14,6 +14,7 @@ module FactoryBot end protected + attr_reader :block private diff --git a/lib/factory_bot/declaration/implicit.rb b/lib/factory_bot/declaration/implicit.rb index e08532c..a69b7e5 100644 --- a/lib/factory_bot/declaration/implicit.rb +++ b/lib/factory_bot/declaration/implicit.rb @@ -14,6 +14,7 @@ module FactoryBot end protected + attr_reader :factory private diff --git a/lib/factory_bot/definition.rb b/lib/factory_bot/definition.rb index b303f26..4f05cf1 100644 --- a/lib/factory_bot/definition.rb +++ b/lib/factory_bot/definition.rb @@ -74,7 +74,7 @@ module FactoryBot end def skip_create - @to_create = ->(instance) { } + @to_create = ->(instance) {} end def define_trait(trait) diff --git a/lib/factory_bot/factory.rb b/lib/factory_bot/factory.rb index 7aa05ad..71b6c40 100644 --- a/lib/factory_bot/factory.rb +++ b/lib/factory_bot/factory.rb @@ -21,10 +21,10 @@ module FactoryBot def build_class @build_class ||= if class_name.is_a? Class - class_name - else - class_name.to_s.camelize.constantize - end + class_name + else + class_name.to_s.camelize.constantize + end end def run(build_strategy, overrides, &block) diff --git a/lib/factory_bot/linter.rb b/lib/factory_bot/linter.rb index ecde3d8..a83118f 100644 --- a/lib/factory_bot/linter.rb +++ b/lib/factory_bot/linter.rb @@ -1,6 +1,5 @@ module FactoryBot class Linter - def initialize(factories, linting_strategy, factory_strategy = :create) @factories_to_lint = factories @linting_method = "lint_#{linting_strategy}" @@ -70,7 +69,7 @@ module FactoryBot FactoryBot.public_send(factory_strategy, factory.name, trait_name) rescue => error result |= - [FactoryTraitError.new(error, factory, trait_name)] + [FactoryTraitError.new(error, factory, trait_name)] end end result diff --git a/lib/factory_bot/null_factory.rb b/lib/factory_bot/null_factory.rb index bc9720d..e22bab0 100644 --- a/lib/factory_bot/null_factory.rb +++ b/lib/factory_bot/null_factory.rb @@ -11,8 +11,11 @@ module FactoryBot :to_create, to: :definition def compile; end + def class_name; end + def evaluator_class; FactoryBot::Evaluator; end + def hierarchy_class; FactoryBot::DefinitionHierarchy; end end end diff --git a/lib/factory_bot/null_object.rb b/lib/factory_bot/null_object.rb index c576b7f..91dd961 100644 --- a/lib/factory_bot/null_object.rb +++ b/lib/factory_bot/null_object.rb @@ -13,7 +13,7 @@ module FactoryBot end end - def respond_to?(method, include_private=false) + def respond_to?(method, include_private = false) @methods_to_respond_to.include? method.to_s end diff --git a/lib/factory_bot/sequence.rb b/lib/factory_bot/sequence.rb index 26a39d9..31648a4 100644 --- a/lib/factory_bot/sequence.rb +++ b/lib/factory_bot/sequence.rb @@ -1,5 +1,4 @@ module FactoryBot - # Sequences are defined using sequence within a FactoryBot.define block. # Sequence values are generated using next. # @api private diff --git a/lib/factory_bot/trait.rb b/lib/factory_bot/trait.rb index 84bc323..f71e5ac 100644 --- a/lib/factory_bot/trait.rb +++ b/lib/factory_bot/trait.rb @@ -25,6 +25,7 @@ module FactoryBot end protected + attr_reader :block end end diff --git a/spec/acceptance/activesupport_instrumentation_spec.rb b/spec/acceptance/activesupport_instrumentation_spec.rb index 8290898..f592c14 100644 --- a/spec/acceptance/activesupport_instrumentation_spec.rb +++ b/spec/acceptance/activesupport_instrumentation_spec.rb @@ -24,7 +24,6 @@ describe "using ActiveSupport::Instrumentation to track factory interaction" do after(:build) { Kernel.sleep(0.1) } end end - end end diff --git a/spec/acceptance/attribute_existing_on_object_spec.rb b/spec/acceptance/attribute_existing_on_object_spec.rb index 9cf92f5..1ea429b 100644 --- a/spec/acceptance/attribute_existing_on_object_spec.rb +++ b/spec/acceptance/attribute_existing_on_object_spec.rb @@ -20,10 +20,11 @@ end describe "assigning overrides that are also private methods on object" do before do - define_model("Website", format: :string, y: :integer, more_format: :string, some_funky_method: :string) + define_model("Website", format: :string, y: :integer, more_format: :string, some_funky_method: :string) Object.class_eval do private + def some_funky_method(args) end end diff --git a/spec/acceptance/parent_spec.rb b/spec/acceptance/parent_spec.rb index 9e79211..1512cc0 100644 --- a/spec/acceptance/parent_spec.rb +++ b/spec/acceptance/parent_spec.rb @@ -23,7 +23,7 @@ describe "an instance generated by a factory that inherits from another factory" end factory :bill do - name { "Bill" } #block to make attribute dynamic + name { "Bill" } # block to make attribute dynamic end end end @@ -41,7 +41,7 @@ describe "an instance generated by a factory that inherits from another factory" it { should be_admin } its(:name) { should eq "admin" } its(:email) { should eq "admin@example.com" } - its(:upper_email) { should eq "ADMIN@EXAMPLE.COM"} + its(:upper_email) { should eq "ADMIN@EXAMPLE.COM" } end describe "the child class redefining parent's dynamic method" do diff --git a/spec/acceptance/private_attributes_spec.rb b/spec/acceptance/private_attributes_spec.rb index eb121bb..f704b0a 100644 --- a/spec/acceptance/private_attributes_spec.rb +++ b/spec/acceptance/private_attributes_spec.rb @@ -2,6 +2,7 @@ describe 'setting private attributes' do it 'raises a NoMethodError' do define_class('User') do private + attr_accessor :foo end diff --git a/spec/acceptance/traits_spec.rb b/spec/acceptance/traits_spec.rb index 8adec52..b538200 100644 --- a/spec/acceptance/traits_spec.rb +++ b/spec/acceptance/traits_spec.rb @@ -141,7 +141,7 @@ describe "an instance generated by a factory with multiple traits" do context "factory using global trait" do subject { FactoryBot.create(:user_with_email) } its(:name) { should eq "Bill" } - its(:email) { should eq "Bill@example.com"} + its(:email) { should eq "Bill@example.com" } end context "factory created with alternate syntax for specifying trait" do @@ -333,7 +333,7 @@ describe "applying inline traits" do FactoryBot.define do factory :user do trait :with_post do - posts { [ Post.new ] } + posts { [Post.new] } end end end diff --git a/spec/acceptance/transient_attributes_spec.rb b/spec/acceptance/transient_attributes_spec.rb index a9729c3..9bbdde3 100644 --- a/spec/acceptance/transient_attributes_spec.rb +++ b/spec/acceptance/transient_attributes_spec.rb @@ -105,7 +105,7 @@ describe "assigning values from a transient attribute" do FactoryBot.define do factory :user do transient do - foo { Foo.new('id-of-foo', 'name-of-foo')} + foo { Foo.new('id-of-foo', 'name-of-foo') } end foo_id { foo.id } diff --git a/spec/factory_bot/attribute/dynamic_spec.rb b/spec/factory_bot/attribute/dynamic_spec.rb index 9512a50..bfc9527 100644 --- a/spec/factory_bot/attribute/dynamic_spec.rb +++ b/spec/factory_bot/attribute/dynamic_spec.rb @@ -1,6 +1,6 @@ describe FactoryBot::Attribute::Dynamic do let(:name) { :first_name } - let(:block) { -> { } } + let(:block) { -> {} } subject { FactoryBot::Attribute::Dynamic.new(name, false, block) } @@ -54,6 +54,6 @@ describe FactoryBot::Attribute::Dynamic do end describe FactoryBot::Attribute::Dynamic, "with a string name" do - subject { FactoryBot::Attribute::Dynamic.new("name", false, -> { } ) } + subject { FactoryBot::Attribute::Dynamic.new("name", false, -> {}) } its(:name) { should eq :name } end diff --git a/spec/factory_bot/definition_proxy_spec.rb b/spec/factory_bot/definition_proxy_spec.rb index d3dd5af..52e0ca2 100644 --- a/spec/factory_bot/definition_proxy_spec.rb +++ b/spec/factory_bot/definition_proxy_spec.rb @@ -63,7 +63,6 @@ describe FactoryBot::DefinitionProxy, "#method_missing" do end describe FactoryBot::DefinitionProxy, "#sequence" do - before do allow(FactoryBot::Sequence).to receive(:new).and_call_original end @@ -179,7 +178,7 @@ describe FactoryBot::DefinitionProxy, "#factory" do end it "with a block" do - child_block = -> { } + child_block = -> {} proxy.factory(:child, {}, &child_block) expect(proxy.child_factories).to include([:child, {}, child_block]) end