Sha256: 6ef3d2f9dcd096f3cf158319c298fc85886346274242091db7a11af8be3d8dd3

Contents?: true

Size: 1.62 KB

Versions: 15

Compression:

Stored size: 1.62 KB

Contents

class Surrogate
  module RSpec
    class AbstractFailureMessage
      class ArgsInspector
        def self.inspect(invocation)
          inspected_arguments = invocation.args.map { |argument| inspect_argument argument }
          inspected_arguments << 'no args' if inspected_arguments.empty?
          "`" << inspected_arguments.join(", ") << "'"
        end

        def self.inspect_argument(to_inspect)
          if RSpec.rspec_mocks_loaded? && to_inspect.respond_to?(:description)
            to_inspect.description
          else
            to_inspect.inspect
          end
        end
      end

      attr_accessor :method_name, :invocations, :with_filter, :times_predicate

      def initialize(method_name, invocations, with_filter, times_predicate)
        self.method_name     = method_name
        self.invocations     = invocations
        self.with_filter     = with_filter
        self.times_predicate = times_predicate
      end

      def get_message
        raise "I should have been overridden"
      end

      def times_invoked
        invocations.size
      end

      def inspect_arguments(arguments)
        # can we fix this as soon as an array enters the system instead of catching it here?
        if arguments.kind_of? Invocation
          ArgsInspector.inspect arguments
        else
          ArgsInspector.inspect Invocation.new arguments
        end
      end

      def expected_invocation
        with_filter.expected_invocation
      end

      def times_msg(n)
        "#{n} time#{'s' unless n == 1}"
      end

      def expected_times_invoked
        times_predicate.expected_times_invoked
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
surrogate-0.8.1 lib/surrogate/rspec/abstract_failure_message.rb
surrogate-0.8.0 lib/surrogate/rspec/abstract_failure_message.rb
surrogate-0.7.0 lib/surrogate/rspec/abstract_failure_message.rb
surrogate-0.6.5 lib/surrogate/rspec/abstract_failure_message.rb
surrogate-0.6.4 lib/surrogate/rspec/abstract_failure_message.rb
surrogate-0.6.3 lib/surrogate/rspec/abstract_failure_message.rb
surrogate-0.6.2 lib/surrogate/rspec/abstract_failure_message.rb
surrogate-0.6.1 lib/surrogate/rspec/abstract_failure_message.rb
surrogate-0.6.0 lib/surrogate/rspec/abstract_failure_message.rb
surrogate-0.5.5 lib/surrogate/rspec/abstract_failure_message.rb
surrogate-0.5.4 lib/surrogate/rspec/abstract_failure_message.rb
surrogate-0.5.3 lib/surrogate/rspec/abstract_failure_message.rb
surrogate-0.5.2 lib/surrogate/rspec/abstract_failure_message.rb
surrogate-0.5.1 lib/surrogate/rspec/abstract_failure_message.rb
surrogate-0.5.0 lib/surrogate/rspec/abstract_failure_message.rb