pivotal-screw-unit 0.4.3 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +6 -0
- data/Rakefile +4 -1
- data/VERSION.yml +2 -2
- data/bin/screw_unit_server +14 -4
- data/lib/screw_unit/representations/spec.html.rb +1 -1
- data/lib/screw_unit/resources/core_file.rb +7 -0
- data/lib/screw_unit.rb +12 -8
- data/spec/functional/functional_spec_helper.rb +11 -4
- data/spec/functional/functional_spec_server_starter.rb +13 -8
- data/spec/unit/js_test_core/specs/spec_file_spec.rb +51 -18
- data/spec/unit/unit_spec_helper.rb +22 -90
- data/vendor/js-test-core/CHANGES +3 -0
- data/vendor/js-test-core/lib/js_test_core/app.rb +12 -0
- data/vendor/js-test-core/lib/js_test_core/client.rb +5 -5
- data/vendor/js-test-core/lib/js_test_core/configuration.rb +35 -0
- data/vendor/js-test-core/lib/js_test_core/{selenium → extensions/selenium}/client/driver.rb +0 -0
- data/vendor/js-test-core/lib/js_test_core/extensions.rb +1 -1
- data/vendor/js-test-core/lib/js_test_core/models/selenium_session.rb +80 -0
- data/vendor/js-test-core/lib/js_test_core/models.rb +8 -0
- data/vendor/js-test-core/lib/js_test_core/representations/dir.html.rb +24 -0
- data/vendor/js-test-core/{vendor/thin-rest/lib/thin_rest/representations/resource_not_found.html.rb → lib/js_test_core/representations/not_found.html.rb} +3 -7
- data/vendor/js-test-core/{vendor/thin-rest/lib/thin_rest → lib/js_test_core}/representations/page.html.rb +1 -1
- data/vendor/js-test-core/lib/js_test_core/representations/spec.html.rb +1 -1
- data/vendor/js-test-core/lib/js_test_core/representations.rb +4 -2
- 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 +38 -18
- 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 -60
- data/vendor/js-test-core/lib/js_test_core/resources.rb +7 -8
- data/vendor/js-test-core/lib/js_test_core.rb +18 -13
- data/vendor/js-test-core/{vendor/thin-rest/README → spec/example_core/subdir/SubDirFile.js} +0 -0
- data/vendor/js-test-core/spec/example_specs/custom_dir_and_suite/passing_spec.js +1 -1
- 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 +6 -6
- 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 +54 -63
- 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 +15 -19
- data/vendor/js-test-core/spec/unit/unit_spec_helper.rb +14 -148
- data/vendor/js-test-core/vendor/lucky-luciano/README.markdown +7 -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/be_http.rb +32 -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.rb +4 -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/{thin-rest → lucky-luciano}/spec/spec_suite.rb +1 -2
- metadata +74 -59
- data/spec/unit/js_test_core/specs/spec_dir_spec.rb +0 -39
- data/vendor/js-test-core/lib/js_test_core/rack/commonlogger.rb +0 -5
- data/vendor/js-test-core/lib/js_test_core/rack.rb +0 -2
- 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 -67
- data/vendor/js-test-core/lib/js_test_core/resources/runner.rb +0 -107
- data/vendor/js-test-core/lib/js_test_core/resources/session.rb +0 -44
- data/vendor/js-test-core/lib/js_test_core/resources/session_finish.rb +0 -17
- data/vendor/js-test-core/lib/js_test_core/resources/specs/spec.rb +0 -32
- 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 -21
- data/vendor/js-test-core/lib/js_test_core/selenium.rb +0 -2
- data/vendor/js-test-core/lib/js_test_core/server.rb +0 -50
- 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 -8
- data/vendor/js-test-core/lib/js_test_core/thin.rb +0 -3
- data/vendor/js-test-core/spec/example_specs/custom_dir_and_suite.html +0 -9
- 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 -53
- data/vendor/js-test-core/spec/unit/js_test_core/resources/file_not_found_spec.rb +0 -16
- data/vendor/js-test-core/spec/unit/js_test_core/resources/runners/runner_spec.rb +0 -303
- data/vendor/js-test-core/spec/unit/js_test_core/resources/session_finish_spec.rb +0 -79
- data/vendor/js-test-core/spec/unit/js_test_core/resources/session_spec.rb +0 -82
- data/vendor/js-test-core/spec/unit/js_test_core/resources/specs/spec_dir_spec.rb +0 -104
- data/vendor/js-test-core/spec/unit/js_test_core/resources/specs/spec_file_spec.rb +0 -41
- data/vendor/js-test-core/spec/unit/js_test_core/server_spec.rb +0 -117
- data/vendor/js-test-core/spec/unit/thin/js_test_core_connection_spec.rb +0 -6
- data/vendor/js-test-core/vendor/thin-rest/CHANGES +0 -2
- data/vendor/js-test-core/vendor/thin-rest/lib/thin_rest/connection.rb +0 -117
- data/vendor/js-test-core/vendor/thin-rest/lib/thin_rest/extensions/object.rb +0 -21
- data/vendor/js-test-core/vendor/thin-rest/lib/thin_rest/extensions.rb +0 -3
- data/vendor/js-test-core/vendor/thin-rest/lib/thin_rest/representations/internal_error.html.rb +0 -20
- data/vendor/js-test-core/vendor/thin-rest/lib/thin_rest/representations.rb +0 -4
- data/vendor/js-test-core/vendor/thin-rest/lib/thin_rest/resources/internal_error.rb +0 -11
- data/vendor/js-test-core/vendor/thin-rest/lib/thin_rest/resources/resource.rb +0 -105
- data/vendor/js-test-core/vendor/thin-rest/lib/thin_rest/resources/resource_not_found.rb +0 -19
- data/vendor/js-test-core/vendor/thin-rest/lib/thin_rest/resources.rb +0 -4
- data/vendor/js-test-core/vendor/thin-rest/lib/thin_rest/routing_error.rb +0 -5
- data/vendor/js-test-core/vendor/thin-rest/lib/thin_rest.rb +0 -10
- data/vendor/js-test-core/vendor/thin-rest/spec/thin_rest/connection_spec.rb +0 -205
- data/vendor/js-test-core/vendor/thin-rest/spec/thin_rest/resources/resource_not_found_spec.rb +0 -16
- data/vendor/js-test-core/vendor/thin-rest/spec/thin_rest/resources/resource_spec.rb +0 -135
- data/vendor/js-test-core/vendor/thin-rest/spec/thin_rest/resources/root_spec.rb +0 -16
- data/vendor/js-test-core/vendor/thin-rest/spec/thin_rest_spec_helper.rb +0 -134
@@ -1,104 +0,0 @@
|
|
1
|
-
require File.expand_path("#{File.dirname(__FILE__)}/../../../unit_spec_helper")
|
2
|
-
|
3
|
-
module JsTestCore
|
4
|
-
module Resources
|
5
|
-
module Specs
|
6
|
-
describe SpecDir do
|
7
|
-
attr_reader :dir, :absolute_path, :relative_path
|
8
|
-
before do
|
9
|
-
@absolute_path = spec_root_path
|
10
|
-
@relative_path = "/specs"
|
11
|
-
@dir = Resources::Specs::SpecDir.new(:connection => connection, :absolute_path => absolute_path, :relative_path => relative_path)
|
12
|
-
end
|
13
|
-
|
14
|
-
describe "#locate" do
|
15
|
-
context "when passed the name with an extension" do
|
16
|
-
context "when file exists" do
|
17
|
-
it "returns a Resources::File representing it" do
|
18
|
-
file = dir.locate("failing_spec.js")
|
19
|
-
file.relative_path.should == "/specs/failing_spec.js"
|
20
|
-
file.absolute_path.should == "#{spec_root_path}/failing_spec.js"
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
context "when file does not exist" do
|
25
|
-
it "raises error" do
|
26
|
-
lambda { dir.locate("nonexistent.js") }.should raise_error
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
context "when passed a name without an extension" do
|
32
|
-
context "when name corresponds to a subdirectory" do
|
33
|
-
it "returns a DirectoryRunner for the directory" do
|
34
|
-
subdir = dir.locate("foo")
|
35
|
-
subdir.should == spec_dir("/foo")
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
context "when name corresponds to a .js file" do
|
40
|
-
it "returns a SpecFile for the .js file" do
|
41
|
-
spec_file_name = "failing_spec"
|
42
|
-
subdir = dir.locate(spec_file_name)
|
43
|
-
subdir.should == JsTestCore::Resources::Specs::SpecFile.new(
|
44
|
-
:connection => connection,
|
45
|
-
:absolute_path => "#{spec_root_path}/#{spec_file_name}.js",
|
46
|
-
:relative_path => "/specs/#{spec_file_name}.js"
|
47
|
-
)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
context "when name does not correspond to a .js file or directory" do
|
52
|
-
it "raises an error" do
|
53
|
-
lambda do
|
54
|
-
dir.locate("nonexistent")
|
55
|
-
end.should raise_error
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
describe "GET /specs/custom_dir_and_suite" do
|
62
|
-
it "renders the custom_dir_and_suite.html file" do
|
63
|
-
WebRoot.dispatch_specs
|
64
|
-
path = "#{spec_root_path}/custom_dir_and_suite.html"
|
65
|
-
mock(connection).send_head(200, 'Content-Type' => "text/html", 'Content-Length' => ::File.size(path), 'Last-Modified' => ::File.mtime(path).rfc822)
|
66
|
-
mock(connection).send_data(::File.read(path))
|
67
|
-
|
68
|
-
connection.receive_data("GET /specs/custom_dir_and_suite.html HTTP/1.1\r\nHost: _\r\n\r\n")
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
describe "GET /specs/foo" do
|
73
|
-
it "renders a custom spec suite that includes all of the javascript spec files in the directory" do
|
74
|
-
WebRoot.dispatch_specs
|
75
|
-
Thin::Logging.silent = true
|
76
|
-
path = "#{spec_root_path}/foo"
|
77
|
-
mock(connection).send_head(200, 'Content-Type' => "text/html", 'Last-Modified' => ::File.mtime(path).rfc822)
|
78
|
-
mock(connection).send_data(/Content-Length: /)
|
79
|
-
mock(connection).send_data(Regexp.new("Js Test Core Suite")) do |html|
|
80
|
-
doc = Nokogiri::HTML(html)
|
81
|
-
core_js_files = doc.search("script").map {|script| script["src"]}
|
82
|
-
core_js_files.should include("/specs/foo/passing_spec.js")
|
83
|
-
core_js_files.should include("/specs/foo/failing_spec.js")
|
84
|
-
end
|
85
|
-
|
86
|
-
connection.receive_data("GET /specs/foo HTTP/1.1\r\nHost: _\r\n\r\n")
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
describe "GET /" do
|
91
|
-
context "when WebRoot.dispatch_specs has been invoked" do
|
92
|
-
it "renders a home page" do
|
93
|
-
WebRoot.dispatch_specs
|
94
|
-
mock(connection).send_head(200, :Location => '/specs')
|
95
|
-
mock(connection).send_body(is_a(String))
|
96
|
-
|
97
|
-
connection.receive_data("GET / HTTP/1.1\r\nHost: _\r\n\r\n")
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
require File.expand_path("#{File.dirname(__FILE__)}/../../../unit_spec_helper")
|
2
|
-
|
3
|
-
module JsTestCore
|
4
|
-
module Resources
|
5
|
-
module Specs
|
6
|
-
describe SpecFile do
|
7
|
-
describe "GET" do
|
8
|
-
before do
|
9
|
-
WebRoot.dispatch_specs
|
10
|
-
end
|
11
|
-
|
12
|
-
describe "GET /specs/custom_suite.html" do
|
13
|
-
it "renders the custom_suite.html file" do
|
14
|
-
path = "#{spec_root_path}/custom_suite.html"
|
15
|
-
mock(connection).send_head(200, 'Content-Type' => "text/html", 'Content-Length' => ::File.size(path), 'Last-Modified' => ::File.mtime(path).rfc822)
|
16
|
-
mock(connection).send_data(::File.read(path))
|
17
|
-
|
18
|
-
connection.receive_data("GET /specs/custom_suite.html HTTP/1.1\r\nHost: _\r\n\r\n")
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
describe "GET /specs/foo/passing_spec" do
|
23
|
-
it "renders a Representations::Spec with passing_spec.js as the spec file" do
|
24
|
-
path = "#{spec_root_path}/foo/passing_spec.js"
|
25
|
-
mock(connection).send_head(200, 'Content-Type' => "text/html", 'Last-Modified' => ::File.mtime(path).rfc822)
|
26
|
-
mock(connection).send_data(/Content-Length: /)
|
27
|
-
mock(connection).send_data(Regexp.new("Js Test Core Suite")) do |html|
|
28
|
-
doc = Nokogiri::HTML(html)
|
29
|
-
core_js_files = doc.search("script").map {|script| script["src"]}
|
30
|
-
core_js_files.should include("/specs/foo/passing_spec.js")
|
31
|
-
core_js_files.should_not include("/specs/foo/failing_spec.js")
|
32
|
-
end
|
33
|
-
|
34
|
-
connection.receive_data("GET /specs/foo/passing_spec HTTP/1.1\r\nHost: _\r\n\r\n")
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
@@ -1,117 +0,0 @@
|
|
1
|
-
require File.expand_path("#{File.dirname(__FILE__)}/../unit_spec_helper")
|
2
|
-
|
3
|
-
module JsTestCore
|
4
|
-
describe Server do
|
5
|
-
attr_reader :result
|
6
|
-
|
7
|
-
before do
|
8
|
-
@result = ""
|
9
|
-
stub(EventMachine).send_data do |signature, data, data_length|
|
10
|
-
@result << data
|
11
|
-
end
|
12
|
-
stub(EventMachine).close_connection
|
13
|
-
end
|
14
|
-
|
15
|
-
describe ".run" do
|
16
|
-
attr_reader :server_instance
|
17
|
-
before do
|
18
|
-
@server_instance = Server.instance
|
19
|
-
Server.instance = nil
|
20
|
-
end
|
21
|
-
|
22
|
-
it "instantiates an instance of Server and starts a Rack Thin handler" do
|
23
|
-
host = DEFAULT_HOST
|
24
|
-
port = DEFAULT_PORT
|
25
|
-
|
26
|
-
mock(EventMachine).run.yields
|
27
|
-
mock(EventMachine).start_server(host, port, ::Thin::JsTestCoreConnection)
|
28
|
-
|
29
|
-
Server.run(spec_root_path, implementation_root_path, public_path)
|
30
|
-
end
|
31
|
-
|
32
|
-
it "when passed a custom host and port, sets the host and port to the passed in value" do
|
33
|
-
host = 'foobar.com'
|
34
|
-
port = 80
|
35
|
-
|
36
|
-
mock(EventMachine).run.yields
|
37
|
-
mock(EventMachine).start_server(host, port, ::Thin::JsTestCoreConnection)
|
38
|
-
|
39
|
-
Server.run(spec_root_path, implementation_root_path, public_path, {:Host => host, :Port => port})
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
describe ".spec_root" do
|
44
|
-
it "returns the Dir " do
|
45
|
-
Server.spec_root_path.should == spec_root_path
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
describe ".spec_root_path" do
|
50
|
-
it "returns the absolute path of the specs root directory" do
|
51
|
-
Server.spec_root_path.should == spec_root_path
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
describe ".public_path" do
|
56
|
-
it "returns the expanded path of the public path" do
|
57
|
-
Server.public_path.should == public_path
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
describe ".core_path" do
|
62
|
-
it "returns the expanded path to the JsTestCore core directory" do
|
63
|
-
Server.core_path.should == core_path
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
describe ".implementation_root_path" do
|
68
|
-
it "returns the expanded path to the JsTestCore implementations directory" do
|
69
|
-
dir = ::File.dirname(__FILE__)
|
70
|
-
Server.implementation_root_path.should == implementation_root_path
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
describe "#call" do
|
75
|
-
describe "when there is an error" do
|
76
|
-
attr_reader :top_line_of_backtrace
|
77
|
-
before do
|
78
|
-
@top_line_of_backtrace = __LINE__ + 2
|
79
|
-
stub.instance_of(Resources::WebRoot).locate('somedir') do
|
80
|
-
raise "Foobar"
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
it "shows the full request path in the error message" do
|
85
|
-
error = nil
|
86
|
-
mock(connection).log_error(is_a(Exception)) do |error_arg|
|
87
|
-
error = error_arg
|
88
|
-
end
|
89
|
-
|
90
|
-
get('/somedir')
|
91
|
-
error.message.should =~ Regexp.new("/somedir")
|
92
|
-
end
|
93
|
-
|
94
|
-
it "uses the backtrace from where the original error was raised" do
|
95
|
-
error = nil
|
96
|
-
mock(connection).log_error(is_a(Exception)) do |error_arg|
|
97
|
-
error = error_arg
|
98
|
-
end
|
99
|
-
|
100
|
-
get('/somedir')
|
101
|
-
no_error = false
|
102
|
-
top_of_backtrace = error.backtrace.first.split(":")
|
103
|
-
backtrace_file = ::File.expand_path(top_of_backtrace[0])
|
104
|
-
backtrace_line = Integer(top_of_backtrace[1])
|
105
|
-
backtrace_file.should == __FILE__
|
106
|
-
backtrace_line.should == top_line_of_backtrace
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
describe "#root_url" do
|
112
|
-
it "returns the url of the site's root" do
|
113
|
-
server.root_url.should == "http://#{server.host}:#{server.port}"
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|
@@ -1,117 +0,0 @@
|
|
1
|
-
module ThinRest
|
2
|
-
class Connection < Thin::Connection
|
3
|
-
attr_reader :resource, :rack_request
|
4
|
-
|
5
|
-
def process
|
6
|
-
guard_against_errors do
|
7
|
-
method = rack_request.request_method.downcase.to_sym
|
8
|
-
@resource = get_resource
|
9
|
-
resource.send(method)
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
def rack_request
|
14
|
-
@rack_request ||= Rack::Request.new(@request.env)
|
15
|
-
end
|
16
|
-
|
17
|
-
def send_head(status=200, additional_parameters={})
|
18
|
-
send_data(head(status, additional_parameters))
|
19
|
-
end
|
20
|
-
|
21
|
-
def head(status, additional_parameters)
|
22
|
-
parameters = {}
|
23
|
-
parameters['Connection'] = "close" unless request.persistent?
|
24
|
-
parameters.merge!(additional_parameters)
|
25
|
-
head_output = parameters.inject("HTTP/1.1 #{status} OK\r\nServer: Thin Rest Server\r\n") do |header, parameter|
|
26
|
-
header << "#{parameter[0]}: #{parameter[1]}\r\n"
|
27
|
-
end
|
28
|
-
if additional_parameters[:'Content-Length'] || additional_parameters['Content-Length']
|
29
|
-
head_output << "\r\n"
|
30
|
-
end
|
31
|
-
head_output
|
32
|
-
end
|
33
|
-
|
34
|
-
def send_body(data)
|
35
|
-
terminate_after_sending do
|
36
|
-
send_data("Content-Length: #{data.length}\r\n\r\n")
|
37
|
-
send_data(data)
|
38
|
-
yield(self) if block_given?
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def terminate_after_sending
|
43
|
-
yield
|
44
|
-
ensure
|
45
|
-
unless request.persistent?
|
46
|
-
close_connection_after_writing
|
47
|
-
end
|
48
|
-
terminate_request
|
49
|
-
end
|
50
|
-
|
51
|
-
def unbind
|
52
|
-
super
|
53
|
-
resource.unbind if resource
|
54
|
-
rescue Exception => e
|
55
|
-
handle_error e
|
56
|
-
end
|
57
|
-
|
58
|
-
def terminate_request
|
59
|
-
persistent = persistent?
|
60
|
-
@resource = nil
|
61
|
-
@rack_request = nil
|
62
|
-
@request.close rescue nil
|
63
|
-
@response.close rescue nil
|
64
|
-
|
65
|
-
# Prepare the connection for another request if the client
|
66
|
-
# supports HTTP pipelining (persistent connection).
|
67
|
-
if persistent
|
68
|
-
post_init
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
def persistent?
|
73
|
-
request.persistent?
|
74
|
-
end
|
75
|
-
|
76
|
-
def handle_error(error)
|
77
|
-
log_error error
|
78
|
-
Resources::InternalError.new(:connection => self, :error => error).get
|
79
|
-
rescue Exception => unexpected_error
|
80
|
-
log_error unexpected_error
|
81
|
-
end
|
82
|
-
|
83
|
-
protected
|
84
|
-
def guard_against_errors
|
85
|
-
yield
|
86
|
-
rescue RoutingError => e
|
87
|
-
handle_error e
|
88
|
-
rescue Exception => e
|
89
|
-
wrapped_error = Exception.new("Error in #{rack_request.path_info} : #{e.message}")
|
90
|
-
wrapped_error.set_backtrace(e.backtrace)
|
91
|
-
handle_error wrapped_error
|
92
|
-
end
|
93
|
-
|
94
|
-
def get_resource
|
95
|
-
path_parts.inject(root_resource) do |resource, child_resource_name|
|
96
|
-
resource.locate(child_resource_name)
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
def root_resource
|
101
|
-
raise NotImplementedError
|
102
|
-
end
|
103
|
-
|
104
|
-
def path_parts
|
105
|
-
rack_request.path_info.split('/').reject { |part| part == "" }
|
106
|
-
end
|
107
|
-
|
108
|
-
def error_message(e)
|
109
|
-
output = "Error in Connection#receive_line\n"
|
110
|
-
output << "#{e.message}\n"
|
111
|
-
output << e.backtrace.join("\n\t")
|
112
|
-
output << "\n\nResource was:\n\t"
|
113
|
-
output << "#{resource.inspect}\n"
|
114
|
-
output
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
# From Mauricio Fernandez.
|
2
|
-
class Object
|
3
|
-
module InstanceExecHelper; end
|
4
|
-
include InstanceExecHelper
|
5
|
-
def instance_exec(*args, &block)
|
6
|
-
begin
|
7
|
-
old_critical, Thread.critical = Thread.critical, true
|
8
|
-
n = 0
|
9
|
-
n += 1 while respond_to?(mname="__instance_exec#{n}")
|
10
|
-
InstanceExecHelper.module_eval{ define_method(mname, &block) }
|
11
|
-
ensure
|
12
|
-
Thread.critical = old_critical
|
13
|
-
end
|
14
|
-
begin
|
15
|
-
ret = send(mname, *args)
|
16
|
-
ensure
|
17
|
-
InstanceExecHelper.module_eval{ remove_method(mname) } rescue nil
|
18
|
-
end
|
19
|
-
ret
|
20
|
-
end
|
21
|
-
end
|
data/vendor/js-test-core/vendor/thin-rest/lib/thin_rest/representations/internal_error.html.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
module ThinRest
|
2
|
-
module Representations
|
3
|
-
class InternalError < Page
|
4
|
-
needs :error
|
5
|
-
protected
|
6
|
-
def body_content
|
7
|
-
h1 error.message
|
8
|
-
ul do
|
9
|
-
error.backtrace.each do |line|
|
10
|
-
li line
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def title_text
|
16
|
-
error.message
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,105 +0,0 @@
|
|
1
|
-
module ThinRest
|
2
|
-
module Resources
|
3
|
-
class Resource
|
4
|
-
class << self
|
5
|
-
def property(*names)
|
6
|
-
names.each do |name|
|
7
|
-
my_properties << name.to_sym
|
8
|
-
|
9
|
-
define_method name do
|
10
|
-
env[name]
|
11
|
-
end
|
12
|
-
|
13
|
-
define_method "#{name}=" do |new_value|
|
14
|
-
env[name] = new_value
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def properties
|
20
|
-
if superclass.respond_to?(:properties)
|
21
|
-
superclass.properties | my_properties
|
22
|
-
else
|
23
|
-
my_properties
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def route(name, resource_type_name=nil, &block)
|
28
|
-
routes[name] = block || lambda do |env, name|
|
29
|
-
resource_type = resource_type_name.split('::').inject(Object) do |mod, next_mod_name|
|
30
|
-
mod.const_get(next_mod_name)
|
31
|
-
end
|
32
|
-
resource_type.new(env)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def routes
|
37
|
-
@routes ||= {}
|
38
|
-
end
|
39
|
-
|
40
|
-
protected
|
41
|
-
def my_properties
|
42
|
-
@my_properties ||= []
|
43
|
-
end
|
44
|
-
|
45
|
-
def handle_dequeue_and_process_error(command, error)
|
46
|
-
if command.connection
|
47
|
-
command.connection.handle_error error
|
48
|
-
else
|
49
|
-
super
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
ANY = Object.new
|
54
|
-
|
55
|
-
property :connection
|
56
|
-
attr_reader :env
|
57
|
-
|
58
|
-
def initialize(env={})
|
59
|
-
@env = env
|
60
|
-
env.each do |name, value|
|
61
|
-
if self.class.properties.include?(name.to_sym)
|
62
|
-
instance_variable_set("@#{name}", value)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
after_initialize
|
66
|
-
end
|
67
|
-
|
68
|
-
def request; connection.request; end
|
69
|
-
def response; connection.response; end
|
70
|
-
def rack_request; connection.rack_request; end
|
71
|
-
|
72
|
-
def get
|
73
|
-
connection.send_head
|
74
|
-
connection.send_body(do_get || "")
|
75
|
-
end
|
76
|
-
|
77
|
-
def post
|
78
|
-
connection.send_head
|
79
|
-
connection.send_body(do_post || "")
|
80
|
-
end
|
81
|
-
|
82
|
-
def put
|
83
|
-
connection.send_head
|
84
|
-
connection.send_body(do_put || "")
|
85
|
-
end
|
86
|
-
|
87
|
-
def delete
|
88
|
-
connection.send_head
|
89
|
-
connection.send_body(do_delete || "")
|
90
|
-
end
|
91
|
-
|
92
|
-
def locate(name)
|
93
|
-
route_handler = self.class.routes[name] || self.class.routes[ANY] || ResourceNotFound.method(:default_handler)
|
94
|
-
instance_exec(env, name, &route_handler)
|
95
|
-
end
|
96
|
-
|
97
|
-
def unbind
|
98
|
-
end
|
99
|
-
|
100
|
-
protected
|
101
|
-
def after_initialize
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
module ThinRest
|
2
|
-
module Resources
|
3
|
-
class ResourceNotFound < Resource
|
4
|
-
class << self
|
5
|
-
def default_handler(env, name)
|
6
|
-
new(env)
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
property :name
|
11
|
-
def get
|
12
|
-
connection.send_head(404)
|
13
|
-
connection.send_body(Representations::ResourceNotFound.new(:path_info => connection.rack_request.path_info).to_s) do
|
14
|
-
raise RoutingError, "Invalid route: #{connection.rack_request.path_info} ; name: #{name}"
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,10 +0,0 @@
|
|
1
|
-
require "rubygems"
|
2
|
-
require "thin"
|
3
|
-
require "erector"
|
4
|
-
|
5
|
-
dir = File.dirname(__FILE__)
|
6
|
-
require "#{dir}/thin_rest/connection"
|
7
|
-
require "#{dir}/thin_rest/resources"
|
8
|
-
require "#{dir}/thin_rest/representations"
|
9
|
-
require "#{dir}/thin_rest/routing_error"
|
10
|
-
require "#{dir}/thin_rest/extensions"
|