Class: WebConsole::Testing::FakeMiddleware
- Inherits:
-
Object
- Object
- WebConsole::Testing::FakeMiddleware
- Defined in:
- lib/web_console/testing/fake_middleware.rb
Constant Summary collapse
- DEFAULT_HEADERS =
{ Rack::CONTENT_TYPE => "application/javascript" }
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(opts) ⇒ FakeMiddleware
constructor
A new instance of FakeMiddleware.
- #view ⇒ Object
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 |
#view ⇒ Object
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 |