Class: PactExpectations

Inherits:
Object
  • Object
show all
Defined in:
lib/pact_expectations.rb,
lib/pact_expectations/version.rb

Defined Under Namespace

Classes: DuplicatedKey, Error, ExpectationNotCalled, NotFound

Constant Summary collapse

VerifyError =

For backward-compatibility

ExpectationNotCalled
VERSION =
"1.2.0"

Class Method Summary collapse

Class Method Details

.add_response_body_for(key, expectation = {}) ⇒ Object

Raises:



51
52
53
54
# File 'lib/pact_expectations.rb', line 51

def add_response_body_for(key, expectation = {})
  raise DuplicatedKey if expectations.include?(key)
  expectations[key] = expectation
end

.reified_body_for(key) ⇒ Object

Raises:



62
63
64
65
66
# File 'lib/pact_expectations.rb', line 62

def reified_body_for(key)
  raise NotFound unless expectations.include?(key)
  reificated_call << key
  Pact::Reification.from_term(expectations[key])
end

.reset!Object



77
78
79
80
81
# File 'lib/pact_expectations.rb', line 77

def reset!
  @expectations = nil
  @response_call = nil
  @reificated_call = nil
end

.response_body_for(key) ⇒ Object

Raises:



56
57
58
59
60
# File 'lib/pact_expectations.rb', line 56

def response_body_for(key)
  raise NotFound unless expectations.include?(key)
  response_call << key
  expectations[key]
end

.verifyObject



68
69
70
71
72
73
74
75
# File 'lib/pact_expectations.rb', line 68

def verify
  not_call_responses = response_call ^ expectations.keys
  not_call_reificated = reificated_call ^ expectations.keys

  if !not_call_responses.empty? || !not_call_reificated.empty?
    raise ExpectationNotCalled.new(not_call_responses, not_call_reificated)
  end
end