Module: Jets::SpecHelpers

Defined in:
lib/jets/spec_helpers.rb,
lib/jets/spec_helpers/params.rb,
lib/jets/spec_helpers/request.rb,
lib/jets/spec_helpers/response.rb

Defined Under Namespace

Classes: Params, Request, Response

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#requestObject (readonly)

Returns the value of attribute request.



11
12
13
# File 'lib/jets/spec_helpers.rb', line 11

def request
  @request
end

#responseObject (readonly)

Returns the value of attribute response.



11
12
13
# File 'lib/jets/spec_helpers.rb', line 11

def response
  @response
end

Instance Method Details

#fixture_file(filename) ⇒ Object



49
50
51
# File 'lib/jets/spec_helpers.rb', line 49

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

#fixture_path(filename) ⇒ Object



45
46
47
# File 'lib/jets/spec_helpers.rb', line 45

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

#http_call(method:, path:, **params) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/jets/spec_helpers.rb', line 29

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

#initializeObject



12
13
14
15
16
# File 'lib/jets/spec_helpers.rb', line 12

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