Sha256: a79843e19cd53b7e82de42b836e0b3eebddb00a67358cf0265a66bef9489f74a

Contents?: true

Size: 1.81 KB

Versions: 2

Compression:

Stored size: 1.81 KB

Contents

require_relative "mocktail/dsl"
require_relative "mocktail/errors"
require_relative "mocktail/handles_dry_call"
require_relative "mocktail/handles_dry_new_call"
require_relative "mocktail/imitates_type"
require_relative "mocktail/initializes_mocktail"
require_relative "mocktail/matcher_presentation"
require_relative "mocktail/matchers"
require_relative "mocktail/registers_matcher"
require_relative "mocktail/registers_stubbing"
require_relative "mocktail/replaces_next"
require_relative "mocktail/replaces_type"
require_relative "mocktail/resets_state"
require_relative "mocktail/value"
require_relative "mocktail/verifies_call"
require_relative "mocktail/version"

module Mocktail
  # Returns an instance of `type` whose implementation is mocked out
  def self.of(type)
    ImitatesType.new.imitate(type)
  end

  # Returns an instance of `klass` whose implementation is mocked out AND
  # stubs its constructor to return that fake the next time klass.new is called
  def self.of_next(type, count: 1)
    ReplacesNext.new.replace(type, count)
  end

  # See lib/mocktail/dsl.rb
  define_singleton_method :stubs, DSL.instance_method(:stubs)
  define_singleton_method :verify, DSL.instance_method(:verify)

  def self.matchers
    MatcherPresentation.new
  end

  def self.captor
    Matchers::Captor.new
  end

  def self.register_matcher(matcher)
    RegistersMatcher.new.register(matcher)
  end

  # Replaces every singleton method on `type` with a fake, and when instantiated
  # or included will also fake instance methods
  def self.replace(type)
    ReplacesType.new.replace(type)
    nil
  end

  def self.reset
    ResetsState.new.reset
  end

  # Stores most transactional state about calls & stubbing configurations
  def self.cabinet
    Thread.current[:mocktail_store] ||= Cabinet.new
  end
end

Mocktail::InitializesMocktail.new.init

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mocktail-0.0.2 lib/mocktail.rb
mocktail-0.0.1 lib/mocktail.rb