Sha256: 17a35650269898cc0ac91b621a5d776813dcaba2e4b97955798630e98e41228b

Contents?: true

Size: 1.31 KB

Versions: 28

Compression:

Stored size: 1.31 KB

Contents

# frozen_string_literal: true

require 'base64'

module Jets
  module SpecHelpers
    attr_reader :request, :response
    def initialize(*)
      super
      @request = Request.new(:get, '/', {}, Params.new)
      @response = nil # will be set after http_call
    end

    rest_methods = %w[get post put patch delete]
    rest_methods.each do |meth|
      define_method(meth) do |path, **params|
        http_call(method: meth, path: path, **params)
      end
      # Example:
      # def get(path, **params)
      #   http_call(method: :get, path: path, **params)
      # end
    end

    def http_call(method:, path:, **params)
      request.method = method.to_sym
      request.path = path
      request.headers.deep_merge!(params.delete(:headers) || {})

      request.params.body_params = params.delete(:params) || params || {}

      request.params.query_params = params.delete(:query)
      request.params.query_params ||= params if request.method == :get
      request.params.query_params ||= {}

      request.params.path_params = params

      @response = request.dispatch!
    end

    def fixture_path(filename)
      "#{Jets.root}/spec/fixtures/#{filename}"
    end

    def fixture_file(filename)
      File.new(fixture_path(filename))
    end
  end
end

require "rspec"
RSpec.configure do |c|
  c.include Jets::SpecHelpers
end

Version data entries

28 entries across 28 versions & 2 rubygems

Version Path
jets_bb_fork-0.0.4 lib/jets/spec_helpers.rb
jets-2.0.1 lib/jets/spec_helpers.rb
jets-2.0.0 lib/jets/spec_helpers.rb
jets-1.9.32 lib/jets/spec_helpers.rb
jets-1.9.31 lib/jets/spec_helpers.rb
jets-1.9.30 lib/jets/spec_helpers.rb
jets-1.9.29 lib/jets/spec_helpers.rb
jets-1.9.28 lib/jets/spec_helpers.rb
jets-1.9.27 lib/jets/spec_helpers.rb
jets-1.9.26 lib/jets/spec_helpers.rb
jets-1.9.25 lib/jets/spec_helpers.rb
jets-1.9.24 lib/jets/spec_helpers.rb
jets-1.9.23 lib/jets/spec_helpers.rb
jets-1.9.22 lib/jets/spec_helpers.rb
jets-1.9.21 lib/jets/spec_helpers.rb
jets-1.9.20 lib/jets/spec_helpers.rb
jets-1.9.19 lib/jets/spec_helpers.rb
jets-1.9.18 lib/jets/spec_helpers.rb
jets-1.9.17 lib/jets/spec_helpers.rb
jets-1.9.16 lib/jets/spec_helpers.rb