screw-unit 0.3.3 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -0,0 +1,51 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../unit_spec_helper")
2
+
3
+ module JsTestCore
4
+ module Resources
5
+ describe WebRoot do
6
+ describe "GET / - ResourceNotFound" do
7
+ it "returns a 404 error" do
8
+ response = get("/i_dont_exist")
9
+ response.should be_http(
10
+ 404,
11
+ {},
12
+ Regexp.new("File /i_dont_exist not found")
13
+ )
14
+ end
15
+ end
16
+
17
+ describe "PUT / - ResourceNotFound" do
18
+ it "returns a 404 error" do
19
+ response = put("/i_dont_exist")
20
+ response.should be_http(
21
+ 404,
22
+ {},
23
+ Regexp.new("File /i_dont_exist not found")
24
+ )
25
+ end
26
+ end
27
+
28
+ describe "POST / - ResourceNotFound" do
29
+ it "returns a 404 error" do
30
+ response = post("/i_dont_exist")
31
+ response.should be_http(
32
+ 404,
33
+ {},
34
+ Regexp.new("File /i_dont_exist not found")
35
+ )
36
+ end
37
+ end
38
+
39
+ describe "DELETE / - ResourceNotFound" do
40
+ it "returns a 404 error" do
41
+ response = delete("/i_dont_exist")
42
+ response.should be_http(
43
+ 404,
44
+ {},
45
+ Regexp.new("File /i_dont_exist not found")
46
+ )
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,362 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../unit_spec_helper")
2
+
3
+ module JsTestCore
4
+ module Resources
5
+ describe SeleniumSession do
6
+ attr_reader :request, :driver, :session_id, :selenium_browser_start_command
7
+
8
+ def self.before_with_selenium_browser_start_command(selenium_browser_start_command="selenium browser start command")
9
+ before do
10
+ @driver = FakeSeleniumDriver.new
11
+ @session_id = FakeSeleniumDriver::SESSION_ID
12
+ @selenium_browser_start_command = selenium_browser_start_command
13
+ stub(Selenium::Client::Driver).new('localhost', 4444, selenium_browser_start_command, 'http://0.0.0.0:8080') do
14
+ driver
15
+ end
16
+ end
17
+ end
18
+
19
+ after do
20
+ Models::SeleniumSession.send(:instances).clear
21
+ end
22
+
23
+ describe "POST /selenium_sessions" do
24
+ before_with_selenium_browser_start_command
25
+ before do
26
+ stub(Thread).start.yields
27
+ end
28
+
29
+ it "responds with a 200 and the session_id" do
30
+ Models::SeleniumSession.find(session_id).should be_nil
31
+ response = post(SeleniumSession.path("/"), {:selenium_browser_start_command => selenium_browser_start_command})
32
+ body = "session_id=#{session_id}"
33
+ response.should be_http(
34
+ 200,
35
+ {'Content-Length' => body.length.to_s},
36
+ body
37
+ )
38
+ end
39
+
40
+ it "starts the Selenium Driver, creates a SessionID cookie, and opens the spec page" do
41
+ mock(driver).start
42
+ stub(driver).session_id {session_id}
43
+ mock(driver).create_cookie("session_id=#{session_id}")
44
+ mock(driver).open("/")
45
+ mock(driver).open("/specs")
46
+
47
+ mock(Selenium::Client::Driver).new('localhost', 4444, selenium_browser_start_command, 'http://0.0.0.0:8080') do
48
+ driver
49
+ end
50
+ response = post(SeleniumSession.path("/"), {:selenium_browser_start_command => selenium_browser_start_command})
51
+ end
52
+
53
+ describe "when a selenium_host parameter is passed into the request" do
54
+ it "starts the Selenium Driver with the passed in selenium_host" do
55
+ mock(Selenium::Client::Driver).new('another-machine', 4444, selenium_browser_start_command, 'http://0.0.0.0:8080') do
56
+ driver
57
+ end
58
+ response = post(SeleniumSession.path("/"), {
59
+ :selenium_browser_start_command => selenium_browser_start_command,
60
+ :selenium_host => "another-machine"
61
+ })
62
+ end
63
+ end
64
+
65
+ describe "when a selenium_host parameter is not passed into the request" do
66
+ it "starts the Selenium Driver from localhost" do
67
+ mock(Selenium::Client::Driver).new('localhost', 4444, selenium_browser_start_command, 'http://0.0.0.0:8080') do
68
+ driver
69
+ end
70
+ response = post(SeleniumSession.path("/"), {
71
+ :selenium_browser_start_command => selenium_browser_start_command,
72
+ :selenium_host => ""
73
+ })
74
+ end
75
+ end
76
+
77
+ describe "when a selenium_port parameter is passed into the request" do
78
+ it "starts the Selenium Driver with the passed in selenium_port" do
79
+ mock(Selenium::Client::Driver).new('localhost', 4000, selenium_browser_start_command, 'http://0.0.0.0:8080') do
80
+ driver
81
+ end
82
+ response = post(SeleniumSession.path("/"), {
83
+ :selenium_browser_start_command => selenium_browser_start_command,
84
+ :selenium_port => "4000"
85
+ })
86
+ end
87
+ end
88
+
89
+ describe "when a selenium_port parameter is not passed into the request" do
90
+ it "starts the Selenium Driver from localhost" do
91
+ mock(Selenium::Client::Driver).new('localhost', 4444, selenium_browser_start_command, 'http://0.0.0.0:8080') do
92
+ driver
93
+ end
94
+ response = post(SeleniumSession.path("/"), {
95
+ :selenium_browser_start_command => selenium_browser_start_command,
96
+ :selenium_port => ""
97
+ })
98
+ end
99
+ end
100
+
101
+ describe "when a spec_url is passed into the request" do
102
+ it "runs Selenium with the passed in host and part to run the specified spec session in Firefox" do
103
+ mock(Selenium::Client::Driver).new('localhost', 4444, selenium_browser_start_command, 'http://another-host:8080') do
104
+ driver
105
+ end
106
+ mock(driver).start
107
+ stub(driver).create_cookie
108
+ mock(driver).open("/")
109
+ mock(driver).open("/specs/subdir")
110
+ mock(driver).session_id {session_id}.at_least(1)
111
+
112
+ response = post(SeleniumSession.path("/"), {
113
+ :selenium_browser_start_command => selenium_browser_start_command,
114
+ :spec_url => "http://another-host:8080/specs/subdir"
115
+ })
116
+ end
117
+ end
118
+
119
+ describe "when a spec_url is not passed into the request" do
120
+ before do
121
+ mock(Selenium::Client::Driver).new('localhost', 4444, selenium_browser_start_command, 'http://0.0.0.0:8080') do
122
+ driver
123
+ end
124
+ end
125
+
126
+ it "uses Selenium to run the entire spec session in Firefox" do
127
+ mock(driver).start
128
+ stub(driver).create_cookie
129
+ mock(driver).open("/")
130
+ mock(driver).open("/specs")
131
+ mock(driver).session_id {session_id}.at_least(1)
132
+
133
+ response = post(SeleniumSession.path("/"), {
134
+ :selenium_browser_start_command => selenium_browser_start_command,
135
+ :spec_url => ""
136
+ })
137
+ end
138
+ end
139
+ end
140
+
141
+ describe "POST /selenium_sessions/firefox" do
142
+ before_with_selenium_browser_start_command "*firefox"
143
+
144
+ it "creates a selenium_session whose #driver started with '*firefox'" do
145
+ Models::SeleniumSession.find(session_id).should be_nil
146
+ response = post(SeleniumSession.path("/firefox"))
147
+ body = "session_id=#{session_id}"
148
+ response.should be_http(
149
+ 200,
150
+ {'Content-Length' => body.length.to_s},
151
+ body
152
+ )
153
+
154
+ selenium_session = Models::SeleniumSession.find(session_id)
155
+ selenium_session.class.should == Models::SeleniumSession
156
+ selenium_session.driver.should == driver
157
+ end
158
+ end
159
+
160
+ describe "POST /selenium_sessions/iexplore" do
161
+ before_with_selenium_browser_start_command "*iexplore"
162
+
163
+ it "creates a selenium_session whose #driver started with '*iexplore'" do
164
+ Models::SeleniumSession.find(session_id).should be_nil
165
+ response = post(SeleniumSession.path("/iexplore"))
166
+ body = "session_id=#{session_id}"
167
+ response.should be_http(
168
+ 200,
169
+ {'Content-Length' => body.length.to_s},
170
+ body
171
+ )
172
+
173
+ selenium_session = Models::SeleniumSession.find(session_id)
174
+ selenium_session.class.should == Models::SeleniumSession
175
+ selenium_session.driver.should == driver
176
+ end
177
+ end
178
+
179
+ describe "GET /sessions/:session_id" do
180
+ context "when there is no Runner with the :session_id" do
181
+ it "responds with a 404" do
182
+ session_id = "invalid_session_id"
183
+ response = get(SeleniumSession.path(session_id))
184
+ response.body.should include("Could not find session #{session_id}")
185
+ response.status.should == 404
186
+ end
187
+ end
188
+
189
+ context "when there is a Runner with the :session_id" do
190
+ attr_reader :driver, :session_id, :session_runner
191
+ before do
192
+ @driver = FakeSeleniumDriver.new
193
+ @session_id = FakeSeleniumDriver::SESSION_ID
194
+ stub(Selenium::Client::Driver).new('localhost', 4444, '*firefox', 'http://0.0.0.0:8080') do
195
+ driver
196
+ end
197
+
198
+ post(SeleniumSession.path('firefox'))
199
+ @session_runner = Models::SeleniumSession.find(session_id)
200
+ session_runner.should be_running
201
+ end
202
+
203
+ context "when a Runner with the :session_id is running" do
204
+ it "responds with a 200 and status=running" do
205
+ response = get(SeleniumSession.path(session_id))
206
+
207
+ body = "status=#{SeleniumSession::RUNNING}"
208
+ response.should be_http(200, {'Content-Length' => body.length.to_s}, body)
209
+ end
210
+ end
211
+
212
+ context "when a Runner with the :session_id has completed" do
213
+ context "when the session has a status of 'success'" do
214
+ before do
215
+ session_runner.finish("")
216
+ session_runner.should be_successful
217
+ end
218
+
219
+ it "responds with a 200 and status=success" do
220
+ response = get(SeleniumSession.path(session_id))
221
+
222
+ body = "status=#{SeleniumSession::SUCCESSFUL_COMPLETION}"
223
+ response.should be_http(200, {'Content-Length' => body.length.to_s}, body)
224
+ end
225
+ end
226
+
227
+ context "when the session has a status of 'failure'" do
228
+ attr_reader :reason
229
+ before do
230
+ @reason = "Failure stuff"
231
+ session_runner.finish(reason)
232
+ session_runner.should be_failed
233
+ end
234
+
235
+ it "responds with a 200 and status=failure and reason" do
236
+ response = get(SeleniumSession.path(session_id))
237
+
238
+ body = "status=#{SeleniumSession::FAILURE_COMPLETION}&reason=#{reason}"
239
+ response.should be_http(200, {'Content-Length' => body.length.to_s}, body)
240
+ end
241
+ end
242
+ end
243
+ end
244
+ end
245
+
246
+ describe "finish" do
247
+ attr_reader :stdout
248
+ before do
249
+ @stdout = StringIO.new
250
+ SeleniumSession.const_set(:STDOUT, stdout)
251
+ end
252
+
253
+ after do
254
+ SeleniumSession.__send__(:remove_const, :STDOUT)
255
+ end
256
+
257
+ describe "POST /selenium_sessions/finish" do
258
+ attr_reader :selenium_session
259
+ context "when passed a :session_id parameter" do
260
+ context "when :session_id does not match a registered SeleniumSession" do
261
+ it "returns the text and writes the text to stdout" do
262
+ Models::SeleniumSession.find(1).should be_nil
263
+
264
+ text = "The text in the POST body"
265
+ response = post(SeleniumSession.path("/finish", :session_id => 1), :text => text)
266
+ response.should be_http(
267
+ 200,
268
+ {},
269
+ text
270
+ )
271
+ stdout.string.should == "#{text}\n"
272
+ end
273
+ end
274
+
275
+ context "when :session_id matches a registered SeleniumSession" do
276
+ before do
277
+ @driver = FakeSeleniumDriver.new
278
+ @selenium_session = Models::SeleniumSession.new(:spec_url => "http://localhost:8080/specs")
279
+ stub(selenium_session).driver {driver}
280
+ driver.start
281
+ @session_id = driver.session_id
282
+ Models::SeleniumSession.register(selenium_session)
283
+ end
284
+
285
+ it "finishes the SeleniumSession" do
286
+ text = "The text in the POST body"
287
+ mock.proxy(selenium_session).finish(text)
288
+ selenium_session.should be_running
289
+
290
+ response = post(SeleniumSession.path("/finish", :session_id => session_id), :text => text)
291
+ response.should be_http(
292
+ 200,
293
+ {},
294
+ text
295
+ )
296
+ selenium_session.should_not be_running
297
+ end
298
+ end
299
+ end
300
+
301
+ context "when the session_id cookie is set" do
302
+ context "when :session_id does not match a registered SeleniumSession" do
303
+ it "returns the text and writes the text to stdout" do
304
+ Models::SeleniumSession.find(1).should be_nil
305
+
306
+ text = "The text in the POST body"
307
+ response = post(SeleniumSession.path("/finish"), {:text => text}, {:cookie => "session_id=1"})
308
+ response.should be_http(
309
+ 200,
310
+ {},
311
+ text
312
+ )
313
+ stdout.string.should == "#{text}\n"
314
+ end
315
+ end
316
+
317
+ context "when :session_id matches a registered SeleniumSession" do
318
+ attr_reader :selenium_session
319
+ before do
320
+ @driver = FakeSeleniumDriver.new
321
+ @selenium_session = Models::SeleniumSession.new(:spec_url => "http://localhost:8080/specs")
322
+ stub(selenium_session).driver {driver}
323
+ driver.start
324
+ @session_id = driver.session_id
325
+ Models::SeleniumSession.register(selenium_session)
326
+ end
327
+
328
+ it "finishes the SeleniumSession" do
329
+ text = "The text in the POST body"
330
+ mock.proxy(selenium_session).finish(text)
331
+ selenium_session.should be_running
332
+
333
+ response = post(SeleniumSession.path("/finish"), {:text => text}, {:cookie => "session_id=#{session_id}"})
334
+ response.should be_http(
335
+ 200,
336
+ {},
337
+ text
338
+ )
339
+ selenium_session.should_not be_running
340
+ end
341
+ end
342
+ end
343
+ end
344
+
345
+ describe "POST /sessions/:session_id/finish" do
346
+ it "returns the text and writes the text to stdout" do
347
+ text = "The text in the POST body"
348
+
349
+ response = post(SeleniumSession.path("/:session_id/finish", :session_id => 1), :text => text)
350
+ response.should be_http(
351
+ 200,
352
+ {},
353
+ text
354
+ )
355
+ stdout.string.should == "#{text}\n"
356
+ end
357
+ end
358
+
359
+ end
360
+ end
361
+ end
362
+ end
@@ -0,0 +1,120 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../unit_spec_helper")
2
+
3
+ module JsTestCore
4
+ module Resources
5
+ describe SpecFile do
6
+ describe "Files" do
7
+ describe "GET /specs/failing_spec" do
8
+ it "renders a suite only for failing_spec.js as text/html" do
9
+ absolute_path = "#{spec_root_path}/failing_spec.js"
10
+
11
+ response = get(SpecFile.path("failing_spec"))
12
+ response.should be_http(
13
+ 200,
14
+ {
15
+ "Content-Type" => "text/html",
16
+ "Last-Modified" => ::File.mtime(absolute_path).rfc822
17
+ },
18
+ ""
19
+ )
20
+ doc = Nokogiri::HTML(response.body)
21
+ js_files = doc.search("script").map {|script| script["src"]}
22
+ js_files.should include("/specs/failing_spec.js")
23
+ end
24
+ end
25
+
26
+ describe "GET /specs/failing_spec.js" do
27
+ it "renders the contents of failing_spec.js as text/javascript" do
28
+ absolute_path = "#{spec_root_path}/failing_spec.js"
29
+
30
+ response = get(SpecFile.path("failing_spec.js"))
31
+ response.should be_http(
32
+ 200,
33
+ {
34
+ "Content-Type" => "text/javascript",
35
+ "Last-Modified" => ::File.mtime(absolute_path).rfc822
36
+ },
37
+ ::File.read(absolute_path)
38
+ )
39
+ end
40
+ end
41
+
42
+ describe "GET /specs/custom_suite" do
43
+ it "renders the custom_suite.html file" do
44
+ path = "#{spec_root_path}/custom_suite.html"
45
+
46
+ response = get(SpecFile.path("custom_suite.html"))
47
+ response.should be_http(
48
+ 200,
49
+ {
50
+ "Content-Type" => "text/html",
51
+ "Last-Modified" => ::File.mtime(path).rfc822
52
+ },
53
+ ::File.read(path)
54
+ )
55
+ end
56
+ end
57
+ end
58
+
59
+ describe "Directories" do
60
+ describe "GET /specs" do
61
+ macro "renders a suite for all specs" do |relative_path|
62
+ it "renders a suite for all specs" do
63
+ path = "#{spec_root_path}"
64
+
65
+ response = get(relative_path)
66
+ response.should be_http(
67
+ 200,
68
+ {
69
+ "Content-Type" => "text/html",
70
+ "Last-Modified" => ::File.mtime(path).rfc822
71
+ },
72
+ ""
73
+ )
74
+ doc = Nokogiri::HTML(response.body)
75
+ js_files = doc.search("script").map {|script| script["src"]}
76
+ js_files.should include("/specs/failing_spec.js")
77
+ js_files.should include("/specs/custom_dir_and_suite/passing_spec.js")
78
+ js_files.should include("/specs/foo/passing_spec.js")
79
+ js_files.should include("/specs/foo/failing_spec.js")
80
+ end
81
+ end
82
+
83
+ send("renders a suite for all specs", SpecFile.path)
84
+ send("renders a suite for all specs", SpecFile.path("/"))
85
+ end
86
+
87
+ describe "GET /specs/foo" do
88
+ it "renders a spec suite that includes all of the javascript spec files in the directory" do
89
+ path = "#{spec_root_path}/foo"
90
+
91
+ response = get(SpecFile.path("foo"))
92
+ response.should be_http(
93
+ 200,
94
+ {
95
+ "Content-Type" => "text/html",
96
+ "Last-Modified" => ::File.mtime(path).rfc822
97
+ },
98
+ ""
99
+ )
100
+ doc = Nokogiri::HTML(response.body)
101
+ js_files = doc.search("script").map {|script| script["src"]}
102
+ js_files.should include("/specs/foo/passing_spec.js")
103
+ js_files.should include("/specs/foo/failing_spec.js")
104
+ end
105
+ end
106
+ end
107
+
108
+ describe "GET /specs/i_dont_exist" do
109
+ it "renders a 404" do
110
+ response = get(SpecFile.path("i_dont_exist"))
111
+ response.should be_http(
112
+ 404,
113
+ {},
114
+ "/specs/i_dont_exist not found"
115
+ )
116
+ end
117
+ end
118
+ end
119
+ end
120
+ end