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,205 +0,0 @@
|
|
1
|
-
require File.expand_path("#{File.dirname(__FILE__)}/../thin_rest_spec_helper")
|
2
|
-
|
3
|
-
module ThinRest
|
4
|
-
describe Connection do
|
5
|
-
describe "#process" do
|
6
|
-
attr_reader :result
|
7
|
-
before do
|
8
|
-
stub(connection).socket_address {'0.0.0.0'}
|
9
|
-
|
10
|
-
@result = ""
|
11
|
-
stub(EventMachine).send_data do |signature, data, data_length|
|
12
|
-
result << data
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
context "when the call is successful" do
|
17
|
-
context "when the request has Connection: close" do
|
18
|
-
it "sends the response to the socket with a Connection: close response header" do
|
19
|
-
mock(connection).close_connection_after_writing
|
20
|
-
connection.receive_data "GET /subresource HTTP/1.1\r\nConnection: close\r\nHost: _\r\n\r\n"
|
21
|
-
result.should include("GET response")
|
22
|
-
result.should include("Connection: close")
|
23
|
-
end
|
24
|
-
|
25
|
-
it "closes the connection" do
|
26
|
-
mock(connection).close_connection_after_writing
|
27
|
-
connection.receive_data "GET /subresource HTTP/1.1\r\nConnection: close\r\nHost: _\r\n\r\n"
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
context "when the request does not have Connection: close" do
|
32
|
-
it "sends the response to the socket without a Connection: close response header" do
|
33
|
-
connection.receive_data "GET /subresource HTTP/1.1\r\nHost: _\r\n\r\n"
|
34
|
-
result.should include("GET response")
|
35
|
-
result.should_not include("Connection: close")
|
36
|
-
end
|
37
|
-
|
38
|
-
it "does not close the connection" do
|
39
|
-
dont_allow(connection).close_connection_after_writing
|
40
|
-
connection.receive_data "GET /subresource HTTP/1.1\r\nHost: _\r\n\r\n"
|
41
|
-
end
|
42
|
-
|
43
|
-
context "when a second request is made" do
|
44
|
-
it "sends the response for the second request and not for the first request" do
|
45
|
-
connection.receive_data "GET /subresource HTTP/1.1\r\nHost: _\r\n\r\n"
|
46
|
-
result.should include("GET response")
|
47
|
-
result.should_not include("Another GET response")
|
48
|
-
|
49
|
-
connection.receive_data "GET /another_subresource HTTP/1.1\r\nHost: _\r\n\r\n"
|
50
|
-
result.should include("Another GET response")
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
context "when the call raises an error" do
|
57
|
-
it "responds with a 500 page and logs the error" do
|
58
|
-
error = nil
|
59
|
-
mock(connection).log_error(is_a(Exception)) do |error_arg|
|
60
|
-
error = error_arg
|
61
|
-
end
|
62
|
-
mock(connection).send_head(500)
|
63
|
-
mock(connection).send_body(Regexp.new(ErrorSubresource::ERROR_MESSAGE))
|
64
|
-
|
65
|
-
connection.receive_data "GET /error_subresource HTTP/1.1\r\nHost: _\r\n\r\n"
|
66
|
-
error.message.should =~ Regexp.new("/error_subresource")
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
describe "#send_head" do
|
72
|
-
before do
|
73
|
-
@connection = create_connection
|
74
|
-
stub(EventMachine).close_connection
|
75
|
-
end
|
76
|
-
|
77
|
-
context "when passed no arguments" do
|
78
|
-
it "responds with a 200 HTTP header excluding the Content-Length" do
|
79
|
-
expected_header = "HTTP/1.1 200 OK\r\nServer: Thin Rest Server\r\n"
|
80
|
-
mock(EventMachine).send_data( connection.signature, expected_header, expected_header.length ) {expected_header.length}
|
81
|
-
connection.send_head
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
context "when passed 301" do
|
86
|
-
it "responds with a 301 HTTP header excluding the Content-Length" do
|
87
|
-
expected_header = "HTTP/1.1 301 OK\r\nServer: Thin Rest Server\r\n"
|
88
|
-
mock(EventMachine).send_data( connection.signature, expected_header, expected_header.length ) {expected_header.length}
|
89
|
-
connection.send_head(301)
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
context "when passed additional parameters" do
|
94
|
-
it "responds with the additional parameters in the header" do
|
95
|
-
expected_header = "HTTP/1.1 301 OK\r\nServer: Thin Rest Server\r\nLocation: http://google.com\r\n"
|
96
|
-
mock(EventMachine).send_data( connection.signature, expected_header, expected_header.length ) {expected_header.length}
|
97
|
-
connection.send_head(301, :Location => "http://google.com")
|
98
|
-
end
|
99
|
-
|
100
|
-
context "when not passed Content-length" do
|
101
|
-
it 'does not end with \r\n\r\n' do
|
102
|
-
expected_header = "HTTP/1.1 301 OK\r\nServer: Thin Rest Server\r\nLocation: http://google.com\r\n"
|
103
|
-
mock(EventMachine).send_data( connection.signature, expected_header, expected_header.length ) {expected_header.length}
|
104
|
-
connection.send_head(301, :Location => "http://google.com")
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
context "when passed Content-Length" do
|
109
|
-
it 'when passed a Symbol representation of Content-Length ends with \r\n\r\n' do
|
110
|
-
expected_header = "HTTP/1.1 301 OK\r\nServer: Thin Rest Server\r\nContent-Length: 10\r\n\r\n"
|
111
|
-
mock(EventMachine).send_data( connection.signature, expected_header, expected_header.length ) {expected_header.length}
|
112
|
-
connection.send_head(301, :'Content-Length' => 10)
|
113
|
-
end
|
114
|
-
|
115
|
-
it 'when passed a String representation of Content-Length ends with \r\n\r\n' do
|
116
|
-
expected_header = "HTTP/1.1 301 OK\r\nServer: Thin Rest Server\r\nContent-Length: 10\r\n\r\n"
|
117
|
-
mock(EventMachine).send_data( connection.signature, expected_header, expected_header.length ) {expected_header.length}
|
118
|
-
connection.send_head(301, 'Content-Length' => 10)
|
119
|
-
end
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
describe "#send_body" do
|
125
|
-
before do
|
126
|
-
@connection = create_connection
|
127
|
-
stub(EventMachine).close_connection
|
128
|
-
end
|
129
|
-
|
130
|
-
it "responds with Content-Length and the body" do
|
131
|
-
data = "The data"
|
132
|
-
header = "Content-Length: #{data.length}\r\n\r\n"
|
133
|
-
|
134
|
-
mock(EventMachine).send_data( connection.signature, header, header.length ) {header.length}
|
135
|
-
mock(EventMachine).send_data( connection.signature, data, data.length ) {data.length}
|
136
|
-
|
137
|
-
connection.send_body data
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
describe "#unbind" do
|
142
|
-
attr_reader :game_session
|
143
|
-
|
144
|
-
before do
|
145
|
-
stub_send_data
|
146
|
-
stub(EventMachine).close_connection
|
147
|
-
@connection = create_connection
|
148
|
-
params = "param_1=1¶m_2=2"
|
149
|
-
body = "#{params}\r\n"
|
150
|
-
connection.receive_data("POST /subresource HTTP/1.1\r\nHost: _\r\n\r\n#{body}")
|
151
|
-
end
|
152
|
-
|
153
|
-
it "calls connection_finished on the backend to protect against memory leaks" do
|
154
|
-
mock(connection.backend).connection_finished(connection)
|
155
|
-
connection.unbind
|
156
|
-
end
|
157
|
-
|
158
|
-
it "does not send data or add a timer of any type" do
|
159
|
-
dont_allow(EventMachine).send_data
|
160
|
-
dont_allow(EventMachine).add_timer
|
161
|
-
|
162
|
-
connection.unbind
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
describe "#handle_error" do
|
167
|
-
before do
|
168
|
-
@connection = create_connection
|
169
|
-
Thin::Logging.silent = true
|
170
|
-
end
|
171
|
-
|
172
|
-
it "logs the error" do
|
173
|
-
error = RuntimeError.new("Unexpected Error")
|
174
|
-
stub(error).backtrace(caller)
|
175
|
-
|
176
|
-
stub(connection).warn
|
177
|
-
mock.proxy(connection).log_error(error)
|
178
|
-
mock.proxy(connection).log_error(anything)
|
179
|
-
|
180
|
-
connection.handle_error(error)
|
181
|
-
end
|
182
|
-
end
|
183
|
-
|
184
|
-
describe "#persistent?" do
|
185
|
-
before do
|
186
|
-
@connection = create_connection
|
187
|
-
stub(connection).socket_address {'0.0.0.0'}
|
188
|
-
end
|
189
|
-
|
190
|
-
context "when #request.persistent? is true" do
|
191
|
-
it "returns true" do
|
192
|
-
stub(connection.request).persistent? {true}
|
193
|
-
connection.should be_persistent
|
194
|
-
end
|
195
|
-
end
|
196
|
-
|
197
|
-
context "when #request.persistent? is false" do
|
198
|
-
it "returns false" do
|
199
|
-
stub(connection.request).persistent? {false}
|
200
|
-
connection.should_not be_persistent
|
201
|
-
end
|
202
|
-
end
|
203
|
-
end
|
204
|
-
end
|
205
|
-
end
|
data/vendor/js-test-core/vendor/thin-rest/spec/thin_rest/resources/resource_not_found_spec.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
require File.expand_path("#{File.dirname(__FILE__)}/../../thin_rest_spec_helper")
|
2
|
-
|
3
|
-
module ThinRest
|
4
|
-
module Resources
|
5
|
-
describe ResourceNotFound do
|
6
|
-
describe "GET /invalid_path" do
|
7
|
-
it "returns a page with a of files in the directory" do
|
8
|
-
mock(connection).send_head(404)
|
9
|
-
mock(connection).send_body(Regexp.new("File /invalid_path not found."))
|
10
|
-
|
11
|
-
connection.receive_data("GET /invalid_path HTTP/1.1\r\nHost: _\r\n\r\n")
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,135 +0,0 @@
|
|
1
|
-
require File.expand_path("#{File.dirname(__FILE__)}/../../thin_rest_spec_helper")
|
2
|
-
|
3
|
-
module ThinRest
|
4
|
-
module Resources
|
5
|
-
describe Resource do
|
6
|
-
attr_reader :root
|
7
|
-
self.thin_logging = true
|
8
|
-
before do
|
9
|
-
stub(EventMachine).close_connection
|
10
|
-
@root = Root.new(:connection => connection)
|
11
|
-
end
|
12
|
-
|
13
|
-
describe ".property" do
|
14
|
-
it "creates a reader that takes its value from its env property" do
|
15
|
-
root.env[:connection].should == connection
|
16
|
-
root.connection.should == root.env[:connection]
|
17
|
-
end
|
18
|
-
|
19
|
-
it "creates a writer that sets its passed in value to its env property" do
|
20
|
-
another_connection = create_connection
|
21
|
-
root.connection = another_connection
|
22
|
-
root.connection.should == another_connection
|
23
|
-
root.env[:connection].should == another_connection
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
describe "#locate" do
|
28
|
-
context "/subresource - route is defined using a String" do
|
29
|
-
it "returns an instance of Subresource" do
|
30
|
-
root.locate("subresource").class.should == Subresource
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
context "/block_subresource - route is defined using a block" do
|
35
|
-
it "returns an instance of BlockSubresource" do
|
36
|
-
root.locate("block_subresource").class.should == BlockSubresource
|
37
|
-
end
|
38
|
-
|
39
|
-
it "executes the block within the instance of the Resource" do
|
40
|
-
root.foobar.should_not be_nil
|
41
|
-
root.locate("block_subresource").foobar.should == root.foobar
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
context "/no_handler_subresource - route is not defined" do
|
46
|
-
it "returns a ResourceNotFound resource" do
|
47
|
-
root.locate("no_handler_subresource").class.should == Resources::ResourceNotFound
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
context "/wrong_property - passed in property not defined" do
|
52
|
-
it "does not set an instance variable named after the wrong property" do
|
53
|
-
resource = root.locate("wrong_property")
|
54
|
-
resource.env.should == {:connection => connection, :baz => "wrong_property"}
|
55
|
-
resource.instance_variable_get("@connection").should == connection
|
56
|
-
resource.instance_variable_get("@baz").should be_nil
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
describe "Delegations" do
|
62
|
-
describe "#request" do
|
63
|
-
it "delegates to #connection" do
|
64
|
-
root.request.should == connection.request
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
describe "#response" do
|
69
|
-
it "delegates to #connection" do
|
70
|
-
root.response.should == connection.response
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
describe "#rack_request" do
|
75
|
-
it "delegates to #connection" do
|
76
|
-
root.rack_request.should == connection.rack_request
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
describe "GET /subresource" do
|
82
|
-
it "sends the GET response for the resource" do
|
83
|
-
mock(connection).send_data(connection.head(200, {}))
|
84
|
-
expected_data = "GET response"
|
85
|
-
expected_content_length = "Content-Length: #{expected_data.length}\r\n\r\n"
|
86
|
-
mock(connection).send_data(expected_content_length) {expected_content_length.length}
|
87
|
-
mock(connection).send_data(expected_data) {expected_data.length}
|
88
|
-
connection.receive_data("GET /subresource HTTP/1.1\r\nHost: _\r\n\r\n")
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
describe "GET /no_handler_subresource" do
|
93
|
-
it "renders an error page and logs the error" do
|
94
|
-
stub(connection).send_data
|
95
|
-
mock(connection).send_data(Regexp.new("File /no_handler_subresource not found"))
|
96
|
-
mock(connection).log_error(is_a(ThinRest::RoutingError))
|
97
|
-
connection.receive_data("GET /no_handler_subresource HTTP/1.1\r\nHost: _\r\n\r\n")
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
describe "POST /subresource" do
|
102
|
-
it "sends the POST response for the resource" do
|
103
|
-
mock(connection).send_data(connection.head(200, {}))
|
104
|
-
expected_data = "POST response"
|
105
|
-
expected_content_length = "Content-Length: #{expected_data.length}\r\n\r\n"
|
106
|
-
mock(connection).send_data(expected_content_length) {expected_content_length.length}
|
107
|
-
mock(connection).send_data(expected_data) {expected_data.length}
|
108
|
-
connection.receive_data("POST /subresource HTTP/1.1\r\nHost: _\r\n\r\n")
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
describe "PUT /subresource" do
|
113
|
-
it "sends the PUT response for the resource" do
|
114
|
-
mock(connection).send_data(connection.head(200, {}))
|
115
|
-
expected_data = "PUT response"
|
116
|
-
expected_content_length = "Content-Length: #{expected_data.length}\r\n\r\n"
|
117
|
-
mock(connection).send_data(expected_content_length) {expected_content_length.length}
|
118
|
-
mock(connection).send_data(expected_data) {expected_data.length}
|
119
|
-
connection.receive_data("PUT /subresource HTTP/1.1\r\nHost: _\r\n\r\n")
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
describe "DELETE /subresource" do
|
124
|
-
it "sends the DELETE response for the resource" do
|
125
|
-
mock(connection).send_data(connection.head(200, {}))
|
126
|
-
expected_data = "DELETE response"
|
127
|
-
expected_content_length = "Content-Length: #{expected_data.length}\r\n\r\n"
|
128
|
-
mock(connection).send_data(expected_content_length) {expected_content_length.length}
|
129
|
-
mock(connection).send_data(expected_data) {expected_data.length}
|
130
|
-
connection.receive_data("DELETE /subresource HTTP/1.1\r\nHost: _\r\n\r\n")
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
require File.expand_path("#{File.dirname(__FILE__)}/../../thin_rest_spec_helper")
|
2
|
-
|
3
|
-
module ThinRest
|
4
|
-
module Resources
|
5
|
-
describe ResourceNotFound do
|
6
|
-
describe "GET /invalid_path" do
|
7
|
-
it "returns a page with a of files in the directory" do
|
8
|
-
mock(connection).send_head(404)
|
9
|
-
mock(connection).send_body(Regexp.new("File /invalid_path not found."))
|
10
|
-
|
11
|
-
connection.receive_data("GET /invalid_path HTTP/1.1\r\nHost: _\r\n\r\n")
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,134 +0,0 @@
|
|
1
|
-
dir = File.dirname(__FILE__)
|
2
|
-
$LOAD_PATH.unshift(File.expand_path("#{dir}/../lib"))
|
3
|
-
require "thin_rest"
|
4
|
-
require "spec"
|
5
|
-
require "spec/autorun"
|
6
|
-
require "guid"
|
7
|
-
|
8
|
-
Spec::Runner.configure do |config|
|
9
|
-
config.mock_with :rr
|
10
|
-
end
|
11
|
-
|
12
|
-
class Spec::ExampleGroup
|
13
|
-
class << self
|
14
|
-
def thin_logging
|
15
|
-
if @thin_logging.nil?
|
16
|
-
return false
|
17
|
-
else
|
18
|
-
@thin_logging
|
19
|
-
end
|
20
|
-
end
|
21
|
-
attr_writer :thin_logging
|
22
|
-
end
|
23
|
-
|
24
|
-
attr_reader :connection
|
25
|
-
before do
|
26
|
-
@connection = create_connection
|
27
|
-
|
28
|
-
stub(EventMachine).send_data {raise "EventMachine.send_data needs to be stubbed or mocked out"}
|
29
|
-
stub(EventMachine).close_connection {raise "EventMachine.close_connection needs to be stubbed or mocked out"}
|
30
|
-
stub(EventMachine).close_connection_after_writing {raise "EventMachine.close_connection_after_writing needs to be stubbed or mocked out"}
|
31
|
-
stub(EventMachine).set_comm_inactivity_timeout {raise "EventMachine.set_comm_inactivity_timeout needs to be stubbed or mocked out"}
|
32
|
-
stub(EventMachine).report_connection_error_status {0}
|
33
|
-
stub(EventMachine).add_timer
|
34
|
-
Thin::Logging.silent = !self.class.thin_logging
|
35
|
-
Thin::Logging.debug = self.class.thin_logging
|
36
|
-
end
|
37
|
-
|
38
|
-
after(:each) do
|
39
|
-
Thin::Logging.silent = true
|
40
|
-
Thin::Logging.debug = false
|
41
|
-
end
|
42
|
-
|
43
|
-
def create_connection(guid = Guid.new.to_s)
|
44
|
-
connection = TestConnection.new(guid)
|
45
|
-
connection.backend = Object.new
|
46
|
-
stub(connection.backend).connection_finished
|
47
|
-
connection
|
48
|
-
end
|
49
|
-
|
50
|
-
def stub_send_data
|
51
|
-
stub(EventMachine).send_data do |signature, data, data_length|
|
52
|
-
data_length
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
class TestConnection < ThinRest::Connection
|
58
|
-
def root_resource
|
59
|
-
Root.new(:connection => self)
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
class Root < ThinRest::Resources::Resource
|
64
|
-
property :connection
|
65
|
-
route 'subresource', 'Subresource'
|
66
|
-
route 'another_subresource', 'AnotherSubresource'
|
67
|
-
route 'block_subresource' do |properties, name|
|
68
|
-
BlockSubresource.new(properties.merge(:foobar => foobar))
|
69
|
-
end
|
70
|
-
route 'error_subresource', 'ErrorSubresource'
|
71
|
-
route 'wrong_property' do |properties, name|
|
72
|
-
WrongPropertySubresource.new(properties.merge(:baz => name))
|
73
|
-
end
|
74
|
-
|
75
|
-
|
76
|
-
def foobar
|
77
|
-
:baz
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
class Subresource < ThinRest::Resources::Resource
|
82
|
-
def do_get
|
83
|
-
"GET response"
|
84
|
-
end
|
85
|
-
|
86
|
-
def do_post
|
87
|
-
"POST response"
|
88
|
-
end
|
89
|
-
|
90
|
-
def do_put
|
91
|
-
"PUT response"
|
92
|
-
end
|
93
|
-
|
94
|
-
def do_delete
|
95
|
-
"DELETE response"
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
class AnotherSubresource < ThinRest::Resources::Resource
|
100
|
-
def do_get
|
101
|
-
"Another GET response"
|
102
|
-
end
|
103
|
-
|
104
|
-
def do_post
|
105
|
-
"Another POST response"
|
106
|
-
end
|
107
|
-
|
108
|
-
def do_put
|
109
|
-
"Another PUT response"
|
110
|
-
end
|
111
|
-
|
112
|
-
def do_delete
|
113
|
-
"Another DELETE response"
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
class BlockSubresource < ThinRest::Resources::Resource
|
118
|
-
property :foobar
|
119
|
-
end
|
120
|
-
|
121
|
-
class ErrorSubresource < ThinRest::Resources::Resource
|
122
|
-
ERROR_MESSAGE = "An Error"
|
123
|
-
|
124
|
-
def get
|
125
|
-
raise ERROR_MESSAGE
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
class WrongPropertySubresource < ThinRest::Resources::Resource
|
130
|
-
property :foobar
|
131
|
-
def get
|
132
|
-
"Wrong Property"
|
133
|
-
end
|
134
|
-
end
|