# class WebConsole::Testing::FakeMiddleware

### Constants

DEFAULT_HEADERS

### Public Class Methods

new(opts) click to toggle source

    # File lib/web_console/testing/fake_middleware.rb, line 13
    def initialize(opts)
      @headers        = opts.fetch(:headers, DEFAULT_HEADERS)
      @req_path_regex = opts[:req_path_regex]
      @view_path      = opts[:view_path]
    end

### Public Instance Methods

call(env) click to toggle source

    # File lib/web_console/testing/fake_middleware.rb, line 19
    def call(env)
      [ 200, @headers, [ render(req_path(env)) ] ]
    end

view() click to toggle source

    # File lib/web_console/testing/fake_middleware.rb, line 23
    def view
      @view ||= View.new(@view_path)
    end

### Private Instance Methods

render(template) click to toggle source

    # File lib/web_console/testing/fake_middleware.rb, line 34
    def render(template)
      view.render(template: template, layout: nil)
    end

req_path(env) click to toggle source

extract target path from REQUEST_PATH

    # File lib/web_console/testing/fake_middleware.rb, line 30
    def req_path(env)
      env["REQUEST_PATH"].match(@req_path_regex)[1]
    end