Sha256: 73ea5a9beb41609ddd54e1ebdd4abb3dd880ba2c3f806d51fd897728d02ea519

Contents?: true

Size: 1.61 KB

Versions: 1

Compression:

Stored size: 1.61 KB

Contents

module Spec
  module Adapters
    module MockFramework

      def setup_mocks_for_rspec
        # No setup required
      end

      def verify_mocks_for_rspec
      end

      def teardown_mocks_for_rspec
      end
    end
  end
end

module Caricature

  module RSpecMatchers

    class HaveReceived
      def initialize(expected)
        @expected = expected
        @block_args, @error, @args = nil, "", [:any]
      end

      def matches?(target)
        @target = target

        veri = @target.did_receive?(@expected).with(*@args)
        veri.with_block_args(*@block_args) if @block_args
        result = veri.successful?

        @error = "\n#{veri.error}" unless result

        result
      end

      def failure_message_for_should
        "expected #{@target.inspect} to have received #{@expected}" + @error
      end

      def failure_message_for_should_not
        "expected #{@target.inspect} not to have received #{@expected}" + @error
      end

      # constrain this verification to the provided arguments
      def with(*args)
        ags = *args
        @args = args
        @args = [:any] if (args.first.is_a?(Symbol) and args.first == :any) || ags.nil?
        # @callback = b if b
        self
      end

      def with_block_args(*args)
        @block_args = args
        self
      end

      # allow any arguments ignore the argument constraint
      def allow_any_arguments
        @args = :any
        self
      end
    end

    def have_received(method_name, *args)
      HaveReceived.new(method_name).with(*args)
    end
  end
end

Spec::Runner.configure do |config|
  config.include(Caricature::RSpecMatchers)
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
caricature-0.7.2 lib/caricature/rspec/integration.rb