Sha256: 3273ef2ac90bc1bf5a8495e7b537ee0af8805a86e79022942cce35998659bd3f

Contents?: true

Size: 1.13 KB

Versions: 2

Compression:

Stored size: 1.13 KB

Contents

# -*- encoding : utf-8 -*-
begin
  require 'pacto'
  require 'pacto/server'
rescue LoadError
  raise 'pacto/test_helper requires the pacto-server gem'
end

module Pacto
  module TestHelper
    DEFAULT_ARGS = {
      stdout: true,
      log_file: 'pacto.log',
      # :config => 'pacto/config/pacto_server.rb',
      strict: false,
      stub: true,
      live: false,
      generate: false,
      verbose: true,
      validate: true,
      directory: File.join(Dir.pwd, 'contracts'),
      port: 9000,
      format: :legacy,
      stenographer_log_file: File.expand_path('pacto_stenographer.log', Dir.pwd),
      strip_port: true
    }

    def with_pacto(args = {})
      start_index = ::Pacto::InvestigationRegistry.instance.investigations.size
      ::Pacto::InvestigationRegistry.instance.investigations.clear
      args = DEFAULT_ARGS.merge(args)
      args[:spy] = args[:verbose]
      server = Pacto::Server::HTTP.supervise('0.0.0.0', args[:port], args)
      yield "http://localhost:#{args[:port]}"
      ::Pacto::InvestigationRegistry.instance.investigations[start_index, -1]
    ensure
      server.terminate unless server.nil?
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pacto-0.4.0.rc3 lib/pacto/test_helper.rb
pacto-0.4.0.rc2 lib/pacto/test_helper.rb