Sha256: 54c7322e427b6ddd45ff9df90f8ef724b9cab577ca0ba2bb0e15f31262c48aac

Contents?: true

Size: 569 Bytes

Versions: 1

Compression:

Stored size: 569 Bytes

Contents

require "mocktra/version"
require 'webmock'
require 'sinatra/base'

WebMock.allow_net_connect!

module Mocktra
  class << self
    def mocktra(pattern, &block)
      pattern = case pattern
        when Regexp
          pattern
        when /^http/
          /^#{Regexp.quote(pattern)}/
        else
          /#{Regexp.quote(pattern)}/
        end
      rack_app = Class.new(Sinatra::Base, &block)
      WebMock::API.stub_request(:any, pattern).to_rack(rack_app)
    end
  end
end

module Kernel
  def Mocktra(*args, &block)
    Mocktra.mocktra(*args, &block)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mocktra-1.0.1 lib/mocktra.rb