web-console 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of web-console might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.markdown +121 -0
- data/Rakefile +48 -0
- data/app/assets/javascripts/web_console/application.js +4 -0
- data/app/assets/javascripts/web_console/console_sessions.js +24 -0
- data/app/assets/stylesheets/web_console/application.css +13 -0
- data/app/assets/stylesheets/web_console/console_sessions.css +8 -0
- data/app/controllers/web_console/application_controller.rb +12 -0
- data/app/controllers/web_console/console_sessions_controller.rb +23 -0
- data/app/helpers/web_console/application_helper.rb +4 -0
- data/app/helpers/web_console/console_session_helper.rb +4 -0
- data/app/models/web_console/console_session.rb +107 -0
- data/app/views/layouts/web_console/application.html.erb +14 -0
- data/app/views/web_console/console_sessions/index.html.erb +4 -0
- data/config/routes.rb +5 -0
- data/lib/web-console.rb +1 -0
- data/lib/web_console.rb +7 -0
- data/lib/web_console/engine.rb +38 -0
- data/lib/web_console/fiber.rb +48 -0
- data/lib/web_console/repl.rb +59 -0
- data/lib/web_console/repl/dummy.rb +38 -0
- data/lib/web_console/repl/irb.rb +61 -0
- data/lib/web_console/stream.rb +27 -0
- data/lib/web_console/version.rb +3 -0
- data/test/controllers/web_console/console_sessions_controller_test.rb +57 -0
- data/test/dummy/README.rdoc +28 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/stylesheets/application.css +13 -0
- data/test/dummy/app/controllers/application_controller.rb +5 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +15 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +29 -0
- data/test/dummy/config/environments/production.rb +80 -0
- data/test/dummy/config/environments/test.rb +36 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +12 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/routes.rb +2 -0
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/schema.rb +16 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/development.log +26591 -0
- data/test/dummy/log/test.log +78368 -0
- data/test/dummy/public/404.html +58 -0
- data/test/dummy/public/422.html +58 -0
- data/test/dummy/public/500.html +57 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/0280bb38c5058cc31c4fcd8c392a5ec4 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/05bd7b24c0a86010ebb28b50ac7cad52 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/2a48be7daff14cf56911b263cbe017c7 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/3a37adb5ebd079cf67dae597b8c2e4f8 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/4f79e5f341043e081becefe4952395c5 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/508ab3c25833ea537a5e3fc90df33595 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/5a8ab22e707dfc7ba00691f90e054d7e +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/5adcb7569cdd03204d650e285f19351f +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/654a1bde557d359b957dc0aa12b0dfa0 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/71f57313d6c92f5483915a6c2d79a506 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/7ec0041a47c34b44e52e836c01454a1a +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/a1534e0c08b73ad82c2edb8c364caa66 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/a841a3af20a321912acfed87036438fb +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/ad8eea7f774b674c29708ca90952764f +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/b0741545b4917192ba7b5e803c2e323d +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/b3159b06164dd474ff8efc3c84aefbba +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/b40b7c5b2003544010f30f0bd3fb81b2 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/bbbe6a3ce382662666a355d708c83d2d +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/c4e26d8dbebb3afd7013acfefa564dd1 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/ca53fb2717d5aac2f1c3939d9444fe3b +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/d6b37d10680a997662c379d0ff7cad27 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/e1d89809967e81220dca66770c50aa67 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/e3d5cafc071e8f9a8efc88fddf721947 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/f44e2a41bd51a92a84f99847ea675ba3 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/f4a21ed9cebe2c83a9d988504dc6720b +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/f4d45273ff5b44879dab0a16805f4309 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/f5deea0ae9671fdb035aefc6c4ba1109 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/0280bb38c5058cc31c4fcd8c392a5ec4 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/05bd7b24c0a86010ebb28b50ac7cad52 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/2a48be7daff14cf56911b263cbe017c7 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/3824a9e25e846a4916b3ac1d67060782 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/3a37adb5ebd079cf67dae597b8c2e4f8 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/4f79e5f341043e081becefe4952395c5 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/508ab3c25833ea537a5e3fc90df33595 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/5a8ab22e707dfc7ba00691f90e054d7e +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/5adcb7569cdd03204d650e285f19351f +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/632346eda030b596f513fff2de181743 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/654a1bde557d359b957dc0aa12b0dfa0 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/71f57313d6c92f5483915a6c2d79a506 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/9b9aee85f29dc573732fbb4001ceda00 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/a841a3af20a321912acfed87036438fb +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/bbbe6a3ce382662666a355d708c83d2d +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/ca53fb2717d5aac2f1c3939d9444fe3b +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/d6b37d10680a997662c379d0ff7cad27 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/e1d89809967e81220dca66770c50aa67 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/e3d5cafc071e8f9a8efc88fddf721947 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/f44e2a41bd51a92a84f99847ea675ba3 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/f4a21ed9cebe2c83a9d988504dc6720b +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/f4d45273ff5b44879dab0a16805f4309 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/f5deea0ae9671fdb035aefc6c4ba1109 +0 -0
- data/test/dummy/tmp/pids/server.pid +1 -0
- data/test/helpers/web_console/console_session_helper_test.rb +6 -0
- data/test/models/console_session_test.rb +110 -0
- data/test/test_helper.rb +15 -0
- data/test/web_console/repl/dummy_test.rb +54 -0
- data/test/web_console/repl/irb_test.rb +108 -0
- data/test/web_console/repl_test.rb +15 -0
- data/test/web_console_test.rb +91 -0
- data/vendor/assets/javascripts/jquery.console.js +727 -0
- metadata +303 -0
@@ -0,0 +1,58 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The page you were looking for doesn't exist (404)</title>
|
5
|
+
<style>
|
6
|
+
body {
|
7
|
+
background-color: #EFEFEF;
|
8
|
+
color: #2E2F30;
|
9
|
+
text-align: center;
|
10
|
+
font-family: arial, sans-serif;
|
11
|
+
}
|
12
|
+
|
13
|
+
div.dialog {
|
14
|
+
width: 25em;
|
15
|
+
margin: 4em auto 0 auto;
|
16
|
+
border: 1px solid #CCC;
|
17
|
+
border-right-color: #999;
|
18
|
+
border-left-color: #999;
|
19
|
+
border-bottom-color: #BBB;
|
20
|
+
border-top: #B00100 solid 4px;
|
21
|
+
border-top-left-radius: 9px;
|
22
|
+
border-top-right-radius: 9px;
|
23
|
+
background-color: white;
|
24
|
+
padding: 7px 4em 0 4em;
|
25
|
+
}
|
26
|
+
|
27
|
+
h1 {
|
28
|
+
font-size: 100%;
|
29
|
+
color: #730E15;
|
30
|
+
line-height: 1.5em;
|
31
|
+
}
|
32
|
+
|
33
|
+
body > p {
|
34
|
+
width: 33em;
|
35
|
+
margin: 0 auto 1em;
|
36
|
+
padding: 1em 0;
|
37
|
+
background-color: #F7F7F7;
|
38
|
+
border: 1px solid #CCC;
|
39
|
+
border-right-color: #999;
|
40
|
+
border-bottom-color: #999;
|
41
|
+
border-bottom-left-radius: 4px;
|
42
|
+
border-bottom-right-radius: 4px;
|
43
|
+
border-top-color: #DADADA;
|
44
|
+
color: #666;
|
45
|
+
box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
|
46
|
+
}
|
47
|
+
</style>
|
48
|
+
</head>
|
49
|
+
|
50
|
+
<body>
|
51
|
+
<!-- This file lives in public/404.html -->
|
52
|
+
<div class="dialog">
|
53
|
+
<h1>The page you were looking for doesn't exist.</h1>
|
54
|
+
<p>You may have mistyped the address or the page may have moved.</p>
|
55
|
+
</div>
|
56
|
+
<p>If you are the application owner check the logs for more information.</p>
|
57
|
+
</body>
|
58
|
+
</html>
|
@@ -0,0 +1,58 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The change you wanted was rejected (422)</title>
|
5
|
+
<style>
|
6
|
+
body {
|
7
|
+
background-color: #EFEFEF;
|
8
|
+
color: #2E2F30;
|
9
|
+
text-align: center;
|
10
|
+
font-family: arial, sans-serif;
|
11
|
+
}
|
12
|
+
|
13
|
+
div.dialog {
|
14
|
+
width: 25em;
|
15
|
+
margin: 4em auto 0 auto;
|
16
|
+
border: 1px solid #CCC;
|
17
|
+
border-right-color: #999;
|
18
|
+
border-left-color: #999;
|
19
|
+
border-bottom-color: #BBB;
|
20
|
+
border-top: #B00100 solid 4px;
|
21
|
+
border-top-left-radius: 9px;
|
22
|
+
border-top-right-radius: 9px;
|
23
|
+
background-color: white;
|
24
|
+
padding: 7px 4em 0 4em;
|
25
|
+
}
|
26
|
+
|
27
|
+
h1 {
|
28
|
+
font-size: 100%;
|
29
|
+
color: #730E15;
|
30
|
+
line-height: 1.5em;
|
31
|
+
}
|
32
|
+
|
33
|
+
body > p {
|
34
|
+
width: 33em;
|
35
|
+
margin: 0 auto 1em;
|
36
|
+
padding: 1em 0;
|
37
|
+
background-color: #F7F7F7;
|
38
|
+
border: 1px solid #CCC;
|
39
|
+
border-right-color: #999;
|
40
|
+
border-bottom-color: #999;
|
41
|
+
border-bottom-left-radius: 4px;
|
42
|
+
border-bottom-right-radius: 4px;
|
43
|
+
border-top-color: #DADADA;
|
44
|
+
color: #666;
|
45
|
+
box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
|
46
|
+
}
|
47
|
+
</style>
|
48
|
+
</head>
|
49
|
+
|
50
|
+
<body>
|
51
|
+
<!-- This file lives in public/422.html -->
|
52
|
+
<div class="dialog">
|
53
|
+
<h1>The change you wanted was rejected.</h1>
|
54
|
+
<p>Maybe you tried to change something you didn't have access to.</p>
|
55
|
+
</div>
|
56
|
+
<p>If you are the application owner check the logs for more information.</p>
|
57
|
+
</body>
|
58
|
+
</html>
|
@@ -0,0 +1,57 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>We're sorry, but something went wrong (500)</title>
|
5
|
+
<style>
|
6
|
+
body {
|
7
|
+
background-color: #EFEFEF;
|
8
|
+
color: #2E2F30;
|
9
|
+
text-align: center;
|
10
|
+
font-family: arial, sans-serif;
|
11
|
+
}
|
12
|
+
|
13
|
+
div.dialog {
|
14
|
+
width: 25em;
|
15
|
+
margin: 4em auto 0 auto;
|
16
|
+
border: 1px solid #CCC;
|
17
|
+
border-right-color: #999;
|
18
|
+
border-left-color: #999;
|
19
|
+
border-bottom-color: #BBB;
|
20
|
+
border-top: #B00100 solid 4px;
|
21
|
+
border-top-left-radius: 9px;
|
22
|
+
border-top-right-radius: 9px;
|
23
|
+
background-color: white;
|
24
|
+
padding: 7px 4em 0 4em;
|
25
|
+
}
|
26
|
+
|
27
|
+
h1 {
|
28
|
+
font-size: 100%;
|
29
|
+
color: #730E15;
|
30
|
+
line-height: 1.5em;
|
31
|
+
}
|
32
|
+
|
33
|
+
body > p {
|
34
|
+
width: 33em;
|
35
|
+
margin: 0 auto 1em;
|
36
|
+
padding: 1em 0;
|
37
|
+
background-color: #F7F7F7;
|
38
|
+
border: 1px solid #CCC;
|
39
|
+
border-right-color: #999;
|
40
|
+
border-bottom-color: #999;
|
41
|
+
border-bottom-left-radius: 4px;
|
42
|
+
border-bottom-right-radius: 4px;
|
43
|
+
border-top-color: #DADADA;
|
44
|
+
color: #666;
|
45
|
+
box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
|
46
|
+
}
|
47
|
+
</style>
|
48
|
+
</head>
|
49
|
+
|
50
|
+
<body>
|
51
|
+
<!-- This file lives in public/500.html -->
|
52
|
+
<div class="dialog">
|
53
|
+
<h1>We're sorry, but something went wrong.</h1>
|
54
|
+
</div>
|
55
|
+
<p>If you are the application owner check the logs for more information.</p>
|
56
|
+
</body>
|
57
|
+
</html>
|
File without changes
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1 @@
|
|
1
|
+
19295
|
@@ -0,0 +1,110 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module WebConsole
|
4
|
+
class ConsoleSessionTest < ActionView::TestCase
|
5
|
+
include ActiveModel::Lint::Tests
|
6
|
+
|
7
|
+
setup do
|
8
|
+
reset_persistent_storage!
|
9
|
+
@model1 = @model = new_valid_model
|
10
|
+
@model2 = new_valid_model
|
11
|
+
end
|
12
|
+
|
13
|
+
test 'consequential ids on creation' do
|
14
|
+
assert_equal 1, @model1.id
|
15
|
+
assert_equal 2, @model2.id
|
16
|
+
end
|
17
|
+
|
18
|
+
test 'populates output on save' do
|
19
|
+
model = new_model
|
20
|
+
assert_nil model.output
|
21
|
+
model.save(input: 'puts "foo"')
|
22
|
+
assert_match %r{foo}, model.output
|
23
|
+
end
|
24
|
+
|
25
|
+
test 'populates prompt on save' do
|
26
|
+
assert_not_nil @model.prompt
|
27
|
+
end
|
28
|
+
|
29
|
+
test 'preserved models can be found' do
|
30
|
+
id = @model.tap(&:save).id
|
31
|
+
assert_equal @model, ConsoleSession.find(id)
|
32
|
+
end
|
33
|
+
|
34
|
+
test 'trying to find a model fails if no longer in storage' do
|
35
|
+
assert_raises(ConsoleSession::NotFound) { ConsoleSession.find(0) }
|
36
|
+
end
|
37
|
+
|
38
|
+
test 'find coerces ids' do
|
39
|
+
id = @model.tap(&:save).id
|
40
|
+
assert_equal @model, ConsoleSession.find("#{id}")
|
41
|
+
end
|
42
|
+
|
43
|
+
test 'not found exceptions are json serializable' do
|
44
|
+
exception = assert_raises(ConsoleSession::NotFound) do
|
45
|
+
ConsoleSession.find(0)
|
46
|
+
end
|
47
|
+
assert_equal '{"error":"Session unavailable"}', exception.to_json
|
48
|
+
end
|
49
|
+
|
50
|
+
test 'persisted models knows that they are in memory' do
|
51
|
+
assert_not @model.persisted?
|
52
|
+
@model.save
|
53
|
+
assert @model.persisted?
|
54
|
+
end
|
55
|
+
|
56
|
+
test 'persisted models knows about their keys' do
|
57
|
+
assert_nil @model.to_key
|
58
|
+
@model.save
|
59
|
+
assert_equal [1], @model.to_key
|
60
|
+
end
|
61
|
+
|
62
|
+
test 'supports json serialization' do
|
63
|
+
with_dummy_adapter do
|
64
|
+
model = new_model
|
65
|
+
|
66
|
+
expected_nil_json = "{\"id\":3,\"input\":null,\"output\":null,\"prompt\":\"\\u003E\\u003E \"}"
|
67
|
+
assert_equal expected_nil_json, model.to_json
|
68
|
+
|
69
|
+
model.save(input: 'puts "foo"')
|
70
|
+
expected_json = "{\"id\":3,\"input\":\"puts \\\"foo\\\"\",\"output\":\"foo\\n=\\u003E nil\\n\",\"prompt\":\"\\u003E\\u003E \"}"
|
71
|
+
assert_equal expected_json, model.to_json
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
test 'create gives already persisted models' do
|
76
|
+
assert ConsoleSession.create.persisted?
|
77
|
+
end
|
78
|
+
|
79
|
+
test 'no gives not persisted models' do
|
80
|
+
assert_not ConsoleSession.new.persisted?
|
81
|
+
end
|
82
|
+
|
83
|
+
private
|
84
|
+
def new_model(attributes = {})
|
85
|
+
ConsoleSession.new(attributes)
|
86
|
+
end
|
87
|
+
|
88
|
+
def new_valid_model(attributes = {})
|
89
|
+
attributes.merge!(input: 'puts "foo"') unless attributes[:input].present?
|
90
|
+
new_model(attributes)
|
91
|
+
end
|
92
|
+
|
93
|
+
def reset_persistent_storage!
|
94
|
+
ConsoleSession::INMEMORY_STORAGE.clear
|
95
|
+
ConsoleSession.class_variable_set(:@@counter, 0)
|
96
|
+
end
|
97
|
+
|
98
|
+
def with_dummy_adapter
|
99
|
+
previous_method = WebConsole::REPL.method(:default)
|
100
|
+
WebConsole::REPL.module_eval do
|
101
|
+
define_singleton_method(:default) { WebConsole::REPL::Dummy }
|
102
|
+
end
|
103
|
+
yield
|
104
|
+
ensure
|
105
|
+
WebConsole::REPL.module_eval do
|
106
|
+
define_singleton_method(:default, &previous_method)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# Configure Rails Environment
|
2
|
+
ENV["RAILS_ENV"] = "test"
|
3
|
+
|
4
|
+
require File.expand_path("../dummy/config/environment.rb", __FILE__)
|
5
|
+
require "rails/test_help"
|
6
|
+
|
7
|
+
Rails.backtrace_cleaner.remove_silencers!
|
8
|
+
|
9
|
+
# Load support files
|
10
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
11
|
+
|
12
|
+
# Load fixtures from the engine
|
13
|
+
if ActiveSupport::TestCase.method_defined?(:fixture_path=)
|
14
|
+
ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
|
15
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class REPLTest < ActiveSupport::TestCase
|
4
|
+
setup do
|
5
|
+
@dummy1 = @dummy = WebConsole::REPL::Dummy.new
|
6
|
+
@dummy2 = WebConsole::REPL::Dummy.new
|
7
|
+
end
|
8
|
+
|
9
|
+
test 'sending input returns the result as output' do
|
10
|
+
assert_equal "=> 42\n", @dummy.send_input('foo = 42')
|
11
|
+
end
|
12
|
+
|
13
|
+
test 'preserves the session in the binding' do
|
14
|
+
assert_equal "=> 42\n", @dummy.send_input('foo = 42')
|
15
|
+
assert_equal "=> 50\n", @dummy.send_input('foo + 8')
|
16
|
+
end
|
17
|
+
|
18
|
+
test 'session isolation requires own bindings' do
|
19
|
+
dummy1 = WebConsole::REPL::IRB.new(Object.new.instance_eval('binding'))
|
20
|
+
dummy2 = WebConsole::REPL::IRB.new(Object.new.instance_eval('binding'))
|
21
|
+
assert_equal "=> 42\n", dummy1.send_input('foo = 42')
|
22
|
+
assert_match %r{NameError}, dummy2.send_input('foo')
|
23
|
+
end
|
24
|
+
|
25
|
+
test 'session preservation requires same bindings' do
|
26
|
+
assert_equal "=> 42\n", @dummy1.send_input('foo = 42')
|
27
|
+
assert_equal "=> 42\n", @dummy2.send_input('foo')
|
28
|
+
end
|
29
|
+
|
30
|
+
test 'captures stdout output' do
|
31
|
+
assert_equal "42\n=> nil\n", @dummy.send_input('puts 42')
|
32
|
+
end
|
33
|
+
|
34
|
+
test 'captures stderr output' do
|
35
|
+
assert_equal "42\n=> 3\n", @dummy.send_input('$stderr.write("42\n")')
|
36
|
+
end
|
37
|
+
|
38
|
+
test 'prompt is present' do
|
39
|
+
assert_not_nil @dummy.prompt
|
40
|
+
end
|
41
|
+
|
42
|
+
test 'rails helpers are available in the session' do
|
43
|
+
each_rails_console_method do |meth|
|
44
|
+
assert_equal "=> true\n", @dummy.send_input("respond_to? :#{meth}")
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
def each_rails_console_method(&block)
|
50
|
+
require 'rails/console/app'
|
51
|
+
require 'rails/console/helpers'
|
52
|
+
Rails::ConsoleMethods.public_instance_methods.each(&block)
|
53
|
+
end
|
54
|
+
end
|