Skip to content

Fix some remaining cop offenses for go module factories

Peter Leitzen requested to merge pl-spec-factories-go-module into master

What does this MR do?

This commit also removes the unused (and broken) factory trait :pseudo for the factory :go_module_version.

Contributes to #267606 (closed) and #322699 (closed).

Offenses

While at it, the following (hidden by default) RuboCop offenses has also been fixed:

$ REVEAL_RUBOCOP_TODO=1 bundle exec rubocop spec/factories/go_module_commits.rb spec/factories/go_module_versions.rb spec/factories/go_modules.rb spec/factories_spec.rb | xcopy

Inspecting 4 files
CCCC

Offenses:

spec/factories/go_module_commits.rb:10:17: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
      project { create(:project, :repository) }
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/factories/go_module_commits.rb:47:17: C: Style/RaiseArgs: Provide an exception class and message as arguments to raise.
        files { raise ArgumentError.new("files is required") }
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/factories/go_module_commits.rb:54:16: C: Style/RaiseArgs: Provide an exception class and message as arguments to raise.
        path { raise ArgumentError.new("path is required") }
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/factories/go_module_commits.rb:67:16: C: Style/StringConcatenation: Prefer string interpolation to string concatenation.
        path { name.to_s + '/' }
               ^^^^^^^^^^^^^^^
spec/factories/go_module_versions.rb:11:7: C: Style/RaiseArgs: Provide an exception class and message as arguments to raise.
      raise ArgumentError.new("invalid sematic version: '#{p.semver}''") if !s && p.semver
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/factories/go_module_versions.rb:16:11: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
    mod { create :go_module }
          ^^^^^^^^^^^^^^^^^
spec/factories/go_module_versions.rb:36:28: C: Style/RedundantInterpolation: Prefer to_s over string interpolation.
          .max    { |a, b| "#{a}" <=> "#{b}" }
                           ^^^^^^
spec/factories/go_module_versions.rb:36:39: C: Style/RedundantInterpolation: Prefer to_s over string interpolation.
          .max    { |a, b| "#{a}" <=> "#{b}" }
                                      ^^^^^^
spec/factories/go_module_versions.rb:56:30: C: Style/RedundantInterpolation: Prefer to_s over string interpolation.
            .max    { |a, b| "#{a}" <=> "#{b}" }
                             ^^^^^^
spec/factories/go_module_versions.rb:56:41: C: Style/RedundantInterpolation: Prefer to_s over string interpolation.
            .max    { |a, b| "#{a}" <=> "#{b}" }
                                        ^^^^^^
spec/factories/go_modules.rb:8:15: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
    project { create :project, :repository }
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/factories_spec.rb:49:18: C: Rails/SaveBang: Use create! instead of create if the return value is not checked.
        expect { create(factory.name) }.not_to raise_error
                 ^^^^^^
spec/factories_spec.rb:55:66: C: Style/IfUnlessModifier: Modifier form of if makes the line too long.
            pending("Trait skipped linting due to legacy error") if skipped_traits.include?([factory.name, trait_name.to_sym])
                                                                 ^^
spec/factories_spec.rb:55:121: C: Layout/LineLength: Line is too long. [126/120]
            pending("Trait skipped linting due to legacy error") if skipped_traits.include?([factory.name, trait_name.to_sym])
                                                                                                                        ^^^^^^

4 files inspected, 14 offenses detected, 14 offenses auto-correctable

See https://docs.gitlab.com/ee/development/contributing/style_guides.html#reveal-existing-rubocop-exceptions.

Does this MR meet the acceptance criteria?

Conformity

Edited by Peter Leitzen

Merge request reports