module Pact::Helpers

Public Class Methods

included(base) click to toggle source
# File lib/pact/helpers.rb, line 10
def self.included(base)
  base.extend(self)
end

Public Instance Methods

each_like(content, options = {}) click to toggle source
# File lib/pact/helpers.rb, line 28
def each_like content, options = {}
  Pact::ArrayLike.new(content, options)
end
like(content) click to toggle source
# File lib/pact/helpers.rb, line 24
def like content
  Pact::SomethingLike.new(content)
end
like_date(date) click to toggle source
# File lib/pact/helpers.rb, line 46
def like_date date
  Pact::Term.new(generate: date, matcher: /^\d{4}-[01]\d-[0-3]\d$/)
end
like_datetime(datetime) click to toggle source
# File lib/pact/helpers.rb, line 36
def like_datetime datetime
  Pact::Term.new(generate: datetime, matcher: /^\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z)$/)
end
like_datetime_rfc822(datetime) click to toggle source
# File lib/pact/helpers.rb, line 50
def like_datetime_rfc822 datetime
  Pact::Term.new(
    generate: datetime,
    matcher: /(?x)(Mon|Tue|Wed|Thu|Fri|Sat|Sun),
                    \s\d{2}\s
                    (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)
                    \s\d{4}\s\d{2}:\d{2}:\d{2}\s(\+|-)\d{4}/
  )
end
like_datetime_with_miliseconds(datetime)
like_datetime_with_milliseconds(datetime) click to toggle source
# File lib/pact/helpers.rb, line 40
def like_datetime_with_milliseconds datetime
  Pact::Term.new(generate: datetime, matcher: /^\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d{3}([+-][0-2]\d:[0-5]\d|Z)$/)
end
like_uuid(uuid) click to toggle source
# File lib/pact/helpers.rb, line 32
def like_uuid uuid
  Pact::Term.new(generate: uuid, matcher: /^[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}$/)
end
term(arg1, arg2 = nil) click to toggle source
# File lib/pact/helpers.rb, line 14
def term arg1, arg2 = nil
  case arg1
  when Hash then Pact::Term.new(arg1)
  when Regexp then Pact::Term.new(matcher: arg1, generate: arg2)
  when String then Pact::Term.new(matcher: arg2, generate: arg1)
  else
    raise ArgumentError, "Cannot create a Pact::Term from arguments #{arg1.inspect} and #{arg2.inspect}. Please provide a Regexp and a String."
  end
end