pivotal-screw-unit-server 0.5.3

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 (112) hide show
  1. data/CHANGES +27 -0
  2. data/README.markdown +354 -0
  3. data/Rakefile +42 -0
  4. data/VERSION.yml +4 -0
  5. data/bin/screw_unit +6 -0
  6. data/bin/screw_unit_server +20 -0
  7. data/core/CHANGES +10 -0
  8. data/core/EXAMPLE.html +68 -0
  9. data/core/LICENSE +22 -0
  10. data/core/README.markdown +307 -0
  11. data/core/example/models/cat.js +5 -0
  12. data/core/example/models/man.js +17 -0
  13. data/core/example/spec/matchers/have.js +8 -0
  14. data/core/example/spec/models/cat_spec.js +31 -0
  15. data/core/example/spec/models/man_spec.js +34 -0
  16. data/core/example/spec/spec_helper.js +5 -0
  17. data/core/example/spec/suite.html +25 -0
  18. data/core/lib/jquery-1.3.2.js +4376 -0
  19. data/core/lib/jquery.fn.js +30 -0
  20. data/core/lib/jquery.print.js +109 -0
  21. data/core/lib/screw.behaviors.js +93 -0
  22. data/core/lib/screw.builder.js +95 -0
  23. data/core/lib/screw.css +90 -0
  24. data/core/lib/screw.events.js +45 -0
  25. data/core/lib/screw.matchers.js +244 -0
  26. data/core/spec/behaviors_spec.js +188 -0
  27. data/core/spec/matchers_spec.js +372 -0
  28. data/core/spec/print_spec.js +158 -0
  29. data/core/spec/spec_helper.js +0 -0
  30. data/core/spec/suite.html +19 -0
  31. data/core/spec/with_screw_context_spec.js +9 -0
  32. data/init.rb +0 -0
  33. data/lib/screw_unit.rb +23 -0
  34. data/lib/screw_unit/representations.rb +2 -0
  35. data/lib/screw_unit/representations/spec.html.rb +117 -0
  36. data/spec/functional/functional_spec.rb +25 -0
  37. data/spec/functional/functional_spec_helper.rb +43 -0
  38. data/spec/functional/functional_spec_server_starter.rb +68 -0
  39. data/spec/functional_suite.rb +10 -0
  40. data/spec/spec_suite.rb +3 -0
  41. data/spec/unit/js_test_core/specs/spec_file_spec.rb +68 -0
  42. data/spec/unit/unit_spec_helper.rb +51 -0
  43. data/spec/unit_suite.rb +10 -0
  44. data/vendor/js-test-core/CHANGES +28 -0
  45. data/vendor/js-test-core/README +12 -0
  46. data/vendor/js-test-core/Rakefile +73 -0
  47. data/vendor/js-test-core/lib/js_test_core.rb +46 -0
  48. data/vendor/js-test-core/lib/js_test_core/app.rb +12 -0
  49. data/vendor/js-test-core/lib/js_test_core/client.rb +129 -0
  50. data/vendor/js-test-core/lib/js_test_core/configuration.rb +35 -0
  51. data/vendor/js-test-core/lib/js_test_core/extensions.rb +3 -0
  52. data/vendor/js-test-core/lib/js_test_core/extensions/selenium/client/driver.rb +7 -0
  53. data/vendor/js-test-core/lib/js_test_core/extensions/time.rb +6 -0
  54. data/vendor/js-test-core/lib/js_test_core/models.rb +8 -0
  55. data/vendor/js-test-core/lib/js_test_core/models/selenium_session.rb +80 -0
  56. data/vendor/js-test-core/lib/js_test_core/representations.rb +11 -0
  57. data/vendor/js-test-core/lib/js_test_core/representations/dir.html.rb +24 -0
  58. data/vendor/js-test-core/lib/js_test_core/representations/not_found.html.rb +15 -0
  59. data/vendor/js-test-core/lib/js_test_core/representations/page.html.rb +41 -0
  60. data/vendor/js-test-core/lib/js_test_core/representations/spec.html.rb +24 -0
  61. data/vendor/js-test-core/lib/js_test_core/resources.rb +16 -0
  62. data/vendor/js-test-core/lib/js_test_core/resources/core_file.rb +19 -0
  63. data/vendor/js-test-core/lib/js_test_core/resources/file.rb +62 -0
  64. data/vendor/js-test-core/lib/js_test_core/resources/implementations_deprecation.rb +12 -0
  65. data/vendor/js-test-core/lib/js_test_core/resources/not_found.rb +35 -0
  66. data/vendor/js-test-core/lib/js_test_core/resources/resource.rb +16 -0
  67. data/vendor/js-test-core/lib/js_test_core/resources/selenium_session.rb +104 -0
  68. data/vendor/js-test-core/lib/js_test_core/resources/spec_file.rb +63 -0
  69. data/vendor/js-test-core/lib/js_test_core/resources/web_root.rb +11 -0
  70. data/vendor/js-test-core/lib/js_test_core/selenium_server_configuration.rb +48 -0
  71. data/vendor/js-test-core/spec/example_core/JsTestCore.css +0 -0
  72. data/vendor/js-test-core/spec/example_core/JsTestCore.js +0 -0
  73. data/vendor/js-test-core/spec/example_core/subdir/SubDirFile.js +0 -0
  74. data/vendor/js-test-core/spec/example_public/favicon.ico +0 -0
  75. data/vendor/js-test-core/spec/example_public/javascripts/foo.js +3 -0
  76. data/vendor/js-test-core/spec/example_public/javascripts/large_file.js +59 -0
  77. data/vendor/js-test-core/spec/example_public/javascripts/subdir/bar.js +1 -0
  78. data/vendor/js-test-core/spec/example_public/robots.txt +0 -0
  79. data/vendor/js-test-core/spec/example_public/stylesheets/example.css +3 -0
  80. data/vendor/js-test-core/spec/example_specs/custom_dir_and_suite/passing_spec.js +6 -0
  81. data/vendor/js-test-core/spec/example_specs/custom_suite.html +8 -0
  82. data/vendor/js-test-core/spec/example_specs/failing_spec.js +5 -0
  83. data/vendor/js-test-core/spec/example_specs/foo/failing_spec.js +6 -0
  84. data/vendor/js-test-core/spec/example_specs/foo/passing_spec.js +6 -0
  85. data/vendor/js-test-core/spec/spec_helpers/be_http.rb +32 -0
  86. data/vendor/js-test-core/spec/spec_helpers/example_group.rb +36 -0
  87. data/vendor/js-test-core/spec/spec_helpers/fake_selenium_driver.rb +27 -0
  88. data/vendor/js-test-core/spec/spec_helpers/show_test_exceptions.rb +22 -0
  89. data/vendor/js-test-core/spec/spec_suite.rb +2 -0
  90. data/vendor/js-test-core/spec/specs/failing_spec.js +0 -0
  91. data/vendor/js-test-core/spec/unit/js_test_core/client_spec.rb +192 -0
  92. data/vendor/js-test-core/spec/unit/js_test_core/configuration_spec.rb +44 -0
  93. data/vendor/js-test-core/spec/unit/js_test_core/models/selenium_session_spec.rb +85 -0
  94. data/vendor/js-test-core/spec/unit/js_test_core/resources/core_file_spec.rb +60 -0
  95. data/vendor/js-test-core/spec/unit/js_test_core/resources/file_spec.rb +81 -0
  96. data/vendor/js-test-core/spec/unit/js_test_core/resources/implementations_deprecation_spec.rb +18 -0
  97. data/vendor/js-test-core/spec/unit/js_test_core/resources/not_found_spec.rb +51 -0
  98. data/vendor/js-test-core/spec/unit/js_test_core/resources/selenium_session_spec.rb +362 -0
  99. data/vendor/js-test-core/spec/unit/js_test_core/resources/spec_file_spec.rb +120 -0
  100. data/vendor/js-test-core/spec/unit/js_test_core/resources/web_root_spec.rb +28 -0
  101. data/vendor/js-test-core/spec/unit/js_test_core/selenium_server_configuration_spec.rb +49 -0
  102. data/vendor/js-test-core/spec/unit/unit_spec_helper.rb +28 -0
  103. data/vendor/js-test-core/spec/unit_suite.rb +10 -0
  104. data/vendor/js-test-core/vendor/lucky-luciano/README.markdown +7 -0
  105. data/vendor/js-test-core/vendor/lucky-luciano/lib/lucky_luciano.rb +4 -0
  106. data/vendor/js-test-core/vendor/lucky-luciano/lib/lucky_luciano/resource.rb +135 -0
  107. data/vendor/js-test-core/vendor/lucky-luciano/lib/lucky_luciano/rspec.rb +4 -0
  108. data/vendor/js-test-core/vendor/lucky-luciano/lib/lucky_luciano/rspec/be_http.rb +32 -0
  109. data/vendor/js-test-core/vendor/lucky-luciano/spec/lucky_luciano/resource_spec.rb +231 -0
  110. data/vendor/js-test-core/vendor/lucky-luciano/spec/spec_helper.rb +48 -0
  111. data/vendor/js-test-core/vendor/lucky-luciano/spec/spec_suite.rb +4 -0
  112. metadata +198 -0
@@ -0,0 +1,18 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../unit_spec_helper")
2
+
3
+ module JsTestCore
4
+ module Resources
5
+ describe ImplementationsDeprecation do
6
+ describe "GET /implementations/*" do
7
+ it "responds with a 301 to /javascripts/*" do
8
+ response = get(ImplementationsDeprecation.path("/subdir/bar.js"))
9
+ response.should be_http(
10
+ 301,
11
+ {'Location' => File.path("/javascripts/subdir/bar.js")},
12
+ "This page has been moved to #{File.path("/javascripts/subdir/bar.js")}"
13
+ )
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -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