Skip to content

Commit

Permalink
feat(generators): add generators to a consumer contract request (#97)
Browse files Browse the repository at this point in the history
* feat(generators): add generators to a consumer contract request

* feat(generators): add test for consumer contract request generators

Co-authored-by: Honza2 <[email protected]>
  • Loading branch information
slt and hhhonzik committed Nov 14, 2022
1 parent 9980bd6 commit fbce4cb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
8 changes: 5 additions & 3 deletions lib/pact/consumer_contract/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Request
class Expected < Pact::Request::Base

DEFAULT_OPTIONS = {:allow_unexpected_keys => false}.freeze
attr_accessor :options #Temporary hack
attr_accessor :options, :generators

def self.from_hash(hash)
sym_hash = symbolize_keys hash
Expand All @@ -16,11 +16,13 @@ def self.from_hash(hash)
headers = sym_hash.fetch(:headers, key_not_found)
body = sym_hash.fetch(:body, key_not_found)
options = sym_hash.fetch(:options, {})
new(method, path, headers, body, query, options)
generators = sym_hash.fetch(:generators, {})
new(method, path, headers, body, query, options, generators)
end

def initialize(method, path, headers, body, query, options = {})
def initialize(method, path, headers, body, query, options = {}, generators = {})
super(method, path, headers, body, query)
@generators = generators
@options = options
end

Expand Down
3 changes: 2 additions & 1 deletion spec/lib/pact/consumer_contract/request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ module Pact

describe "matching to actual requests" do

subject { Request::Expected.new(expected_method, expected_path, expected_headers, expected_body, expected_query, options) }
subject { Request::Expected.new(expected_method, expected_path, expected_headers, expected_body, expected_query, options, generators) }
let(:options) { {} }
let(:generators) { {} }

let(:expected_method) { 'get' }
let(:expected_path) { '/foo' }
Expand Down

0 comments on commit fbce4cb

Please sign in to comment.