Class: WebConsole::Testing::FakeMiddleware

Inherits:
Object
  • Object
show all
Defined in:
lib/web_console/testing/fake_middleware.rb

Constant Summary collapse

DEFAULT_HEADERS =
{ Rack::CONTENT_TYPE => "application/javascript" }

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ FakeMiddleware

Returns a new instance of FakeMiddleware.



15
16
17
18
19
# File 'lib/web_console/testing/fake_middleware.rb', line 15

def initialize(opts)
  @headers        = opts.fetch(:headers, DEFAULT_HEADERS)
  @req_path_regex = opts[:req_path_regex]
  @view_path      = opts[:view_path]
end

Instance Method Details

#call(env) ⇒ Object



21
22
23
24
25
26
# File 'lib/web_console/testing/fake_middleware.rb', line 21

def call(env)
  body = render(req_path(env))
  @headers[Rack::CONTENT_LENGTH] = body.bytesize.to_s

  [ 200, @headers, [ body ] ]
end

#viewObject



28
29
30
# File 'lib/web_console/testing/fake_middleware.rb', line 28

def view
  @view = View.with_empty_template_cache.with_view_paths(@view_path)
end