screw-unit-server 0.3.0 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +23 -1
- data/README.markdown +10 -3
- data/Rakefile +27 -55
- data/VERSION.yml +4 -0
- data/bin/screw_unit_server +14 -4
- data/core/CHANGES +10 -0
- data/core/EXAMPLE.html +4 -4
- data/core/README.markdown +7 -7
- data/core/example/models/man.js +2 -2
- data/core/example/spec/suite.html +1 -1
- data/core/lib/jquery-1.3.2.js +4376 -0
- data/core/lib/jquery.fn.js +2 -1
- data/core/lib/jquery.print.js +13 -12
- data/core/lib/screw.behaviors.js +11 -9
- data/core/lib/screw.builder.js +26 -11
- data/core/lib/screw.css +2 -2
- data/core/lib/screw.events.js +11 -4
- data/core/lib/screw.matchers.js +192 -13
- data/core/spec/behaviors_spec.js +11 -1
- data/core/spec/matchers_spec.js +288 -9
- data/core/spec/print_spec.js +47 -8
- data/core/spec/suite.html +2 -1
- data/core/spec/with_screw_context_spec.js +9 -0
- data/lib/screw_unit.rb +13 -16
- data/lib/screw_unit/representations.rb +2 -0
- data/lib/screw_unit/representations/spec.html.rb +117 -0
- data/spec/functional/functional_spec.rb +14 -3
- data/spec/functional/functional_spec_helper.rb +22 -34
- data/spec/functional/functional_spec_server_starter.rb +68 -0
- data/spec/unit/js_test_core/specs/spec_file_spec.rb +45 -20
- data/spec/unit/unit_spec_helper.rb +24 -93
- data/vendor/js-test-core/CHANGES +19 -0
- data/vendor/js-test-core/Rakefile +2 -1
- data/vendor/js-test-core/lib/js_test_core.rb +26 -10
- data/vendor/js-test-core/lib/js_test_core/app.rb +12 -0
- data/vendor/js-test-core/lib/js_test_core/client.rb +97 -18
- data/vendor/js-test-core/lib/js_test_core/configuration.rb +35 -0
- data/vendor/js-test-core/lib/js_test_core/extensions.rb +3 -0
- data/vendor/js-test-core/lib/js_test_core/extensions/selenium/client/driver.rb +7 -0
- data/vendor/js-test-core/lib/js_test_core/extensions/time.rb +6 -0
- data/vendor/js-test-core/lib/js_test_core/models.rb +8 -0
- data/vendor/js-test-core/lib/js_test_core/models/selenium_session.rb +80 -0
- data/vendor/js-test-core/lib/js_test_core/representations.rb +11 -0
- data/vendor/js-test-core/lib/js_test_core/representations/dir.html.rb +24 -0
- data/vendor/js-test-core/lib/js_test_core/representations/not_found.html.rb +15 -0
- data/vendor/js-test-core/lib/js_test_core/representations/page.html.rb +41 -0
- data/vendor/js-test-core/lib/js_test_core/representations/spec.html.rb +24 -0
- data/vendor/js-test-core/lib/js_test_core/resources.rb +13 -8
- data/vendor/js-test-core/lib/js_test_core/resources/core_file.rb +19 -0
- data/vendor/js-test-core/lib/js_test_core/resources/file.rb +44 -14
- data/vendor/js-test-core/lib/js_test_core/resources/implementations_deprecation.rb +12 -0
- data/vendor/js-test-core/lib/js_test_core/resources/not_found.rb +35 -0
- data/vendor/js-test-core/lib/js_test_core/resources/resource.rb +16 -0
- data/vendor/js-test-core/lib/js_test_core/resources/selenium_session.rb +104 -0
- data/vendor/js-test-core/lib/js_test_core/resources/spec_file.rb +63 -0
- data/vendor/js-test-core/lib/js_test_core/resources/web_root.rb +5 -56
- data/vendor/js-test-core/lib/js_test_core/selenium_server_configuration.rb +48 -0
- data/vendor/js-test-core/spec/example_core/subdir/SubDirFile.js +0 -0
- data/vendor/js-test-core/spec/example_public/javascripts/large_file.js +59 -0
- data/vendor/js-test-core/spec/example_public/javascripts/subdir/bar.js +1 -0
- data/vendor/js-test-core/spec/example_specs/custom_dir_and_suite/passing_spec.js +6 -0
- data/vendor/js-test-core/spec/example_specs/custom_suite.html +8 -0
- data/vendor/js-test-core/spec/example_specs/foo/failing_spec.js +1 -1
- data/vendor/js-test-core/spec/example_specs/foo/passing_spec.js +1 -1
- data/vendor/js-test-core/spec/spec_helpers/be_http.rb +32 -0
- data/vendor/js-test-core/spec/spec_helpers/example_group.rb +36 -0
- data/vendor/js-test-core/spec/spec_helpers/fake_selenium_driver.rb +27 -0
- data/vendor/js-test-core/spec/spec_helpers/show_test_exceptions.rb +22 -0
- data/vendor/js-test-core/spec/unit/js_test_core/client_spec.rb +140 -85
- data/vendor/js-test-core/spec/unit/js_test_core/configuration_spec.rb +44 -0
- data/vendor/js-test-core/spec/unit/js_test_core/models/selenium_session_spec.rb +85 -0
- data/vendor/js-test-core/spec/unit/js_test_core/resources/core_file_spec.rb +60 -0
- data/vendor/js-test-core/spec/unit/js_test_core/resources/file_spec.rb +61 -68
- data/vendor/js-test-core/spec/unit/js_test_core/resources/implementations_deprecation_spec.rb +18 -0
- data/vendor/js-test-core/spec/unit/js_test_core/resources/not_found_spec.rb +51 -0
- data/vendor/js-test-core/spec/unit/js_test_core/resources/selenium_session_spec.rb +362 -0
- data/vendor/js-test-core/spec/unit/js_test_core/resources/spec_file_spec.rb +120 -0
- data/vendor/js-test-core/spec/unit/js_test_core/resources/web_root_spec.rb +14 -89
- data/vendor/js-test-core/spec/unit/js_test_core/selenium_server_configuration_spec.rb +49 -0
- data/vendor/js-test-core/spec/unit/unit_spec_helper.rb +16 -113
- data/vendor/js-test-core/vendor/lucky-luciano/README.markdown +7 -0
- data/vendor/js-test-core/vendor/lucky-luciano/lib/lucky_luciano.rb +4 -0
- data/vendor/js-test-core/vendor/lucky-luciano/lib/lucky_luciano/resource.rb +135 -0
- data/vendor/js-test-core/vendor/lucky-luciano/lib/lucky_luciano/rspec.rb +4 -0
- data/vendor/js-test-core/vendor/lucky-luciano/lib/lucky_luciano/rspec/be_http.rb +32 -0
- data/vendor/js-test-core/vendor/lucky-luciano/spec/lucky_luciano/resource_spec.rb +231 -0
- data/vendor/js-test-core/vendor/lucky-luciano/spec/spec_helper.rb +48 -0
- data/vendor/js-test-core/vendor/lucky-luciano/spec/spec_suite.rb +4 -0
- metadata +143 -129
- data/core/TODO +0 -2
- data/core/lib/jquery-1.2.3.js +0 -3408
- data/core/lib/screw.assets.js +0 -36
- data/core/lib/screw.server.js +0 -21
- data/lib/screw_unit/resources.rb +0 -2
- data/lib/screw_unit/resources/spec.rb +0 -37
- data/spec/unit/js_test_core/specs/spec_dir_spec.rb +0 -43
- data/vendor/js-test-core/lib/js_test_core/rack.rb +0 -2
- data/vendor/js-test-core/lib/js_test_core/rack/commonlogger.rb +0 -5
- data/vendor/js-test-core/lib/js_test_core/rails_server.rb +0 -22
- data/vendor/js-test-core/lib/js_test_core/resources/dir.rb +0 -52
- data/vendor/js-test-core/lib/js_test_core/resources/file_not_found.rb +0 -15
- data/vendor/js-test-core/lib/js_test_core/resources/runners.rb +0 -15
- data/vendor/js-test-core/lib/js_test_core/resources/runners/firefox_runner.rb +0 -75
- data/vendor/js-test-core/lib/js_test_core/resources/specs/spec_dir.rb +0 -50
- data/vendor/js-test-core/lib/js_test_core/resources/specs/spec_file.rb +0 -17
- data/vendor/js-test-core/lib/js_test_core/resources/suite.rb +0 -24
- data/vendor/js-test-core/lib/js_test_core/resources/suite_finish.rb +0 -19
- data/vendor/js-test-core/lib/js_test_core/selenium.rb +0 -2
- data/vendor/js-test-core/lib/js_test_core/selenium/selenium_driver.rb +0 -5
- data/vendor/js-test-core/lib/js_test_core/server.rb +0 -111
- data/vendor/js-test-core/lib/js_test_core/thin.rb +0 -3
- data/vendor/js-test-core/lib/js_test_core/thin/backends/js_test_core_server.rb +0 -9
- data/vendor/js-test-core/lib/js_test_core/thin/js_test_core_connection.rb +0 -42
- data/vendor/js-test-core/spec/unit/js_test_core/rails_server_spec.rb +0 -45
- data/vendor/js-test-core/spec/unit/js_test_core/resources/dir_spec.rb +0 -42
- data/vendor/js-test-core/spec/unit/js_test_core/resources/file_not_found_spec.rb +0 -26
- data/vendor/js-test-core/spec/unit/js_test_core/resources/runner_spec.rb +0 -24
- data/vendor/js-test-core/spec/unit/js_test_core/resources/runners/firefox_runner_spec.rb +0 -197
- data/vendor/js-test-core/spec/unit/js_test_core/resources/specs/spec_dir_spec.rb +0 -79
- data/vendor/js-test-core/spec/unit/js_test_core/resources/specs/spec_file_spec.rb +0 -42
- data/vendor/js-test-core/spec/unit/js_test_core/resources/suite_finish_spec.rb +0 -94
- data/vendor/js-test-core/spec/unit/js_test_core/resources/suite_spec.rb +0 -44
- data/vendor/js-test-core/spec/unit/js_test_core/server_spec.rb +0 -131
- data/vendor/js-test-core/spec/unit/thin/js_test_core_connection_spec.rb +0 -92
@@ -0,0 +1,41 @@
|
|
1
|
+
module JsTestCore
|
2
|
+
module Representations
|
3
|
+
class Page < Erector::Widget
|
4
|
+
def content(&block)
|
5
|
+
rawtext %Q{<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">}
|
6
|
+
html :xmlns => "http://www.w3.org/1999/xhtml", :"xml:lang" => "en" do
|
7
|
+
head do
|
8
|
+
meta :"http-equiv" => "Content-Type", :content => "text/html;charset=UTF-8"
|
9
|
+
title title_text
|
10
|
+
head_content
|
11
|
+
end
|
12
|
+
body do
|
13
|
+
body_content(&block)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
protected
|
19
|
+
def head_content
|
20
|
+
end
|
21
|
+
|
22
|
+
def title_text
|
23
|
+
"Thin Rest"
|
24
|
+
end
|
25
|
+
|
26
|
+
def body_content(&block)
|
27
|
+
yield(self)
|
28
|
+
end
|
29
|
+
|
30
|
+
def path
|
31
|
+
helpers.rack_request.path_info
|
32
|
+
end
|
33
|
+
|
34
|
+
def script_elements
|
35
|
+
end
|
36
|
+
|
37
|
+
def link_elements
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module JsTestCore
|
2
|
+
module Representations
|
3
|
+
class Spec < Page
|
4
|
+
needs :spec_files
|
5
|
+
protected
|
6
|
+
def title_text
|
7
|
+
"Js Test Core Suite"
|
8
|
+
end
|
9
|
+
|
10
|
+
def head_content
|
11
|
+
spec_script_elements
|
12
|
+
end
|
13
|
+
|
14
|
+
def spec_script_elements
|
15
|
+
spec_files.each do |file|
|
16
|
+
script :type => "text/javascript", :src => file
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def body_content
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -1,11 +1,16 @@
|
|
1
1
|
dir = File.dirname(__FILE__)
|
2
|
-
|
3
|
-
|
2
|
+
|
3
|
+
module JsTestCore
|
4
|
+
module Resources
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
require "#{dir}/resources/resource"
|
9
|
+
require "#{dir}/resources/selenium_session"
|
4
10
|
require "#{dir}/resources/file"
|
5
|
-
require "#{dir}/resources/
|
6
|
-
require "#{dir}/resources/
|
7
|
-
require "#{dir}/resources/specs/spec_file"
|
8
|
-
require "#{dir}/resources/specs/spec_dir"
|
11
|
+
require "#{dir}/resources/spec_file"
|
12
|
+
require "#{dir}/resources/core_file"
|
9
13
|
require "#{dir}/resources/web_root"
|
10
|
-
require "#{dir}/resources/
|
11
|
-
|
14
|
+
require "#{dir}/resources/not_found"
|
15
|
+
|
16
|
+
require "#{dir}/resources/implementations_deprecation"
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module JsTestCore
|
2
|
+
module Resources
|
3
|
+
class CoreFile < File
|
4
|
+
map "/core"
|
5
|
+
|
6
|
+
get "/?" do
|
7
|
+
do_get
|
8
|
+
end
|
9
|
+
|
10
|
+
get "*" do
|
11
|
+
do_get
|
12
|
+
end
|
13
|
+
|
14
|
+
def absolute_path
|
15
|
+
@absolute_path ||= ::File.expand_path("#{core_path}#{relative_path.gsub(%r{^/core}, "")}")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -1,32 +1,62 @@
|
|
1
1
|
module JsTestCore
|
2
2
|
module Resources
|
3
|
-
class File
|
3
|
+
class File < Resource
|
4
|
+
map "*"
|
5
|
+
|
4
6
|
MIME_TYPES = {
|
7
|
+
'.html' => 'text/html',
|
8
|
+
'.htm' => 'text/html',
|
5
9
|
'.js' => 'text/javascript',
|
6
10
|
'.css' => 'text/css',
|
7
11
|
'.png' => 'image/png',
|
8
12
|
'.jpg' => 'image/jpeg',
|
9
13
|
'.jpeg' => 'image/jpeg',
|
10
14
|
'.gif' => 'image/gif',
|
11
|
-
|
15
|
+
}
|
12
16
|
|
13
|
-
|
17
|
+
get "*" do
|
18
|
+
do_get
|
19
|
+
end
|
20
|
+
|
21
|
+
def relative_path
|
22
|
+
@relative_path ||= request.path_info
|
23
|
+
end
|
14
24
|
|
15
|
-
def
|
16
|
-
@absolute_path
|
17
|
-
@relative_path = relative_path
|
25
|
+
def absolute_path
|
26
|
+
@absolute_path ||= ::File.expand_path("#{public_path}#{relative_path}")
|
18
27
|
end
|
19
28
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
29
|
+
protected
|
30
|
+
|
31
|
+
def do_get
|
32
|
+
if ::File.exists?(absolute_path)
|
33
|
+
if ::File.directory?(absolute_path)
|
34
|
+
render_dir
|
35
|
+
else
|
36
|
+
render_file
|
37
|
+
end
|
38
|
+
else
|
39
|
+
pass
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def render_dir
|
44
|
+
Representations::Dir.new(:relative_path => relative_path, :absolute_path => absolute_path).to_s
|
24
45
|
end
|
25
46
|
|
26
|
-
def
|
27
|
-
|
28
|
-
|
47
|
+
def render_file
|
48
|
+
extension = ::File.extname(absolute_path)
|
49
|
+
content_type = MIME_TYPES[extension] || 'text/html'
|
50
|
+
[
|
51
|
+
200,
|
52
|
+
{
|
53
|
+
'Content-Type' => content_type,
|
54
|
+
'Last-Modified' => ::File.mtime(absolute_path).rfc822,
|
55
|
+
'Content-Length' => ::File.size(absolute_path)
|
56
|
+
},
|
57
|
+
::File.read(absolute_path)
|
58
|
+
]
|
29
59
|
end
|
30
60
|
end
|
31
61
|
end
|
32
|
-
end
|
62
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module JsTestCore
|
2
|
+
module Resources
|
3
|
+
class ImplementationsDeprecation < Resource
|
4
|
+
map "/implementations"
|
5
|
+
|
6
|
+
get "*" do
|
7
|
+
new_path = File.path("javascripts", *params["splat"])
|
8
|
+
[301, {'Location' => new_path}, "This page has been moved to #{new_path}"]
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module JsTestCore
|
2
|
+
module Resources
|
3
|
+
class NotFound < Resource
|
4
|
+
map "*"
|
5
|
+
|
6
|
+
get "/" do
|
7
|
+
call
|
8
|
+
end
|
9
|
+
|
10
|
+
put "/" do
|
11
|
+
call
|
12
|
+
end
|
13
|
+
|
14
|
+
post "/" do
|
15
|
+
call
|
16
|
+
end
|
17
|
+
|
18
|
+
delete "/" do
|
19
|
+
call
|
20
|
+
end
|
21
|
+
|
22
|
+
def call
|
23
|
+
body = Representations::NotFound.new(:message => "File #{request.path_info} not found").to_s
|
24
|
+
[
|
25
|
+
404,
|
26
|
+
{
|
27
|
+
"Content-Type" => "text/html",
|
28
|
+
"Content-Length" => body.size.to_s
|
29
|
+
},
|
30
|
+
body
|
31
|
+
]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module JsTestCore
|
2
|
+
module Resources
|
3
|
+
class Resource < LuckyLuciano::Resource
|
4
|
+
protected
|
5
|
+
|
6
|
+
def spec_root_path; server.spec_root_path; end
|
7
|
+
def public_path; server.public_path; end
|
8
|
+
def core_path; server.core_path; end
|
9
|
+
def root_url; server.root_url; end
|
10
|
+
|
11
|
+
def server
|
12
|
+
JsTestCore::Configuration
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
module JsTestCore
|
2
|
+
module Resources
|
3
|
+
class SeleniumSession < Resource
|
4
|
+
map "/selenium_sessions"
|
5
|
+
|
6
|
+
post "/" do
|
7
|
+
do_post params["selenium_browser_start_command"]
|
8
|
+
end
|
9
|
+
|
10
|
+
post "/firefox" do
|
11
|
+
do_post "*firefox"
|
12
|
+
end
|
13
|
+
|
14
|
+
post '/iexplore' do |env, name|
|
15
|
+
do_post "*iexplore"
|
16
|
+
end
|
17
|
+
|
18
|
+
get "/:session_id" do
|
19
|
+
do_get
|
20
|
+
end
|
21
|
+
|
22
|
+
post "/finish" do
|
23
|
+
do_finish
|
24
|
+
end
|
25
|
+
|
26
|
+
post "/:session_id/finish" do
|
27
|
+
do_finish
|
28
|
+
end
|
29
|
+
|
30
|
+
include FileUtils
|
31
|
+
RUNNING = 'running'
|
32
|
+
SUCCESSFUL_COMPLETION = 'success'
|
33
|
+
FAILURE_COMPLETION = 'failure'
|
34
|
+
|
35
|
+
protected
|
36
|
+
|
37
|
+
def do_get
|
38
|
+
selenium_session = Models::SeleniumSession.find(session_id)
|
39
|
+
if selenium_session
|
40
|
+
body = if selenium_session.running?
|
41
|
+
"status=#{RUNNING}"
|
42
|
+
else
|
43
|
+
if selenium_session.successful?
|
44
|
+
"status=#{SUCCESSFUL_COMPLETION}"
|
45
|
+
else
|
46
|
+
"status=#{FAILURE_COMPLETION}&reason=#{selenium_session.run_result}"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
[
|
50
|
+
200,
|
51
|
+
{'Content-Length' => body.length},
|
52
|
+
body
|
53
|
+
]
|
54
|
+
else
|
55
|
+
body = Representations::NotFound.new(:message => "Could not find session #{session_id}").to_s
|
56
|
+
[
|
57
|
+
404,
|
58
|
+
{
|
59
|
+
"Content-Type" => "text/html",
|
60
|
+
"Content-Length" => body.size.to_s
|
61
|
+
},
|
62
|
+
body
|
63
|
+
]
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def do_finish
|
68
|
+
if selenium_session = Models::SeleniumSession.find(session_id)
|
69
|
+
selenium_session.finish(request['text'])
|
70
|
+
else
|
71
|
+
STDOUT.puts request['text']
|
72
|
+
end
|
73
|
+
[200, {}, request['text']]
|
74
|
+
end
|
75
|
+
|
76
|
+
def session_id
|
77
|
+
params["session_id"] || request.cookies["session_id"]
|
78
|
+
end
|
79
|
+
|
80
|
+
def do_post(selenium_browser_start_command)
|
81
|
+
selenium_session = Models::SeleniumSession.new({
|
82
|
+
:spec_url => request['spec_url'].to_s == "" ? full_spec_suite_url : request['spec_url'],
|
83
|
+
:selenium_browser_start_command => selenium_browser_start_command,
|
84
|
+
:selenium_host => request['selenium_host'].to_s == "" ? 'localhost' : request['selenium_host'].to_s,
|
85
|
+
:selenium_port => request['selenium_port'].to_s == "" ? 4444 : Integer(request['selenium_port'])
|
86
|
+
})
|
87
|
+
selenium_session.start
|
88
|
+
|
89
|
+
body = "session_id=#{selenium_session.session_id}"
|
90
|
+
[
|
91
|
+
200,
|
92
|
+
{
|
93
|
+
"Content-Length" => body.length
|
94
|
+
},
|
95
|
+
body
|
96
|
+
]
|
97
|
+
end
|
98
|
+
|
99
|
+
def full_spec_suite_url
|
100
|
+
"#{Configuration.root_url}/specs"
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module JsTestCore
|
2
|
+
module Resources
|
3
|
+
class SpecFile < ::JsTestCore::Resources::File
|
4
|
+
class << self
|
5
|
+
def spec_representation_class
|
6
|
+
@spec_representation_class ||= JsTestCore::Representations::Spec
|
7
|
+
end
|
8
|
+
|
9
|
+
attr_writer :spec_representation_class
|
10
|
+
end
|
11
|
+
|
12
|
+
map "/specs"
|
13
|
+
|
14
|
+
get "/?" do
|
15
|
+
do_get
|
16
|
+
end
|
17
|
+
|
18
|
+
get "*" do
|
19
|
+
do_get
|
20
|
+
end
|
21
|
+
|
22
|
+
protected
|
23
|
+
|
24
|
+
def do_get
|
25
|
+
if ::File.exists?(absolute_path)
|
26
|
+
if ::File.directory?(absolute_path)
|
27
|
+
spec_files = ::Dir["#{absolute_path}/**/*_spec.js"].map do |file|
|
28
|
+
["#{relative_path}#{file.gsub(absolute_path, "")}"]
|
29
|
+
end
|
30
|
+
get_generated_spec(absolute_path, spec_files)
|
31
|
+
else
|
32
|
+
super
|
33
|
+
end
|
34
|
+
elsif ::File.exists?("#{absolute_path}.js")
|
35
|
+
get_generated_spec("#{absolute_path}.js", ["#{relative_path}.js"])
|
36
|
+
else
|
37
|
+
pass
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def get_generated_spec(real_path, spec_files)
|
42
|
+
html = render_spec(spec_files)
|
43
|
+
[
|
44
|
+
200,
|
45
|
+
{
|
46
|
+
'Content-Type' => "text/html",
|
47
|
+
'Last-Modified' => ::File.mtime(real_path).rfc822,
|
48
|
+
'Content-Length' => html.length
|
49
|
+
},
|
50
|
+
html
|
51
|
+
]
|
52
|
+
end
|
53
|
+
|
54
|
+
def render_spec(spec_files)
|
55
|
+
self.class.spec_representation_class.new(:spec_files => spec_files).to_s
|
56
|
+
end
|
57
|
+
|
58
|
+
def absolute_path
|
59
|
+
@absolute_path ||= ::File.expand_path("#{spec_root_path}#{relative_path.gsub(%r{^/specs}, "")}")
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -1,61 +1,10 @@
|
|
1
1
|
module JsTestCore
|
2
2
|
module Resources
|
3
|
-
class WebRoot
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
['core', lambda do
|
9
|
-
Resources::Dir.new(JsTestCore::Server.core_path, "/core")
|
10
|
-
end],
|
11
|
-
['implementations', lambda do
|
12
|
-
Resources::Dir.new(JsTestCore::Server.implementation_root_path, "/implementations")
|
13
|
-
end],
|
14
|
-
['suites', lambda do
|
15
|
-
Resources::Suite
|
16
|
-
end],
|
17
|
-
['runners', lambda do
|
18
|
-
Resources::Runners.new
|
19
|
-
end]
|
20
|
-
]
|
21
|
-
|
22
|
-
class << self
|
23
|
-
attr_accessor :dispatch_strategy
|
24
|
-
def dispatch_specs
|
25
|
-
self.dispatch_strategy = :specs
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
attr_reader :public_path
|
30
|
-
def initialize(public_path)
|
31
|
-
@public_path = ::File.expand_path(public_path)
|
32
|
-
end
|
33
|
-
|
34
|
-
def locate(name)
|
35
|
-
if self.class.dispatch_strategy == :specs && name == 'specs'
|
36
|
-
return JsTestCore::Resources::Specs::SpecDir.new(JsTestCore::Server.spec_root_path, "/specs")
|
37
|
-
end
|
38
|
-
|
39
|
-
location, initializer = LOCATIONS.find do |location|
|
40
|
-
location.first == name
|
41
|
-
end
|
42
|
-
if initializer
|
43
|
-
initializer.call(self)
|
44
|
-
else
|
45
|
-
potential_file_in_public_path = "#{public_path}/#{name}"
|
46
|
-
if ::File.directory?(potential_file_in_public_path)
|
47
|
-
Resources::Dir.new(potential_file_in_public_path, "/#{name}")
|
48
|
-
elsif ::File.exists?(potential_file_in_public_path)
|
49
|
-
Resources::File.new(potential_file_in_public_path, "/#{name}")
|
50
|
-
else
|
51
|
-
Resources::FileNotFound.new(name)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
def get(request, response)
|
57
|
-
response.status = 301
|
58
|
-
response['Location'] = "/#{self.class.dispatch_strategy}"
|
3
|
+
class WebRoot < Resource
|
4
|
+
map "/"
|
5
|
+
|
6
|
+
get("") do
|
7
|
+
[200, {}, "<html><head></head><body>Welcome to the Js Test Server. Click the following link to run you <a href=/specs>spec suite</a>.</body></html>"]
|
59
8
|
end
|
60
9
|
end
|
61
10
|
end
|