Module: Pact::Helpers
- Included in:
- Pact
- Defined in:
- lib/pact/helpers.rb
Class Method Summary collapse
Instance Method Summary collapse
- #each_like(content, options = {}) ⇒ Object
- #like(content) ⇒ Object
- #like_date(date) ⇒ Object
- #like_datetime(datetime) ⇒ Object
- #like_datetime_rfc822(datetime) ⇒ Object
- #like_datetime_with_milliseconds(datetime) ⇒ Object (also: #like_datetime_with_miliseconds)
- #like_decimal(float) ⇒ Object
- #like_integer(int) ⇒ Object
- #like_uuid(uuid) ⇒ Object
- #term(arg1, arg2 = nil) ⇒ Object
Class Method Details
.included(base) ⇒ Object
10 11 12 |
# File 'lib/pact/helpers.rb', line 10 def self.included(base) base.extend(self) end |
Instance Method Details
#each_like(content, options = {}) ⇒ Object
28 29 30 |
# File 'lib/pact/helpers.rb', line 28 def each_like content, = {} Pact::ArrayLike.new(content, ) end |
#like(content) ⇒ Object
24 25 26 |
# File 'lib/pact/helpers.rb', line 24 def like content Pact::SomethingLike.new(content) end |
#like_date(date) ⇒ Object
46 47 48 |
# 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) ⇒ Object
36 37 38 |
# 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) ⇒ Object
60 61 62 63 64 65 66 67 68 |
# File 'lib/pact/helpers.rb', line 60 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_milliseconds(datetime) ⇒ Object Also known as: like_datetime_with_miliseconds
40 41 42 |
# 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_decimal(float) ⇒ Object
56 57 58 |
# File 'lib/pact/helpers.rb', line 56 def like_decimal float Pact::Term.new(generate: float, matcher: /^0|-?\d+\.\d*$/) end |
#like_integer(int) ⇒ Object
52 53 54 |
# File 'lib/pact/helpers.rb', line 52 def like_integer int Pact::Term.new(generate: int, matcher: /^-?\d+$/) end |
#like_uuid(uuid) ⇒ Object
32 33 34 |
# 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) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# 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 |