rspec/rspec-mocks

View on GitHub

Showing 34 of 34 total issues

Class MessageExpectation has 58 methods (exceeds 20 allowed). Consider refactoring.

    class MessageExpectation
      # @!group Configuring Responses

      # @overload and_return(value)
      # @overload and_return(first_value, second_value)
Severity: Major
Found in lib/rspec/mocks/message_expectation.rb - About 1 day to fix

    Class ErrorGenerator has 48 methods (exceeds 20 allowed). Consider refactoring.

        class ErrorGenerator
          attr_writer :opts
    
          def initialize(target=nil)
            @target = target
    Severity: Minor
    Found in lib/rspec/mocks/error_generator.rb - About 6 hrs to fix

      File message_expectation.rb has 441 lines of code (exceeds 250 allowed). Consider refactoring.

      RSpec::Support.require_rspec_support 'mutex'
      
      module RSpec
        module Mocks
          # A message expectation that only allows concrete return values to be set
      Severity: Minor
      Found in lib/rspec/mocks/message_expectation.rb - About 6 hrs to fix

        Class Proxy has 34 methods (exceeds 20 allowed). Consider refactoring.

            class Proxy
              # @private
              SpecificMessage = Struct.new(:object, :message, :args) do
                def ==(expectation)
                  expectation.orig_object == object && expectation.matches?(message, *args)
        Severity: Minor
        Found in lib/rspec/mocks/proxy.rb - About 4 hrs to fix

          File proxy.rb has 340 lines of code (exceeds 250 allowed). Consider refactoring.

          module RSpec
            module Mocks
              # @private
              class Proxy
                # @private
          Severity: Minor
          Found in lib/rspec/mocks/proxy.rb - About 4 hrs to fix

            Class MethodDouble has 30 methods (exceeds 20 allowed). Consider refactoring.

                class MethodDouble
                  # @private
                  attr_reader :method_name, :object, :expectations, :stubs, :method_stasher
            
                  # @private
            Severity: Minor
            Found in lib/rspec/mocks/method_double.rb - About 3 hrs to fix

              Class Recorder has 29 methods (exceeds 20 allowed). Consider refactoring.

                    class Recorder
                      # @private
                      attr_reader :message_chains, :stubs, :klass
              
                      def initialize(klass)
              Severity: Minor
              Found in lib/rspec/mocks/any_instance/recorder.rb - About 3 hrs to fix

                Method message_received has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.

                      def message_received(message, *args, &block)
                        record_message_received message, *args, &block
                
                        expectation = find_matching_expectation(message, *args)
                        stub = find_matching_method_stub(message, *args)
                Severity: Minor
                Found in lib/rspec/mocks/proxy.rb - About 3 hrs 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

                Class HaveReceived has 22 methods (exceeds 20 allowed). Consider refactoring.

                      class HaveReceived
                        include Matcher
                
                        COUNT_CONSTRAINTS = %w[exactly at_least at_most times time once twice thrice]
                        ARGS_CONSTRAINTS = %w[with]
                Severity: Minor
                Found in lib/rspec/mocks/matchers/have_received.rb - About 2 hrs to fix

                  File error_generator.rb has 262 lines of code (exceeds 250 allowed). Consider refactoring.

                  RSpec::Support.require_rspec_support "object_formatter"
                  
                  module RSpec
                    module Mocks
                      # Raised when a message expectation is not satisfied.
                  Severity: Minor
                  Found in lib/rspec/mocks/error_generator.rb - About 2 hrs to fix

                    Method enable_should has 49 lines of code (exceeds 25 allowed). Consider refactoring.

                          def self.enable_should(syntax_host=default_should_syntax_host)
                            @warn_about_should = false if syntax_host == default_should_syntax_host
                            return if should_enabled?(syntax_host)
                    
                            syntax_host.class_exec do
                    Severity: Minor
                    Found in lib/rspec/mocks/syntax.rb - About 1 hr to fix

                      Method replay_received_message_on has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.

                            def replay_received_message_on(expectation, &block)
                              expected_method_name = expectation.message
                              meth_double = method_double_for(expected_method_name)
                      
                              if meth_double.expectations.any?
                      Severity: Minor
                      Found in lib/rspec/mocks/proxy.rb - About 1 hr 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

                      Method verify_constants_to_transfer! has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.

                              def verify_constants_to_transfer!
                                return [] unless should_transfer_nested_constants?
                      
                                { @original_value => "the original value", @mutated_value => "the stubbed value" }.each do |value, description|
                                  next if value.respond_to?(:constants)
                      Severity: Minor
                      Found in lib/rspec/mocks/mutate_const.rb - About 1 hr 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

                      Method enable_expect has 28 lines of code (exceeds 25 allowed). Consider refactoring.

                            def self.enable_expect(syntax_host=::RSpec::Mocks::ExampleMethods)
                              return if expect_enabled?(syntax_host)
                      
                              syntax_host.class_exec do
                                def receive(method_name, &block)
                      Severity: Minor
                      Found in lib/rspec/mocks/syntax.rb - About 1 hr to fix

                        Method call has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.

                              def call(*_args_to_ignore, &block)
                                return if @args_to_yield.empty? && @eval_context.nil?
                        
                                @error_generator.raise_missing_block_error @args_to_yield unless block
                                value = nil
                        Severity: Minor
                        Found in lib/rspec/mocks/message_expectation.rb - About 1 hr 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

                        Method original_method_handle_for has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.

                              def original_method_handle_for(message)
                                unbound_method = superclass_proxy &&
                                  superclass_proxy.original_unbound_method_handle_from_ancestor_for(message.to_sym)
                        
                                return super unless unbound_method
                        Severity: Minor
                        Found in lib/rspec/mocks/proxy.rb - About 1 hr 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

                        Method raise_expectation_error has 8 arguments (exceeds 4 allowed). Consider refactoring.

                              def raise_expectation_error(message, expected_received_count, argument_list_matcher,
                                                          actual_received_count, expectation_count_type, args,
                                                          backtrace_line=nil, source_id=nil)
                        Severity: Major
                        Found in lib/rspec/mocks/error_generator.rb - About 1 hr to fix

                          Method initialize has 7 arguments (exceeds 4 allowed). Consider refactoring.

                                  def initialize(error_generator, expectation_ordering, expected_from, method_double,
                                                 type=:expectation, opts={}, &implementation_block)
                          Severity: Major
                          Found in lib/rspec/mocks/message_expectation.rb - About 50 mins to fix

                            Method find_best_matching_expectation_for has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.

                                  def find_best_matching_expectation_for(method_name)
                                    first_match = nil
                            
                                    method_double_for(method_name).expectations.each do |expectation|
                                      next unless yield expectation
                            Severity: Minor
                            Found in lib/rspec/mocks/proxy.rb - About 45 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

                            Method invoke_incrementing_actual_calls_by has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.

                                    def invoke_incrementing_actual_calls_by(increment, allowed_to_fail, parent_stub, *args, &block)
                                      args.unshift(orig_object) if yield_receiver_to_implementation_block?
                            
                                      if negative? || (allowed_to_fail && (@exactly || @at_most) && (@actual_received_count == @expected_received_count))
                                        # args are the args we actually received, @argument_list_matcher is the
                            Severity: Minor
                            Found in lib/rspec/mocks/message_expectation.rb - About 45 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

                            Method setup_simple_method_double has 5 arguments (exceeds 4 allowed). Consider refactoring.

                                  def setup_simple_method_double(method_name, response, collection, error_generator=nil, backtrace_line=nil)
                            Severity: Minor
                            Found in lib/rspec/mocks/method_double.rb - About 35 mins to fix

                              Method invoke_incrementing_actual_calls_by has 5 arguments (exceeds 4 allowed). Consider refactoring.

                                      def invoke_incrementing_actual_calls_by(increment, allowed_to_fail, parent_stub, *args, &block)
                              Severity: Minor
                              Found in lib/rspec/mocks/message_expectation.rb - About 35 mins to fix

                                Method add_stub has 5 arguments (exceeds 4 allowed). Consider refactoring.

                                      def add_stub(error_generator, expectation_ordering, expected_from, opts={}, &implementation)
                                Severity: Minor
                                Found in lib/rspec/mocks/method_double.rb - About 35 mins to fix

                                  Method add_expectation has 5 arguments (exceeds 4 allowed). Consider refactoring.

                                        def add_expectation(error_generator, expectation_ordering, expected_from, opts, &implementation)
                                  Severity: Minor
                                  Found in lib/rspec/mocks/method_double.rb - About 35 mins to fix

                                    Method describe_expectation has 5 arguments (exceeds 4 allowed). Consider refactoring.

                                          def describe_expectation(verb, message, expected_received_count, _actual_received_count, args)
                                    Severity: Minor
                                    Found in lib/rspec/mocks/error_generator.rb - About 35 mins to fix

                                      Method for has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.

                                            def self.for(object_module_or_name, allow_direct_object_refs=false)
                                              case object_module_or_name
                                              when Module
                                                if anonymous_module?(object_module_or_name)
                                                  DirectObjectReference.new(object_module_or_name)
                                      Severity: Minor
                                      Found in lib/rspec/mocks/object_reference.rb - About 35 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

                                      Method raise_unimplemented_error has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.

                                            def raise_unimplemented_error(doubled_module, method_name, object)
                                              message = case object
                                                        when InstanceVerifyingDouble
                                                          "the %s class does not implement the instance method: %s".dup <<
                                                            if ObjectMethodReference.for(doubled_module, method_name).implemented?
                                      Severity: Minor
                                      Found in lib/rspec/mocks/error_generator.rb - About 35 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

                                      Method check_for_unexpected_arguments has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.

                                            def check_for_unexpected_arguments(expectation)
                                              @messages_received_mutex.synchronize do
                                                return if @messages_received.empty?
                                      
                                                return if @messages_received.any? { |method_name, args, _| expectation.matches?(method_name, *args) }
                                      Severity: Minor
                                      Found in lib/rspec/mocks/proxy.rb - About 35 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

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

                                            def method_missing(message, *args, &block)
                                              proxy = __mock_proxy
                                              proxy.record_message_received(message, *args, &block)
                                      
                                              if proxy.null_object?
                                      Severity: Minor
                                      Found in lib/rspec/mocks/test_double.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

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

                                              def usable_rspec_prepended_module
                                                @proxy.prepended_modules_of_singleton_class.each do |mod|
                                                  # If we have one of our modules prepended before one of the user's
                                                  # modules that defines the method, use that, since our module's
                                                  # definition will take precedence.
                                      Severity: Minor
                                      Found in lib/rspec/mocks/method_double.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

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

                                            def self.default_should_syntax_host
                                              # JRuby 1.7.4 introduces a regression whereby `defined?(::BasicObject) => nil`
                                              # yet `BasicObject` still exists and patching onto ::Object breaks things
                                              # e.g. SimpleDelegator expectations won't work
                                              #
                                      Severity: Minor
                                      Found in lib/rspec/mocks/syntax.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

                                      Method observe! has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.

                                              def observe!(method_name)
                                                allow_no_prepended_module_definition_of(method_name)
                                      
                                                if RSpec::Mocks.configuration.verify_partial_doubles? && !Mocks.configuration.temporarily_suppress_partial_double_verification
                                                  unless public_protected_or_private_method_defined?(method_name)
                                      Severity: Minor
                                      Found in lib/rspec/mocks/any_instance/recorder.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

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

                                            def setup_chain
                                              if chain.length > 1
                                                if (matching_stub = find_matching_stub)
                                                  chain.shift
                                                  chain_on(matching_stub.invoke(nil), *chain, &@block)
                                      Severity: Minor
                                      Found in lib/rspec/mocks/message_chain.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

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

                                            def and_return(first_value, *values)
                                              raise_already_invoked_error_if_necessary(__method__)
                                              if negative?
                                                raise "`and_return` is not supported with negative message expectations"
                                              end
                                      Severity: Minor
                                      Found in lib/rspec/mocks/message_expectation.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

                                      Severity
                                      Category