Class: RSpec::Mocks::ErrorGenerator

### Home Classes Methods

### In Files

- lib/rspec/mocks/error_generator.rb

### Parent

Object

### Methods

- ::new
- ::raise_double_negation_error
- #actual_method_call_args_description
- #default_error_message
- #describe_expectation
- #expected_method_call_args_description
- #expected_part_of_expectation_error
- #method_call_args_description
- #opts
- #raise_block_failed_error
- #raise_expectation_error
- #raise_expectation_on_mocked_method
- #raise_expectation_on_unstubbed_method
- #raise_expired_test_double_error
- #raise_invalid_arguments_error
- #raise_missing_block_error
- #raise_missing_default_stub_error
- #raise_non_public_error
- #raise_only_valid_on_a_partial_double
- #raise_out_of_order_error
- #raise_similar_message_args_error
- #raise_unexpected_message_args_error
- #raise_unexpected_message_error
- #raise_unimplemented_error
- #raise_wrong_arity_error
- #received_part_of_expectation_error

### Class/Module Index

Quicksearch

- RSpec
- RSpec::Mocks
- RSpec::Mocks::AllowanceTarget
- RSpec::Mocks::AndReturnImplementation
- RSpec::Mocks::AndWrapOriginalImplementation
- RSpec::Mocks::AndYieldImplementation
- RSpec::Mocks::AnyInstance
- RSpec::Mocks::AnyInstance::Chain
- RSpec::Mocks::AnyInstance::Chain::Customizations
- RSpec::Mocks::AnyInstance::ExpectChainChain
- RSpec::Mocks::AnyInstance::ExpectationChain
- RSpec::Mocks::AnyInstance::FluentInterfaceProxy
- RSpec::Mocks::AnyInstance::MessageChains
- RSpec::Mocks::AnyInstance::PositiveExpectationChain
- RSpec::Mocks::AnyInstance::Proxy
- RSpec::Mocks::AnyInstance::Recorder
- RSpec::Mocks::AnyInstance::StubChain
- RSpec::Mocks::AnyInstance::StubChainChain
- RSpec::Mocks::AnyInstanceAllowanceTarget
- RSpec::Mocks::AnyInstanceExpectationTarget
- RSpec::Mocks::ArgumentListMatcher
- RSpec::Mocks::ArgumentMatchers
- RSpec::Mocks::ArgumentMatchers::AnyArgMatcher
- RSpec::Mocks::ArgumentMatchers::AnyArgsMatcher
- RSpec::Mocks::ArgumentMatchers::ArrayIncludingMatcher
- RSpec::Mocks::ArgumentMatchers::BaseHashMatcher
- RSpec::Mocks::ArgumentMatchers::BooleanMatcher
- RSpec::Mocks::ArgumentMatchers::DuckTypeMatcher
- RSpec::Mocks::ArgumentMatchers::HashExcludingMatcher
- RSpec::Mocks::ArgumentMatchers::HashIncludingMatcher
- RSpec::Mocks::ArgumentMatchers::InstanceOf
- RSpec::Mocks::ArgumentMatchers::KindOf
- RSpec::Mocks::ArgumentMatchers::NoArgsMatcher
- RSpec::Mocks::ArgumentMatchers::SingletonMatcher
- RSpec::Mocks::ClassVerifyingDouble
- RSpec::Mocks::Configuration
- RSpec::Mocks::Constant
- RSpec::Mocks::ConstantMutator
- RSpec::Mocks::ConstantMutator::BaseMutator
- RSpec::Mocks::ConstantMutator::ConstantHider
- RSpec::Mocks::ConstantMutator::DefinedConstantReplacer
- RSpec::Mocks::ConstantMutator::UndefinedConstantSetter
- RSpec::Mocks::DirectObjectReference
- RSpec::Mocks::Double
- RSpec::Mocks::ErrorGenerator
- RSpec::Mocks::ExampleMethods
- RSpec::Mocks::ExampleMethods::ExpectHost
- RSpec::Mocks::ExpectChain
- RSpec::Mocks::ExpectationTarget
- RSpec::Mocks::Implementation
- RSpec::Mocks::InsertOntoBacktrace
- RSpec::Mocks::InstanceMethodReference
- RSpec::Mocks::InstanceMethodStasher
- RSpec::Mocks::InstanceVerifyingDouble
- RSpec::Mocks::MarshalExtension
- RSpec::Mocks::Matchers
- RSpec::Mocks::Matchers::ExpectationCustomization
- RSpec::Mocks::Matchers::HaveReceived
- RSpec::Mocks::Matchers::Receive
- RSpec::Mocks::Matchers::Receive::DefaultDescribable
- RSpec::Mocks::Matchers::ReceiveMessageChain
- RSpec::Mocks::Matchers::ReceiveMessages
- RSpec::Mocks::MessageChain
- RSpec::Mocks::MessageExpectation
- RSpec::Mocks::MessageExpectation::ImplementationDetails
- RSpec::Mocks::MethodDouble
- RSpec::Mocks::MethodReference
- RSpec::Mocks::NamedObjectReference
- RSpec::Mocks::NestedSpace
- RSpec::Mocks::ObjectMethodReference
- RSpec::Mocks::ObjectReference
- RSpec::Mocks::ObjectVerifyingDouble
- RSpec::Mocks::ObjectVerifyingDoubleMethods
- RSpec::Mocks::OrderGroup
- RSpec::Mocks::PartialClassDoubleProxy
- RSpec::Mocks::PartialClassDoubleProxyMethods
- RSpec::Mocks::PartialDoubleProxy
- RSpec::Mocks::Proxy
- RSpec::Mocks::ProxyForNil
- RSpec::Mocks::RootSpace
- RSpec::Mocks::SimpleMessageExpectation
- RSpec::Mocks::Space
- RSpec::Mocks::Space::FakeMutex
- RSpec::Mocks::StubChain
- RSpec::Mocks::Syntax
- RSpec::Mocks::TargetBase
- RSpec::Mocks::TestDouble
- RSpec::Mocks::TestDoubleProxy
- RSpec::Mocks::VerifyingDouble
- RSpec::Mocks::VerifyingExistingMethodDouble
- RSpec::Mocks::VerifyingMessageExpectation
- RSpec::Mocks::VerifyingMethodDouble
- RSpec::Mocks::VerifyingPartialClassDoubleProxy
- RSpec::Mocks::VerifyingPartialDoubleProxy
- RSpec::Mocks::VerifyingProxy
- RSpec::Mocks::VerifyingProxyMethods
- RSpec::Mocks::Version
- BasicObject
- Class

No matching classes.

# RSpec::Mocks::ErrorGenerator

@private

### Attributes

opts[W]

### Public Class Methods

new(target, name) click to toggle source

    # File lib/rspec/mocks/error_generator.rb, line 39
    def initialize(target, name)
      @target = target
      @name = name
    end

raise_double_negation_error(wrapped_expression) click to toggle source

    # File lib/rspec/mocks/error_generator.rb, line 217
    def self.raise_double_negation_error(wrapped_expression)
      raise "Isn't life confusing enough? You've already set a "                "negative message expectation and now you are trying to "                "negate it again with `never`. What does an expression like "                "`#{wrapped_expression}.not_to receive(:msg).never` even mean?"
    end

### Public Instance Methods

actual_method_call_args_description(count, args) click to toggle source

@private

    # File lib/rspec/mocks/error_generator.rb, line 147
    def actual_method_call_args_description(count, args)
      method_call_args_description(args) ||
        if count > 0 && args.length > 0
          " with arguments: #{args.inspect.gsub(/\A\[(.+)\]\z/, '(\1)')}"
        else
          ""
        end
    end

default_error_message(expectation, expected_args, actual_args) click to toggle source

    # File lib/rspec/mocks/error_generator.rb, line 87
    def default_error_message(expectation, expected_args, actual_args)
      [
        intro,
        "received",
        expectation.message.inspect,
        unexpected_arguments_message(expected_args, actual_args),
      ].join(" ")
    end

describe_expectation(verb, message, expected_received_count, _actual_received_count, *args) click to toggle source

@private

    # File lib/rspec/mocks/error_generator.rb, line 175
    def describe_expectation(verb, message, expected_received_count, _actual_received_count, *args)
      "#{verb} #{message}#{format_args(*args)} #{count_message(expected_received_count)}"
    end

expected_method_call_args_description(args) click to toggle source

@private

    # File lib/rspec/mocks/error_generator.rb, line 157
    def expected_method_call_args_description(args)
      method_call_args_description(args) ||
        if args.length > 0
          " with arguments: #{format_args(*args)}"
        else
          ""
        end
    end

expected_part_of_expectation_error(expected_received_count, expectation_count_type, argument_list_matcher) click to toggle source

@private

    # File lib/rspec/mocks/error_generator.rb, line 141
    def expected_part_of_expectation_error(expected_received_count, expectation_count_type, argument_list_matcher)
      "expected: #{count_message(expected_received_count, expectation_count_type)}" +
        expected_method_call_args_description(argument_list_matcher.expected_args)
    end

method_call_args_description(args) click to toggle source

@private

    # File lib/rspec/mocks/error_generator.rb, line 167
    def method_call_args_description(args)
      case args.first
      when ArgumentMatchers::AnyArgsMatcher then " with any arguments"
      when ArgumentMatchers::NoArgsMatcher  then " with no arguments"
      end
    end

opts() click to toggle source

@private

    # File lib/rspec/mocks/error_generator.rb, line 45
    def opts
      @opts ||= {}
    end

raise_block_failed_error(message, detail) click to toggle source

@private

    # File lib/rspec/mocks/error_generator.rb, line 185
    def raise_block_failed_error(message, detail)
      __raise "#{intro} received :#{message} but passed block failed with: #{detail}"
    end

raise_expectation_error(message, expected_received_count, argument_list_matcher, actual_received_count, expectation_count_type, *args) click to toggle source

rubocop:disable Style/ParameterLists @private

    # File lib/rspec/mocks/error_generator.rb, line 98
    def raise_expectation_error(message, expected_received_count, argument_list_matcher, actual_received_count, expectation_count_type, *args)
      expected_part = expected_part_of_expectation_error(expected_received_count, expectation_count_type, argument_list_matcher)
      received_part = received_part_of_expectation_error(actual_received_count, *args)
      __raise "(#{intro}).#{message}#{format_args(*args)}\n    #{expected_part}\n    #{received_part}"
    end

raise_expectation_on_mocked_method(method) click to toggle source

@private

    # File lib/rspec/mocks/error_generator.rb, line 212
    def raise_expectation_on_mocked_method(method)
      __raise "#{intro} expected to have received #{method}, but that "                  "method has been mocked instead of stubbed or spied."
    end

raise_expectation_on_unstubbed_method(method) click to toggle source

@private

    # File lib/rspec/mocks/error_generator.rb, line 206
    def raise_expectation_on_unstubbed_method(method)
      __raise "#{intro} expected to have received #{method}, but that "                  "object is not a spy or method has not been stubbed."
    end

raise_expired_test_double_error() click to toggle source

@private

    # File lib/rspec/mocks/error_generator.rb, line 126
    def raise_expired_test_double_error
      raise ExpiredTestDoubleError,
            "#{intro} was originally created in one example but has leaked into "                "another example and can no longer be used. rspec-mocks' doubles are "                "designed to only last for one example, and you need to create a new "                "one in each example you wish to use it for."
    end

raise_invalid_arguments_error(verifier) click to toggle source

@private

    # File lib/rspec/mocks/error_generator.rb, line 121
    def raise_invalid_arguments_error(verifier)
      __raise verifier.error_message
    end

raise_missing_block_error(args_to_yield) click to toggle source

@private

    # File lib/rspec/mocks/error_generator.rb, line 190
    def raise_missing_block_error(args_to_yield)
      __raise "#{intro} asked to yield |#{arg_list(*args_to_yield)}| but no block was passed"
    end

raise_missing_default_stub_error(expectation, *args) click to toggle source

@private

    # File lib/rspec/mocks/error_generator.rb, line 67
    def raise_missing_default_stub_error(expectation, *args)
      expected_args = format_args(*expectation.expected_args)
      actual_args = format_received_args(*args)
      diff = diff_message(expectation.expected_args, args)

      message = default_error_message(expectation, expected_args, actual_args)
      message << "\nDiff:\n #{diff}" unless diff.empty?
      message << "\n Please stub a default value first if message might be received with other args as well. \n"

      __raise message
    end

raise_non_public_error(method_name, visibility) click to toggle source

@private

    # File lib/rspec/mocks/error_generator.rb, line 114
    def raise_non_public_error(method_name, visibility)
      raise NoMethodError, "%s method `%s' called on %s" % [
        visibility, method_name, intro
      ]
    end

raise_only_valid_on_a_partial_double(method) click to toggle source

@private

    # File lib/rspec/mocks/error_generator.rb, line 200
    def raise_only_valid_on_a_partial_double(method)
      __raise "#{intro} is a pure test double. `#{method}` is only "                  "available on a partial double."
    end

raise_out_of_order_error(message) click to toggle source

@private

    # File lib/rspec/mocks/error_generator.rb, line 180
    def raise_out_of_order_error(message)
      __raise "#{intro} received :#{message} out of order"
    end

raise_similar_message_args_error(expectation, *args_for_multiple_calls) click to toggle source

@private

    # File lib/rspec/mocks/error_generator.rb, line 80
    def raise_similar_message_args_error(expectation, *args_for_multiple_calls)
      expected_args = format_args(*expectation.expected_args)
      actual_args = args_for_multiple_calls.map { |a| format_received_args(*a) }.join(", ")

      __raise(default_error_message(expectation, expected_args, actual_args))
    end

raise_unexpected_message_args_error(expectation, *args) click to toggle source

@private

    # File lib/rspec/mocks/error_generator.rb, line 55
    def raise_unexpected_message_args_error(expectation, *args)
      expected_args = format_args(*expectation.expected_args)
      actual_args = format_received_args(*args)
      diff = diff_message(expectation.expected_args, args)

      message = default_error_message(expectation, expected_args, actual_args)
      message << "\nDiff:#{diff}" unless diff.empty?

      __raise message
    end

raise_unexpected_message_error(message, *args) click to toggle source

@private

    # File lib/rspec/mocks/error_generator.rb, line 50
    def raise_unexpected_message_error(message, *args)
      __raise "#{intro} received unexpected message :#{message}#{arg_message(*args)}"
    end

raise_unimplemented_error(doubled_module, method_name) click to toggle source

@private

    # File lib/rspec/mocks/error_generator.rb, line 106
    def raise_unimplemented_error(doubled_module, method_name)
      __raise "%s does not implement: %s" % [
        doubled_module.description,
        method_name
      ]
    end

raise_wrong_arity_error(args_to_yield, signature) click to toggle source

@private

    # File lib/rspec/mocks/error_generator.rb, line 195
    def raise_wrong_arity_error(args_to_yield, signature)
      __raise "#{intro} yielded |#{arg_list(*args_to_yield)}| to block with #{signature.description}"
    end

received_part_of_expectation_error(actual_received_count, *args) click to toggle source

@private

    # File lib/rspec/mocks/error_generator.rb, line 135
    def received_part_of_expectation_error(actual_received_count, *args)
      "received: #{count_message(actual_received_count)}" +
        actual_method_call_args_description(actual_received_count, args)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.