Sha256: 05e3855a67cb8b96f4602e76a30550ff17e558699bd4ae32d790342bb77a7b7e

Contents?: true

Size: 1.36 KB

Versions: 2

Compression:

Stored size: 1.36 KB

Contents

require 'flexmock/spy_describers'

class FlexMock
  module RSpecMatchers

    class HaveReceived
      include SpyDescribers

      def initialize(method_name)
        @method_name = method_name
        @args = nil
        @block = nil
        @times = nil
        @needs_block = nil
      end

      def matches?(spy)
        @spy = spy
        @options = {}
        @options[:times] = @times if @times
        @options[:with_block] = @needs_block unless @needs_block.nil?
        @spy.flexmock_was_called_with?(@method_name, @args, @options)
      end

      def failure_message_for_should
        describe_spy_expectation(@spy, @method_name, @args, @options)
      end

      def failure_message_for_should_not
        describe_spy_negative_expectation(@spy, @method_name, @args, @options)
      end

      def with(*args)
        @args = args
        self
      end

      def with_a_block
        @needs_block = true
        self
      end

      def without_a_block
        @needs_block = false
        self
      end

      def times(n)
        @times = n
        self
      end

      def never
        times(0)
      end

      def once
        times(1)
      end

      def twice
        times(2)
      end
    end

    def have_received(method_name)
      HaveReceived.new(method_name)
    end
  end
end

RSpec::configure do |config|
  config.include(FlexMock::RSpecMatchers)
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
flexmock-1.0.0.beta.2 lib/flexmock/rspec_spy_matcher.rb
flexmock-1.0.0.beta.1 lib/flexmock/rspec_spy_matcher.rb