Sha256: 3cebf71a313a1a91d40c0481340d45d732a3f00a357c24f71091728b9b9faf44

Contents?: true

Size: 1.11 KB

Versions: 17

Compression:

Stored size: 1.11 KB

Contents

require 'muack/block'
require 'muack/error'

module Muack
  class Modifier < Struct.new(:mock, :defi)
    # Public API
    def times number
      if mock.__mock_class == Stub
        raise StubHasNoTimes.new(object, defi, number)
      end

      if number >= 1
        (number - 1).times{ mock.__mock_defis_push(defi) }
      elsif number == 0
        mock.__mock_defis_pop(defi)
      else
        raise "What would you expect from calling a method #{number} times?"
      end
      self
    end

    # Public API
    def with_any_args
      defi.args = [WithAnyArgs]
      self
    end

    # Public API
    def returns opts={}, &block
      defi.returns = create_block(block, opts)
      self
    end

    # Public API
    def peek_args opts={}, &block
      defi.peek_args = create_block(block, opts)
      self
    end

    # Public API
    def peek_return opts={}, &block
      defi.peek_return = create_block(block, opts)
      self
    end

    # Public API
    def object
      mock.object
    end

    private
    def create_block block, opts
      if opts[:instance_exec] then Block.new(block) else block end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
muack-1.7.0 lib/muack/modifier.rb
muack-1.6.0 lib/muack/modifier.rb
muack-1.5.1 lib/muack/modifier.rb
muack-1.5.0 lib/muack/modifier.rb
muack-1.4.0 lib/muack/modifier.rb
muack-1.3.2 lib/muack/modifier.rb
muack-1.3.1 lib/muack/modifier.rb
muack-1.3.0 lib/muack/modifier.rb
muack-1.2.0 lib/muack/modifier.rb
muack-1.1.2 lib/muack/modifier.rb
muack-1.1.1 lib/muack/modifier.rb
muack-1.1.0 lib/muack/modifier.rb
muack-1.0.4 lib/muack/modifier.rb
muack-1.0.3 lib/muack/modifier.rb
muack-1.0.2 lib/muack/modifier.rb
muack-1.0.1 lib/muack/modifier.rb
muack-1.0.0 lib/muack/modifier.rb