Sha256: 54989af29e41833746090ff8db3d3b57d16f95417720fe1379bdd4438c6d472e

Contents?: true

Size: 1.63 KB

Versions: 1

Compression:

Stored size: 1.63 KB

Contents

# encoding: UTF-8
require_relative './request'
require_relative './response'
require_relative './forward'
require_relative './times'

#
# A class to model an expectation sent to the Mockserver instance.
# See http://www.mock-server.com/#create-expectations for details.
#
# @author:: Nayyara Samuel (mailto: nayyara.samuel@opower.com)
#
module MockServer::Model
  # Expectation model
  class Expectation
    attr_accessor :times

    # Method to setup the request on the expectation object
    # @yieldparam [Request] the request that this expectation references
    # @return [Expectation] this object according to the  the builder pattern
    def request(&_)
      if block_given?
        @request ||= Request.new
        yield @request
      end
      @request
    end

    # Method to setup the response on the expectation object
    # @yieldparam [Response] the response that this expectation references
    # @return [Expectation] this object according to the  the builder pattern
    def response(&_)
      if block_given?
        @response ||= Response.new
        yield @response
      end
      @response
    end

    # Method to setup the request on the expectation object
    # @yieldparam [Forward] the forward object that this expectation references
    # @return [Expectation] this object according to the  the builder pattern
    def forward(&_)
      if block_given?
        @forward ||= Forward.new
        yield @forward
      end
      @forward
    end
  end

  # DSL methods related to expectation
  module DSL
    def expectation(&_)
      expectation = Expectation.new
      yield expectation if block_given?
      expectation
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mockserver-client-0.0.1 lib/mockserver/model/expectation.rb