zeisler/active_mocker

View on GitHub
lib/active_mocker/mock/base.rb

Summary

Maintainability
B
5 hrs
Test Coverage

Class has too many lines. [195/100]
Open

  class Base
    include DoNothingActiveRecordMethods
    include TemplateMethods
    extend Queries
    extend AliasAttribute
Severity: Minor
Found in lib/active_mocker/mock/base.rb by rubocop

This cop checks if the length a class exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Class Base has 39 methods (exceeds 20 allowed). Consider refactoring.
Open

  class Base
    include DoNothingActiveRecordMethods
    include TemplateMethods
    extend Queries
    extend AliasAttribute
Severity: Minor
Found in lib/active_mocker/mock/base.rb - About 5 hrs to fix

    Assignment Branch Condition size for mock_build_version is too high. [15.33/15] (http://c2.com/cgi/wiki?AbcMetric)
    Open

          def mock_build_version(version, active_record: nil)
            @active_record_build_version = Gem::Version.create(active_record)
            if __active_record_build_version__ >= Gem::Version.create("5.1")
              require "active_mocker/mock/compatibility/base/ar51"
              extend AR51
    Severity: Minor
    Found in lib/active_mocker/mock/base.rb by rubocop

    This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

    Method create has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

          def create(attributes = {}, &block)
            if attributes.is_a?(Array)
              attributes.collect { |attr| create(attr, &block) }
            else
              record = new(id: attributes.delete(:id) || attributes.delete("id"))
    Severity: Minor
    Found in lib/active_mocker/mock/base.rb - About 25 mins to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Avoid using touch because it skips validations. (http://guides.rubyonrails.org/active_record_validations.html#skipping-validations)
    Open

          touch if ActiveMocker::LoadedMocks.features[:timestamps]
    Severity: Minor
    Found in lib/active_mocker/mock/base.rb by rubocop

    This cop checks for the use of methods which skip validations which are listed in http://guides.rubyonrails.org/active_record_validations.html#skipping-validations

    Example:

    # bad
    Article.first.decrement!(:view_count)
    DiscussionBoard.decrement_counter(:post_count, 5)
    Article.first.increment!(:view_count)
    DiscussionBoard.increment_counter(:post_count, 5)
    person.toggle :active
    product.touch
    Billing.update_all("category = 'authorized', author = 'David'")
    user.update_attribute(website: 'example.com')
    user.update_columns(last_request_at: Time.current)
    Post.update_counters 5, comment_count: -1, action_count: 1
    
    # good
    user.update_attributes(website: 'example.com')
    FileUtils.touch('file')

    Avoid using touch because it skips validations. (http://guides.rubyonrails.org/active_record_validations.html#skipping-validations)
    Open

              record.touch(:created_at, :created_on) if ActiveMocker::LoadedMocks.features[:timestamps]
    Severity: Minor
    Found in lib/active_mocker/mock/base.rb by rubocop

    This cop checks for the use of methods which skip validations which are listed in http://guides.rubyonrails.org/active_record_validations.html#skipping-validations

    Example:

    # bad
    Article.first.decrement!(:view_count)
    DiscussionBoard.decrement_counter(:post_count, 5)
    Article.first.increment!(:view_count)
    DiscussionBoard.increment_counter(:post_count, 5)
    person.toggle :active
    product.touch
    Billing.update_all("category = 'authorized', author = 'David'")
    user.update_attribute(website: 'example.com')
    user.update_columns(last_request_at: Time.current)
    Post.update_counters 5, comment_count: -1, action_count: 1
    
    # good
    user.update_attributes(website: 'example.com')
    FileUtils.touch('file')

    Add an empty line after magic comments. (https://github.com/bbatsov/ruby-style-guide#separate-magic-comments-from-code)
    Open

    module ActiveMocker
    Severity: Minor
    Found in lib/active_mocker/mock/base.rb by rubocop

    Checks for a newline after the final magic comment.

    Example:

    # good
    # frozen_string_literal: true
    
    # Some documentation for Person
    class Person
      # Some code
    end
    
    # bad
    # frozen_string_literal: true
    # Some documentation for Person
    class Person
      # Some code
    end

    Unused method argument - arguments. (https://github.com/bbatsov/ruby-style-guide#underscore-unused-vars)
    Open

        def call_mock_method(method:, caller:, arguments: [])
    Severity: Minor
    Found in lib/active_mocker/mock/base.rb by rubocop

    This cop checks for unused method arguments.

    Example:

    # bad
    
    def some_method(used, unused, _unused_but_allowed)
      puts used
    end

    Example:

    # good
    
    def some_method(used, _unused, _unused_but_allowed)
      puts used
    end

    Do not use semicolons to terminate expressions. (https://github.com/bbatsov/ruby-style-guide#no-semicolon)
    Open

          @attributes.freeze; self
    Severity: Minor
    Found in lib/active_mocker/mock/base.rb by rubocop

    This cop checks for multiple expressions placed on the same line. It also checks for lines terminated with a semicolon.

    Example:

    # bad
    foo = 1; bar = 2;
    baz = 3;
    
    # good
    foo = 1
    bar = 2
    baz = 3

    Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping. (https://github.com/bbatsov/ruby-style-guide#consistent-string-literals)
    Open

          self.class.send(:is_implemented, method, '#', caller)
    Severity: Minor
    Found in lib/active_mocker/mock/base.rb by rubocop

    Checks if uses of quotes match the configured preference.

    Example: EnforcedStyle: single_quotes (default)

    # bad
    "No special symbols"
    "No string interpolation"
    "Just text"
    
    # good
    'No special symbols'
    'No string interpolation'
    'Just text'
    "Wait! What's #{this}!"

    Example: EnforcedStyle: double_quotes

    # bad
    'Just some text'
    'No special chars or interpolation'
    
    # good
    "Just some text"
    "No special chars or interpolation"
    "Every string in #{project} uses double_quotes"

    Rename has_attribute? to attribute?. (https://github.com/bbatsov/ruby-style-guide#bool-methods-qmark)
    Open

        def has_attribute?(attr_name)
    Severity: Minor
    Found in lib/active_mocker/mock/base.rb by rubocop

    This cop makes sure that predicates are named properly.

    Example:

    # bad
    def is_even?(value)
    end
    
    # good
    def even?(value)
    end
    
    # bad
    def has_value?
    end
    
    # good
    def value?
    end

    Surrounding space missing in default value assignment. (https://github.com/bbatsov/ruby-style-guide#spaces-around-equals)
    Open

          def classes(klass, fail_hard=false)
    Severity: Minor
    Found in lib/active_mocker/mock/base.rb by rubocop

    Checks that the equals signs in parameter default assignments have or don't have surrounding space depending on configuration.

    Example:

    # bad
    def some_method(arg1=:default, arg2=nil, arg3=[])
      # do something...
    end
    
    # good
    def some_method(arg1 = :default, arg2 = nil, arg3 = [])
      # do something...
    end

    Useless public access modifier.
    Open

          public
    Severity: Minor
    Found in lib/active_mocker/mock/base.rb by rubocop

    This cop checks for redundant access modifiers, including those with no code, those which are repeated, and leading public modifiers in a class or module body. Conditionally-defined methods are considered as always being defined, and thus access modifiers guarding such methods are not redundant.

    Example:

    class Foo
      public # this is redundant (default access is public)
    
      def method
      end
    
      private # this is not redundant (a method is defined)
      def method2
      end
    
      private # this is redundant (no following methods are defined)
    end

    Example:

    class Foo
      # The following is not redundant (conditionally defined methods are
      # considered as always defining a method)
      private
    
      if condition?
        def method
        end
      end
    
      protected # this is not redundant (method is defined)
    
      define_method(:method2) do
      end
    
      protected # this is redundant (repeated from previous modifier)
    
      [1,2,3].each do |i|
        define_method("foo#{i}") do
        end
      end
    
      # The following is redundant (methods defined on the class'
      # singleton class are not affected by the public modifier)
      public
    
      def self.method3
      end
    end

    Example:

    # Lint/UselessAccessModifier:
    #   ContextCreatingMethods:
    #     - concerning
    require 'active_support/concern'
    class Foo
      concerning :Bar do
        def some_public_method
        end
    
        private
    
        def some_private_method
        end
      end
    
      # this is not redundant because `concerning` created its own context
      private
    
      def some_other_private_method
      end
    end

    Example:

    # Lint/UselessAccessModifier:
    #   MethodCreatingMethods:
    #     - delegate
    require 'active_support/core_ext/module/delegation'
    class Foo
      # this is not redundant because `delegate` creates methods
      private
    
      delegate :method_a, to: :method_b
    end

    Replace class var @@built_types with a class instance var. (https://github.com/bbatsov/ruby-style-guide#no-class-vars)
    Open

            @@built_types       ||= {}
    Severity: Minor
    Found in lib/active_mocker/mock/base.rb by rubocop

    This cop checks for uses of class variables. Offenses are signaled only on assignment to class variables to reduce the number of offenses that would be reported.

    Use %i or %I for an array of symbols. (https://github.com/bbatsov/ruby-style-guide#percent-i)
    Open

          attributes = [:updated_at, :update_on]
    Severity: Minor
    Found in lib/active_mocker/mock/base.rb by rubocop

    This cop can check for array literals made up of symbols that are not using the %i() syntax.

    Alternatively, it checks for symbol arrays using the %i() syntax on projects which do not want to use that syntax.

    Configuration option: MinSize If set, arrays with fewer elements than this value will not trigger the cop. For example, a MinSize of3` will not enforce a style on an array of 2 or fewer elements.

    Example: EnforcedStyle: percent (default)

    # good
    %i[foo bar baz]
    
    # bad
    [:foo, :bar, :baz]

    Example: EnforcedStyle: brackets

    # good
    [:foo, :bar, :baz]
    
    # bad
    %i[foo bar baz]

    Line is too long. [128/120] (https://github.com/bbatsov/ruby-style-guide#80-character-limits)
    Open

        # Returns +true+ if the specified +attribute+ has been set and is neither +nil+ nor <tt>empty?</tt> (the latter only applies
    Severity: Minor
    Found in lib/active_mocker/mock/base.rb by rubocop

    Use a guard clause instead of wrapping the code inside a conditional expression. (https://github.com/bbatsov/ruby-style-guide#no-nested-conditionals)
    Open

          if respond_to?("#{k}=")
    Severity: Minor
    Found in lib/active_mocker/mock/base.rb by rubocop

    Use a guard clause instead of wrapping the code inside a conditional expression

    Example:

    # bad
    def test
      if something
        work
      end
    end
    
    # good
    def test
      return unless something
      work
    end
    
    # also good
    def test
      work if something
    end
    
    # bad
    if something
      raise 'exception'
    else
      ok
    end
    
    # good
    raise 'exception' if something
    ok

    There are no issues that match your filters.

    Category
    Status