Class: RSpec::Mocks::ErrorGenerator

### Home Classes Methods

### In Files

- lib/rspec/mocks/error_generator.rb

### Parent

Object

### Methods

- ::new
- ::raise_double_negation_error
- #describe_expectation
- #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_missing_block_error
- #raise_missing_default_stub_error
- #raise_only_valid_on_a_partial_mock
- #raise_out_of_order_error
- #raise_similar_message_args_error
- #raise_unexpected_message_args_error
- #raise_unexpected_message_error
- #raise_wrong_arity_error
- #received_part_of_expectation_error

### Class/Module Index

Quicksearch

- RSpec
- RSpec::Mocks
- RSpec::Mocks::AllowanceTarget
- RSpec::Mocks::AmbiguousReturnError
- RSpec::Mocks::AndCallOriginalImplementation
- RSpec::Mocks::AndReturnImplementation
- RSpec::Mocks::AndYieldImplementation
- RSpec::Mocks::AnyInstance
- RSpec::Mocks::AnyInstance::Chain
- RSpec::Mocks::AnyInstance::Chain::Customizations
- RSpec::Mocks::AnyInstance::ExpectationChain
- RSpec::Mocks::AnyInstance::MessageChains
- RSpec::Mocks::AnyInstance::PositiveExpectationChain
- 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::BooleanMatcher
- RSpec::Mocks::ArgumentMatchers::DuckTypeMatcher
- RSpec::Mocks::ArgumentMatchers::EqualityProxy
- RSpec::Mocks::ArgumentMatchers::HashExcludingMatcher
- RSpec::Mocks::ArgumentMatchers::HashIncludingMatcher
- RSpec::Mocks::ArgumentMatchers::InstanceOf
- RSpec::Mocks::ArgumentMatchers::KindOf
- RSpec::Mocks::ArgumentMatchers::MatcherMatcher
- RSpec::Mocks::ArgumentMatchers::NoArgsMatcher
- RSpec::Mocks::ArgumentMatchers::RegexpMatcher
- 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::ConstantStubber
- RSpec::Mocks::Deprecation
- RSpec::Mocks::ErrorGenerator
- RSpec::Mocks::ExampleMethods
- RSpec::Mocks::ExampleMethods::ExpectHost
- RSpec::Mocks::ExpectationTarget
- RSpec::Mocks::Implementation
- RSpec::Mocks::InstanceExec
- RSpec::Mocks::InstanceMethodStasher
- RSpec::Mocks::Matchers
- RSpec::Mocks::Matchers::HaveReceived
- RSpec::Mocks::Matchers::Receive
- RSpec::Mocks::Matchers::Receive::Customization
- RSpec::Mocks::MessageExpectation
- RSpec::Mocks::MethodDouble
- RSpec::Mocks::MethodDouble::ProcWithBlock
- RSpec::Mocks::Mock
- RSpec::Mocks::MockExpectationError
- RSpec::Mocks::OrderGroup
- RSpec::Mocks::Proxy
- RSpec::Mocks::ProxyForNil
- RSpec::Mocks::RecursiveConstMethods
- RSpec::Mocks::Space
- RSpec::Mocks::StubChain
- RSpec::Mocks::Syntax
- RSpec::Mocks::TargetBase
- RSpec::Mocks::TestDouble
- RSpec::Mocks::Version
- Marshal

No matching classes.

# RSpec::Mocks::ErrorGenerator

@private

### Attributes

opts[W]

### Public Class Methods

new(target, name, options={}) click to toggle source

    # File lib/rspec/mocks/error_generator.rb, line 7
    def initialize(target, name, options={})
      @declared_as = options[:__declared_as] || 'Mock'
      @target = target
      @name = name
    end

raise_double_negation_error(wrapped_expression) click to toggle source

    # File lib/rspec/mocks/error_generator.rb, line 119
    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

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

@private

    # File lib/rspec/mocks/error_generator.rb, line 77
    def describe_expectation(message, expected_received_count, actual_received_count, *args)
      "have received #{message}#{format_args(*args)} #{count_message(expected_received_count)}"
    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 58
    def expected_part_of_expectation_error(expected_received_count, expectation_count_type, argument_list_matcher)
      "expected: #{count_message(expected_received_count, expectation_count_type)}" +
        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 64
    def method_call_args_description(args)
      if args.first.is_a?(ArgumentMatchers::AnyArgsMatcher)
        " with any arguments"
      elsif args.first.is_a?(ArgumentMatchers::NoArgsMatcher)
        " with no arguments"
      elsif args.length > 0
        " with arguments: #{args.inspect.gsub(/\A\[(.+)\]\z/, '(\1)')}"
      else
        ""
      end
    end

opts() click to toggle source

@private

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

raise_block_failed_error(message, detail) click to toggle source

@private

    # File lib/rspec/mocks/error_generator.rb, line 87
    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

@private

    # File lib/rspec/mocks/error_generator.rb, line 45
    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 114
    def raise_expectation_on_mocked_method(method)
      __raise "#{intro} expected to have received #{method}, but that " +
              "method has been mocked instead of stubbed."
    end

raise_expectation_on_unstubbed_method(method) click to toggle source

@private

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

raise_missing_block_error(args_to_yield) click to toggle source

@private

    # File lib/rspec/mocks/error_generator.rb, line 92
    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 31
    def raise_missing_default_stub_error(expectation, *args)
      expected_args = format_args(*expectation.expected_args)
      actual_args = format_received_args(*args)
      __raise "#{intro} received #{expectation.message.inspect} with unexpected arguments\n  expected: #{expected_args}\n       got: #{actual_args}\n Please stub a default value first if message might be received with other args as well. \n"
    end

raise_only_valid_on_a_partial_mock(method) click to toggle source

@private

    # File lib/rspec/mocks/error_generator.rb, line 102
    def raise_only_valid_on_a_partial_mock(method)
      __raise "#{intro} is a pure mock object. `#{method}` is only " +
              "available on a partial mock object."
    end

raise_out_of_order_error(message) click to toggle source

@private

    # File lib/rspec/mocks/error_generator.rb, line 82
    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 38
    def raise_similar_message_args_error(expectation, *args_for_multiple_calls)
      expected_args = format_args(*expectation.expected_args)
      actual_args = args_for_multiple_calls.collect {|a| format_received_args(*a)}.join(", ")
      __raise "#{intro} received #{expectation.message.inspect} with unexpected arguments\n  expected: #{expected_args}\n       got: #{actual_args}"
    end

raise_unexpected_message_args_error(expectation, *args) click to toggle source

@private

    # File lib/rspec/mocks/error_generator.rb, line 24
    def raise_unexpected_message_args_error(expectation, *args)
      expected_args = format_args(*expectation.expected_args)
      actual_args = format_received_args(*args)
      __raise "#{intro} received #{expectation.message.inspect} with unexpected arguments\n  expected: #{expected_args}\n       got: #{actual_args}"
    end

raise_unexpected_message_error(message, *args) click to toggle source

@private

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

raise_wrong_arity_error(args_to_yield, arity) click to toggle source

@private

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

received_part_of_expectation_error(actual_received_count, *args) click to toggle source

@private

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

[Validate]

Generated with the Darkfish Rdoc Generator 2.