Sha256: be2df9f376ca27b2dd62cbdfcd87dd5310768786a6625fb9aef7702d1776155f

Contents?: true

Size: 1.1 KB

Versions: 3

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

require 'fix'

# Namespace for the Fix framework.
#
# @api public
#
module Fix
  # Open the on class.
  #
  # @api private
  #
  class On
    # @api public
    #
    # @example Let's define the answer to the Ultimate Question of Life, the
    #   Universe, and Everything.
    #
    #   let(:answer) { 42 }
    #
    # @param method_name [Symbol] The identifier of a method.
    # @param block       [Proc]   A spec to compare against the computed value.
    #
    # @return [#object_id] List of results.
    def let(method_name, &block)
      helpers.update(method_name => block)
    end
  end

  # Open the it class.
  #
  # @api private
  #
  class It
    private

    # Override Ruby's method_missing in order to provide `On#let` interface.
    #
    # @api private
    #
    # @since 0.11.0
    #
    # @raise [NoMethodError] If doesn't respond to the given method.
    def method_missing(name, *args, &block)
      helpers.key?(name) ? helpers.fetch(name).call : super
    end

    def respond_to_missing?(name, include_private = false)
      helpers.key?(name) || super
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
fix-let-0.1.4 lib/fix/let.rb
fix-let-0.1.3 lib/fix/let.rb
fix-let-0.1.2 lib/fix/let.rb