Sha256: 682752b92719ca507b0f7447ac814da3b691e1c34b0fcade9c7e9d99542b9276

Contents?: true

Size: 1.42 KB

Versions: 3

Compression:

Stored size: 1.42 KB

Contents

require 'muack/session'
require 'muack/satisfy'

module Muack
  def self.verify obj=nil
    session.verify(obj)
  ensure
    reset(obj)
  end

  def self.session
    Thread.current[:muack_session] ||= Muack::Session.new
  end

  def self.reset obj=nil
    session = Thread.current[:muack_session]
    session && session.reset(obj)
    Thread.current[:muack_session] = nil unless obj
  end

  module API
    module_function
    def mock obj=Object.new
      ret = Muack.session.mock(obj)
      if block_given? then yield(ret) else ret end
    end

    def stub obj=Object.new
      ret = Muack.session.stub(obj)
      if block_given? then yield(ret) else ret end
    end

    def spy obj
      ret = Muack.session.spy(obj)
      if block_given? then yield(ret) else ret end
    end

    def any_instance_of klass
      ret = Muack.session.any_instance_of(klass)
      if block_given? then yield(ret) else ret end
    end

    def is_a klass
      Muack::IsA.new(klass)
    end

    def anything
      Muack::Anything.new
    end

    def match regexp
      Muack::Match.new(regexp)
    end

    def hash_including hash
      Muack::HashIncluding.new(hash)
    end

    def including element
      Muack::Including.new(element)
    end

    def within range_or_array
      Muack::Within.new(range_or_array)
    end

    def respond_to *msg
      Muack::RespondTo.new(*msg)
    end

    def satisfy &block
      Muack::Satisfy.new(block)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
muack-1.1.1 lib/muack.rb
muack-1.1.0 lib/muack.rb
muack-1.0.4 lib/muack.rb