Sha256: 50569881fb60593a93619d475a293fd3b0365b6afd7d4c0084340bcdbf4633c6

Contents?: true

Size: 1.54 KB

Versions: 2

Compression:

Stored size: 1.54 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 coat obj=Object.new
      ret = Muack.session.coat(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

2 entries across 2 versions & 1 rubygems

Version Path
muack-1.2.0 lib/muack.rb
muack-1.1.2 lib/muack.rb