screw-unit 0.3.3 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (116) hide show
  1. data/CHANGES +10 -0
  2. data/Rakefile +27 -25
  3. data/VERSION.yml +4 -0
  4. data/bin/screw_unit_server +14 -4
  5. data/core/EXAMPLE.html +1 -1
  6. data/core/example/spec/suite.html +1 -1
  7. data/core/lib/jquery-1.3.2.js +4376 -0
  8. data/core/lib/jquery.fn.js +2 -1
  9. data/core/lib/screw.behaviors.js +8 -7
  10. data/core/lib/screw.builder.js +34 -19
  11. data/core/lib/screw.css +1 -1
  12. data/core/lib/screw.events.js +5 -5
  13. data/core/lib/screw.matchers.js +59 -2
  14. data/core/spec/suite.html +2 -1
  15. data/core/spec/with_screw_context_spec.js +9 -0
  16. data/lib/screw_unit.rb +13 -16
  17. data/lib/screw_unit/representations.rb +2 -0
  18. data/lib/screw_unit/{resources/spec.rb → representations/spec.html.rb} +55 -39
  19. data/spec/functional/functional_spec.rb +1 -1
  20. data/spec/functional/functional_spec_helper.rb +21 -33
  21. data/spec/functional/functional_spec_server_starter.rb +68 -0
  22. data/spec/unit/js_test_core/specs/spec_file_spec.rb +52 -18
  23. data/spec/unit/unit_spec_helper.rb +24 -91
  24. data/vendor/js-test-core/CHANGES +8 -0
  25. data/vendor/js-test-core/Rakefile +1 -0
  26. data/vendor/js-test-core/lib/js_test_core.rb +22 -14
  27. data/vendor/js-test-core/lib/js_test_core/app.rb +12 -0
  28. data/vendor/js-test-core/lib/js_test_core/client.rb +21 -9
  29. data/vendor/js-test-core/lib/js_test_core/configuration.rb +35 -0
  30. data/vendor/js-test-core/lib/js_test_core/extensions.rb +1 -1
  31. data/vendor/js-test-core/lib/js_test_core/extensions/selenium/client/driver.rb +7 -0
  32. data/vendor/js-test-core/lib/js_test_core/models.rb +8 -0
  33. data/vendor/js-test-core/lib/js_test_core/models/selenium_session.rb +80 -0
  34. data/vendor/js-test-core/lib/js_test_core/representations.rb +11 -0
  35. data/vendor/js-test-core/lib/js_test_core/representations/dir.html.rb +24 -0
  36. data/vendor/js-test-core/lib/js_test_core/representations/not_found.html.rb +15 -0
  37. data/vendor/js-test-core/lib/js_test_core/representations/page.html.rb +41 -0
  38. data/vendor/js-test-core/lib/js_test_core/representations/spec.html.rb +24 -0
  39. data/vendor/js-test-core/lib/js_test_core/resources.rb +13 -7
  40. data/vendor/js-test-core/lib/js_test_core/resources/core_file.rb +19 -0
  41. data/vendor/js-test-core/lib/js_test_core/resources/file.rb +42 -20
  42. data/vendor/js-test-core/lib/js_test_core/resources/implementations_deprecation.rb +12 -0
  43. data/vendor/js-test-core/lib/js_test_core/resources/not_found.rb +35 -0
  44. data/vendor/js-test-core/lib/js_test_core/resources/resource.rb +16 -0
  45. data/vendor/js-test-core/lib/js_test_core/resources/selenium_session.rb +104 -0
  46. data/vendor/js-test-core/lib/js_test_core/resources/spec_file.rb +63 -0
  47. data/vendor/js-test-core/lib/js_test_core/resources/web_root.rb +5 -60
  48. data/vendor/js-test-core/{vendor/thin-rest/README → spec/example_core/subdir/SubDirFile.js} +0 -0
  49. data/vendor/js-test-core/spec/example_specs/custom_dir_and_suite/passing_spec.js +6 -0
  50. data/vendor/js-test-core/spec/example_specs/custom_suite.html +8 -0
  51. data/vendor/js-test-core/spec/example_specs/foo/failing_spec.js +1 -1
  52. data/vendor/js-test-core/spec/example_specs/foo/passing_spec.js +1 -1
  53. data/vendor/js-test-core/spec/spec_helpers/be_http.rb +32 -0
  54. data/vendor/js-test-core/spec/spec_helpers/example_group.rb +36 -0
  55. data/vendor/js-test-core/spec/spec_helpers/fake_selenium_driver.rb +27 -0
  56. data/vendor/js-test-core/spec/spec_helpers/show_test_exceptions.rb +22 -0
  57. data/vendor/js-test-core/spec/unit/js_test_core/client_spec.rb +35 -10
  58. data/vendor/js-test-core/spec/unit/js_test_core/configuration_spec.rb +44 -0
  59. data/vendor/js-test-core/spec/unit/js_test_core/models/selenium_session_spec.rb +85 -0
  60. data/vendor/js-test-core/spec/unit/js_test_core/resources/core_file_spec.rb +60 -0
  61. data/vendor/js-test-core/spec/unit/js_test_core/resources/file_spec.rb +54 -63
  62. data/vendor/js-test-core/spec/unit/js_test_core/resources/implementations_deprecation_spec.rb +18 -0
  63. data/vendor/js-test-core/spec/unit/js_test_core/resources/not_found_spec.rb +51 -0
  64. data/vendor/js-test-core/spec/unit/js_test_core/resources/selenium_session_spec.rb +362 -0
  65. data/vendor/js-test-core/spec/unit/js_test_core/resources/spec_file_spec.rb +120 -0
  66. data/vendor/js-test-core/spec/unit/js_test_core/resources/web_root_spec.rb +15 -19
  67. data/vendor/js-test-core/spec/unit/unit_spec_helper.rb +16 -149
  68. data/vendor/js-test-core/vendor/lucky-luciano/README.markdown +7 -0
  69. data/vendor/js-test-core/vendor/lucky-luciano/lib/lucky_luciano.rb +4 -0
  70. data/vendor/js-test-core/vendor/lucky-luciano/lib/lucky_luciano/resource.rb +135 -0
  71. data/vendor/js-test-core/vendor/lucky-luciano/lib/lucky_luciano/rspec.rb +4 -0
  72. data/vendor/js-test-core/vendor/lucky-luciano/lib/lucky_luciano/rspec/be_http.rb +32 -0
  73. data/vendor/js-test-core/vendor/lucky-luciano/spec/lucky_luciano/resource_spec.rb +231 -0
  74. data/vendor/js-test-core/vendor/lucky-luciano/spec/spec_helper.rb +48 -0
  75. data/vendor/js-test-core/vendor/{thin-rest → lucky-luciano}/spec/spec_suite.rb +1 -2
  76. metadata +134 -145
  77. data/core/lib/jquery-1.2.6.js +0 -3549
  78. data/lib/screw_unit/resources.rb +0 -2
  79. data/spec/unit/js_test_core/specs/spec_dir_spec.rb +0 -38
  80. data/vendor/js-test-core/lib/js_test_core/rack.rb +0 -2
  81. data/vendor/js-test-core/lib/js_test_core/rack/commonlogger.rb +0 -5
  82. data/vendor/js-test-core/lib/js_test_core/rails_server.rb +0 -22
  83. data/vendor/js-test-core/lib/js_test_core/resources/dir.rb +0 -67
  84. data/vendor/js-test-core/lib/js_test_core/resources/file_not_found.rb +0 -11
  85. data/vendor/js-test-core/lib/js_test_core/resources/runner.rb +0 -107
  86. data/vendor/js-test-core/lib/js_test_core/resources/session.rb +0 -44
  87. data/vendor/js-test-core/lib/js_test_core/resources/session_finish.rb +0 -17
  88. data/vendor/js-test-core/lib/js_test_core/resources/specs/spec_dir.rb +0 -46
  89. data/vendor/js-test-core/lib/js_test_core/resources/specs/spec_file.rb +0 -17
  90. data/vendor/js-test-core/lib/js_test_core/selenium.rb +0 -2
  91. data/vendor/js-test-core/lib/js_test_core/selenium/selenium_driver.rb +0 -5
  92. data/vendor/js-test-core/lib/js_test_core/server.rb +0 -50
  93. data/vendor/js-test-core/lib/js_test_core/thin.rb +0 -3
  94. data/vendor/js-test-core/lib/js_test_core/thin/backends/js_test_core_server.rb +0 -9
  95. data/vendor/js-test-core/lib/js_test_core/thin/js_test_core_connection.rb +0 -8
  96. data/vendor/js-test-core/spec/unit/js_test_core/rails_server_spec.rb +0 -45
  97. data/vendor/js-test-core/spec/unit/js_test_core/resources/dir_spec.rb +0 -52
  98. data/vendor/js-test-core/spec/unit/js_test_core/resources/file_not_found_spec.rb +0 -16
  99. data/vendor/js-test-core/spec/unit/js_test_core/resources/runners/runner_spec.rb +0 -303
  100. data/vendor/js-test-core/spec/unit/js_test_core/resources/session_finish_spec.rb +0 -79
  101. data/vendor/js-test-core/spec/unit/js_test_core/resources/session_spec.rb +0 -82
  102. data/vendor/js-test-core/spec/unit/js_test_core/resources/specs/spec_dir_spec.rb +0 -105
  103. data/vendor/js-test-core/spec/unit/js_test_core/resources/specs/spec_file_spec.rb +0 -42
  104. data/vendor/js-test-core/spec/unit/js_test_core/server_spec.rb +0 -117
  105. data/vendor/js-test-core/spec/unit/thin/js_test_core_connection_spec.rb +0 -6
  106. data/vendor/js-test-core/vendor/thin-rest/CHANGES +0 -2
  107. data/vendor/js-test-core/vendor/thin-rest/lib/thin_rest.rb +0 -9
  108. data/vendor/js-test-core/vendor/thin-rest/lib/thin_rest/connection.rb +0 -116
  109. data/vendor/js-test-core/vendor/thin-rest/lib/thin_rest/extensions.rb +0 -3
  110. data/vendor/js-test-core/vendor/thin-rest/lib/thin_rest/extensions/object.rb +0 -21
  111. data/vendor/js-test-core/vendor/thin-rest/lib/thin_rest/resource.rb +0 -108
  112. data/vendor/js-test-core/vendor/thin-rest/lib/thin_rest/resource_invalid.rb +0 -4
  113. data/vendor/js-test-core/vendor/thin-rest/lib/thin_rest/routing_error.rb +0 -5
  114. data/vendor/js-test-core/vendor/thin-rest/spec/thin_rest/connection_spec.rb +0 -207
  115. data/vendor/js-test-core/vendor/thin-rest/spec/thin_rest/resource_spec.rb +0 -127
  116. data/vendor/js-test-core/vendor/thin-rest/spec/thin_rest_spec_helper.rb +0 -124
@@ -1,82 +0,0 @@
1
- require File.expand_path("#{File.dirname(__FILE__)}/../../unit_spec_helper")
2
-
3
- module JsTestCore
4
- module Resources
5
- describe Session do
6
- describe "GET /sessions/:session_id" do
7
- attr_reader :driver, :session_id
8
-
9
- context "when there is no Runner with the :session_id" do
10
- it "responds with a 404" do
11
- session_id = "invalid_session_id"
12
- Runner.find(session_id).should be_nil
13
-
14
- mock(connection).send_head(404)
15
- mock(connection).send_body("")
16
-
17
- connection.receive_data("GET /sessions/#{session_id} HTTP/1.1\r\nHost: _\r\n\r\n")
18
- end
19
- end
20
-
21
- context "when there is a Runner with the :session_id" do
22
- attr_reader :session_runner
23
- before do
24
- @driver = FakeSeleniumDriver.new
25
- @session_id = FakeSeleniumDriver::SESSION_ID
26
- stub(Selenium::SeleniumDriver).new('localhost', 4444, '*firefox', 'http://0.0.0.0:8080') do
27
- driver
28
- end
29
-
30
- connection_that_starts_firefox = create_connection
31
- stub(connection_that_starts_firefox).send_head
32
- stub(connection_that_starts_firefox).send_body
33
- connection_that_starts_firefox.receive_data("POST /runners/firefox HTTP/1.1\r\nHost: _\r\nContent-Length: 0\r\n\r\n")
34
- @session_runner = Runner.find(session_id)
35
- session_runner.should be_running
36
- end
37
-
38
- context "when a Runner with the :session_id is running" do
39
- it "responds with a 200 and status=running" do
40
- mock(connection).send_head
41
- mock(connection).send_body("status=#{Resources::Session::RUNNING}")
42
-
43
- connection.receive_data("GET /sessions/#{session_id} HTTP/1.1\r\nHost: _\r\n\r\n")
44
- end
45
- end
46
-
47
- context "when a Runner with the :session_id has completed" do
48
- context "when the session has a status of 'success'" do
49
- before do
50
- session_runner.finalize("")
51
- session_runner.should be_successful
52
- end
53
-
54
- it "responds with a 200 and status=success" do
55
- mock(connection).send_head
56
- mock(connection).send_body("status=#{Resources::Session::SUCCESSFUL_COMPLETION}")
57
-
58
- connection.receive_data("GET /sessions/#{session_id} HTTP/1.1\r\nHost: _\r\n\r\n")
59
- end
60
- end
61
-
62
- context "when the session has a status of 'failure'" do
63
- attr_reader :reason
64
- before do
65
- @reason = "Failure stuff"
66
- session_runner.finalize(reason)
67
- session_runner.should be_failed
68
- end
69
-
70
- it "responds with a 200 and status=failure and reason" do
71
- mock(connection).send_head
72
- mock(connection).send_body("status=#{Resources::Session::FAILURE_COMPLETION}&reason=#{reason}")
73
-
74
- connection.receive_data("GET /sessions/#{session_id} HTTP/1.1\r\nHost: _\r\n\r\n")
75
- end
76
- end
77
- end
78
- end
79
- end
80
- end
81
- end
82
- end
@@ -1,105 +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" do
62
- attr_reader :request, :response
63
- before do
64
- @request = Rack::Request.new( Rack::MockRequest.env_for('/core') )
65
- @response = Rack::Response.new
66
- end
67
-
68
- it "raises NotImplementedError" do
69
- lambda do
70
- dir.get
71
- end.should raise_error(NotImplementedError)
72
- end
73
-
74
- it "can be overridden from a Module without needing to redefine the #get method" do
75
- spec_dir_class = Resources::Specs::SpecDir.clone
76
- mod = Module.new do
77
- def get
78
- end
79
- end
80
- spec_dir_class.class_eval do
81
- include mod
82
- end
83
- @dir = spec_dir_class.new(:connection => connection, :absolute_path => absolute_path, :relative_path => relative_path)
84
-
85
- lambda do
86
- dir.get
87
- end.should_not raise_error
88
- end
89
- end
90
-
91
- describe "GET /" do
92
- context "when WebRoot.dispatch_specs has been invoked" do
93
- it "renders a home page" do
94
- WebRoot.dispatch_specs
95
- mock(connection).send_head(200, :Location => '/specs')
96
- mock(connection).send_body(is_a(String))
97
-
98
- connection.receive_data("GET / HTTP/1.1\r\nHost: _\r\n\r\n")
99
- end
100
- end
101
- end
102
- end
103
- end
104
- end
105
- end
@@ -1,42 +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
- attr_reader :file, :absolute_path, :relative_path, :request, :response
8
- before do
9
- @absolute_path = "#{spec_root_path}/failing_spec.js"
10
- @relative_path = "/specs/failing_spec.js"
11
- @file = Resources::Specs::SpecFile.new(:connection => connection, :absolute_path => absolute_path, :relative_path => relative_path)
12
- @request = Rack::Request.new( Rack::MockRequest.env_for(relative_path) )
13
- @response = Rack::Response.new
14
- end
15
-
16
- describe "#get" do
17
- it "raises NotImplementedError" do
18
- lambda do
19
- file.get
20
- end.should raise_error(NotImplementedError)
21
- end
22
-
23
- it "can be overridden from a Module without needing to redefine the #get method" do
24
- spec_file_class = Resources::Specs::SpecFile.clone
25
- mod = Module.new do
26
- def get
27
- end
28
- end
29
- spec_file_class.class_eval do
30
- include mod
31
- end
32
- @file = spec_file_class.new(:connection => connection, :absolute_path => absolute_path, :relative_path => relative_path)
33
-
34
- lambda do
35
- file.get
36
- end.should_not raise_error
37
- end
38
- end
39
- end
40
- end
41
- end
42
- 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,6 +0,0 @@
1
- require File.expand_path("#{File.dirname(__FILE__)}/../unit_spec_helper")
2
-
3
- module Thin
4
- describe JsTestCoreConnection do
5
- end
6
- end
@@ -1,2 +0,0 @@
1
- - Resource.property creates a reader that reads directly from the env hash
2
- - Resource.property creates a writer that updates the env hash directly
@@ -1,9 +0,0 @@
1
- require "rubygems"
2
- require "thin"
3
-
4
- dir = File.dirname(__FILE__)
5
- require "#{dir}/thin_rest/connection"
6
- require "#{dir}/thin_rest/resource"
7
- require "#{dir}/thin_rest/resource_invalid"
8
- require "#{dir}/thin_rest/routing_error"
9
- require "#{dir}/thin_rest/extensions"
@@ -1,116 +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
- end
39
- end
40
-
41
- def terminate_after_sending
42
- yield
43
- unless request.persistent?
44
- close_connection_after_writing
45
- end
46
- ensure
47
- terminate_request
48
- end
49
-
50
- def unbind
51
- super
52
- resource.unbind if resource
53
- rescue Exception => e
54
- handle_error e
55
- end
56
-
57
- def terminate_request
58
- persistent = persistent?
59
- @resource = nil
60
- @rack_request = nil
61
- @request.close rescue nil
62
- @response.close rescue nil
63
-
64
- # Prepare the connection for another request if the client
65
- # supports HTTP pipelining (persistent connection).
66
- if persistent
67
- post_init
68
- end
69
- end
70
-
71
- def persistent?
72
- request.persistent?
73
- end
74
-
75
- def handle_error(error)
76
- log_error error
77
- close_connection rescue nil
78
- rescue Exception => unexpected_error
79
- log_error unexpected_error
80
- end
81
-
82
- protected
83
- def guard_against_errors
84
- yield
85
- rescue RoutingError => e
86
- handle_error e
87
- rescue Exception => e
88
- wrapped_error = Exception.new("Error in #{rack_request.path_info} : #{e.message}")
89
- wrapped_error.set_backtrace(e.backtrace)
90
- handle_error wrapped_error
91
- end
92
-
93
- def get_resource
94
- path_parts.inject(root_resource) do |resource, child_resource_name|
95
- resource.locate(child_resource_name)
96
- end
97
- end
98
-
99
- def root_resource
100
- raise NotImplementedError
101
- end
102
-
103
- def path_parts
104
- rack_request.path_info.split('/').reject { |part| part == "" }
105
- end
106
-
107
- def error_message(e)
108
- output = "Error in Connection#receive_line\n"
109
- output << "#{e.message}\n"
110
- output << e.backtrace.join("\n\t")
111
- output << "\n\nResource was:\n\t"
112
- output << "#{resource.inspect}\n"
113
- output
114
- end
115
- end
116
- end