File: config.ru

package info (click to toggle)
ruby-web-console 4.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 656 kB
  • sloc: ruby: 1,496; javascript: 497; sh: 19; makefile: 4
file content (53 lines) | stat: -rw-r--r-- 1,528 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
require "web_console/testing/fake_middleware"

TEST_ROOT = Pathname(__FILE__).dirname

# e.g. "/node_modules/mocha/mocha.js"
map "/node_modules" do
  node_modules = TEST_ROOT.join("node_modules")
  unless node_modules.directory?
    abort "ERROR: the node_modules/ directory is not found (You must run `npm install`)"
  end
  run Rack::Directory.new(node_modules)
end

# test runners
map "/html" do
  run WebConsole::Testing::FakeMiddleware.new(
    req_path_regex: %r{^/html/(.*)},
    headers: {Rack::CONTENT_TYPE => "text/html"},
    view_path: TEST_ROOT.join("html"),
  )
end

map "/test" do
  run WebConsole::Testing::FakeMiddleware.new(
    req_path_regex: %r{^/test/(.*)},
    view_path: TEST_ROOT.join("test"),
  )
end

map "/templates" do
  run WebConsole::Testing::FakeMiddleware.new(
    req_path_regex: %r{^/templates/(.*)},
    view_path: TEST_ROOT.join("../../lib/web_console/templates"),
  )
end

map "/mock/repl_sessions/result" do
  headers = { Rack::CONTENT_TYPE => 'application/json' }
  body = [ { output: '=> "fake-result"\n', context: [ [ :something, :somewhat, :somewhere ] ] }.to_json ]
  run lambda { |env| [ 200, headers, body ] }
end

map "/mock/repl_sessions/error" do
  headers = { Rack::CONTENT_TYPE => 'application/json' }
  body = [ { output: 'fake-error-message' }.to_json ]
  run lambda { |env| [ 400, headers, body ] }
end

map "/mock/repl_sessions/error.txt" do
  headers = { Rack::CONTENT_TYPE => 'plain/text' }
  body = [ 'error message' ]
  run lambda { |env| [ 400, headers, body ] }
end