Module: Pact::TaskHelper

Included in:
VerificationTask
Defined in:
lib/pact/tasks/task_helper.rb

Instance Method Summary collapse

Instance Method Details

#failure_messageObject



3
4
5
6
7
8
9
# File 'lib/pact/tasks/task_helper.rb', line 3

def failure_message
  redify(
    "\n* * * * * * * * * * * * * * * * * * *\n" +
    "Provider did not honour pact file.\nSee\n * #{Pact.configuration.log_path}\n * #{Pact.configuration.tmp_dir}\nfor logs and pact files." +
    "\n* * * * * * * * * * * * * * * * * * *\n\n"
  )
end

#handle_verification_failureObject



15
16
17
18
19
20
21
# File 'lib/pact/tasks/task_helper.rb', line 15

def handle_verification_failure
  exit_status = yield
  if exit_status != 0
    $stderr.puts failure_message
    fail
  end
end

#redify(string) ⇒ Object



11
12
13
# File 'lib/pact/tasks/task_helper.rb', line 11

def redify string
  "\e[31m#{string}\e[m"
end

#spec_criteria(defaults = {description: nil, provider_state: nil}) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/pact/tasks/task_helper.rb', line 23

def spec_criteria defaults = {description: nil, provider_state: nil}
  criteria = {}
  [:description, :provider_state].each  do | key |
    value = ENV.fetch("PACT_#{key.to_s.upcase}", defaults[key])
    criteria[key] = Regexp.new(value) unless value.nil?
  end
  criteria.any? ? criteria : nil
end