Class: Pact::ConsumerContract::Message
- Inherits:
-
Object
- Object
- Pact::ConsumerContract::Message
- Includes:
- ActiveSupportSupport, SymbolizeKeys
- Defined in:
- lib/pact/consumer_contract/message.rb,
lib/pact/consumer_contract/message/contents.rb
Defined Under Namespace
Classes: Contents
Instance Attribute Summary collapse
-
#_id ⇒ Object
Returns the value of attribute _id.
-
#contents ⇒ Object
Returns the value of attribute contents.
-
#description ⇒ Object
Returns the value of attribute description.
-
#index ⇒ Object
Returns the value of attribute index.
-
#metadata ⇒ Object
Returns the value of attribute metadata.
-
#provider_state ⇒ Object
Returns the value of attribute provider_state.
-
#provider_states ⇒ Object
Returns the value of attribute provider_states.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #description_with_provider_state_quoted ⇒ Object
- #eq?(other) ⇒ Boolean
- #http? ⇒ Boolean
-
#initialize(attributes = {}) ⇒ Message
constructor
A new instance of Message.
- #match_criterion(target, criterion) ⇒ Object
- #matches_criteria?(criteria) ⇒ Boolean
- #message? ⇒ Boolean
- #request ⇒ Object
-
#response ⇒ Object
custom media type?.
- #to_hash ⇒ Object
- #to_s ⇒ Object
- #validate! ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ Message
Returns a new instance of Message.
18 19 20 21 22 23 24 25 26 |
# File 'lib/pact/consumer_contract/message.rb', line 18 def initialize attributes = {} @description = attributes[:description] @provider_state = attributes[:provider_state] || attributes[:providerState] @provider_states = attributes[:provider_states] || [] @contents = attributes[:contents] @metadata = attributes[:metadata] @_id = attributes[:_id] @index = attributes[:index] end |
Instance Attribute Details
#_id ⇒ Object
Returns the value of attribute _id.
16 17 18 |
# File 'lib/pact/consumer_contract/message.rb', line 16 def _id @_id end |
#contents ⇒ Object
Returns the value of attribute contents.
16 17 18 |
# File 'lib/pact/consumer_contract/message.rb', line 16 def contents @contents end |
#description ⇒ Object
Returns the value of attribute description.
16 17 18 |
# File 'lib/pact/consumer_contract/message.rb', line 16 def description @description end |
#index ⇒ Object
Returns the value of attribute index.
16 17 18 |
# File 'lib/pact/consumer_contract/message.rb', line 16 def index @index end |
#metadata ⇒ Object
Returns the value of attribute metadata.
16 17 18 |
# File 'lib/pact/consumer_contract/message.rb', line 16 def @metadata end |
#provider_state ⇒ Object
Returns the value of attribute provider_state.
16 17 18 |
# File 'lib/pact/consumer_contract/message.rb', line 16 def provider_state @provider_state end |
#provider_states ⇒ Object
Returns the value of attribute provider_states.
16 17 18 |
# File 'lib/pact/consumer_contract/message.rb', line 16 def provider_states @provider_states end |
Class Method Details
.from_hash(hash, options = {}) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/pact/consumer_contract/message.rb', line 28 def self.from_hash hash, = {} opts = .dup unless opts[:pact_specification_version] opts[:pact_specification_version] = Pact::SpecificationVersion::NIL_VERSION end contents_matching_rules = hash['matchingRules'] && hash['matchingRules']['body'] contents_hash = Pact::MatchingRules.merge(hash['contents'], contents_matching_rules, opts) contents = Pact::ConsumerContract::Message::Contents.from_hash(contents_hash) = hash['metaData'] || hash['metadata'] provider_state_name = parse_provider_state_name(hash['providerState'], hash['providerStates']) provider_states = parse_provider_states(provider_state_name, hash['providerStates']) new(symbolize_keys(hash).merge( contents: contents, provider_state: provider_state_name, provider_states: provider_states, metadata: )) end |
Instance Method Details
#==(other) ⇒ Object
96 97 98 |
# File 'lib/pact/consumer_contract/message.rb', line 96 def == other other.is_a?(Message) && to_hash == other.to_hash end |
#description_with_provider_state_quoted ⇒ Object
117 118 119 |
# File 'lib/pact/consumer_contract/message.rb', line 117 def description_with_provider_state_quoted provider_state ? "\"#{description}\" given \"#{provider_state}\"" : "\"#{description}\"" end |
#eq?(other) ⇒ Boolean
113 114 115 |
# File 'lib/pact/consumer_contract/message.rb', line 113 def eq? other self == other end |
#http? ⇒ Boolean
84 85 86 |
# File 'lib/pact/consumer_contract/message.rb', line 84 def http? false end |
#match_criterion(target, criterion) ⇒ Object
109 110 111 |
# File 'lib/pact/consumer_contract/message.rb', line 109 def match_criterion target, criterion target == criterion || (criterion.is_a?(Regexp) && criterion.match(target)) end |
#matches_criteria?(criteria) ⇒ Boolean
100 101 102 103 104 105 106 107 |
# File 'lib/pact/consumer_contract/message.rb', line 100 def matches_criteria? criteria criteria.each do | key, value | unless match_criterion self.send(key.to_s), value return false end end true end |
#message? ⇒ Boolean
88 89 90 |
# File 'lib/pact/consumer_contract/message.rb', line 88 def true end |
#request ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/pact/consumer_contract/message.rb', line 56 def request @request ||= Pact::Consumer::Request::Actual.from_hash( path: '/', method: 'POST', query: nil, headers: { 'Content-Type' => 'application/json' }, body: { description: description, providerStates: [{ name: provider_state, params: {} }], metadata: } ) end |
#response ⇒ Object
custom media type?
74 75 76 77 78 79 80 81 82 |
# File 'lib/pact/consumer_contract/message.rb', line 74 def response @response ||= Pact::Response.new( status: 200, headers: {'Content-Type' => 'application/json'}, body: { contents: contents } ) end |
#to_hash ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/pact/consumer_contract/message.rb', line 47 def to_hash { description: description, provider_states: [{ name: provider_state }], contents: contents.contents, metadata: } end |
#to_s ⇒ Object
121 122 123 |
# File 'lib/pact/consumer_contract/message.rb', line 121 def to_s to_hash.to_s end |
#validate! ⇒ Object
92 93 94 |
# File 'lib/pact/consumer_contract/message.rb', line 92 def validate! raise Pact::InvalidMessageError.new(self) unless description && contents end |