Sha256: b86c1a8c758fcddf2291100448e324848c471324d8e7d4077e20d9fabf0cf822

Contents?: true

Size: 1.9 KB

Versions: 18

Compression:

Stored size: 1.9 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
        @additional_validations = []
      end

      def matches?(spy)
        @spy = spy
        @options = construct_options
        @spy.flexmock_received?(@method_name, @args, @options)
      end

      def failure_message_for_should
        failure_message
      end

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

      def failure_message_for_should_not
        failure_message_when_negated
      end

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

      def description
        spy_description(@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

      def on(on_count)
        @on_count = on_count
        self
      end

      def and(&block)
        @additional_validations << block
        self
      end

      def construct_options
        {
          :times      => @times,
          :with_block => @needs_block,
          :on_count   => @on_count,
          :and        => @additional_validations,
        }
      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

18 entries across 18 versions & 1 rubygems

Version Path
flexmock-2.4.2 lib/flexmock/rspec_spy_matcher.rb
flexmock-3.0.1 lib/flexmock/rspec_spy_matcher.rb
flexmock-2.4.1 lib/flexmock/rspec_spy_matcher.rb
flexmock-3.0.0 lib/flexmock/rspec_spy_matcher.rb
flexmock-2.4.0 lib/flexmock/rspec_spy_matcher.rb
flexmock-2.3.8 lib/flexmock/rspec_spy_matcher.rb
flexmock-2.3.6 lib/flexmock/rspec_spy_matcher.rb
flexmock-2.3.5 lib/flexmock/rspec_spy_matcher.rb
flexmock-2.3.4 lib/flexmock/rspec_spy_matcher.rb
flexmock-2.3.3 lib/flexmock/rspec_spy_matcher.rb
flexmock-2.3.2 lib/flexmock/rspec_spy_matcher.rb
flexmock-2.3.1 lib/flexmock/rspec_spy_matcher.rb
flexmock-2.3.0 lib/flexmock/rspec_spy_matcher.rb
flexmock-2.2.1 lib/flexmock/rspec_spy_matcher.rb
flexmock-2.2.0 lib/flexmock/rspec_spy_matcher.rb
flexmock-2.1.0 lib/flexmock/rspec_spy_matcher.rb
flexmock-2.0.6 lib/flexmock/rspec_spy_matcher.rb
flexmock-2.0.5 lib/flexmock/rspec_spy_matcher.rb