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
@@ -62,7 +62,7 @@ module JsTestCore
62
62
  context "when the Session is not found" do
63
63
  it "raises a SessionNotFound error" do
64
64
  mock_post_to_runner("*firefox")
65
- mock(request).get("/sessions/my_session_id") do
65
+ mock(request).get(Resources::SeleniumSession.path(":session_id", :session_id => "my_session_id")) do
66
66
  stub(session_response = Object.new).code {"404"}
67
67
  session_response
68
68
  end
@@ -78,15 +78,33 @@ module JsTestCore
78
78
  end
79
79
  end
80
80
 
81
+ context "when passed-in a timeout" do
82
+ it "wraps a timeout around the run" do
83
+ mock.proxy(Timeout).timeout(5)
84
+ mock_post_to_runner("*firefox")
85
+ mock_polling_returns([running_status, running_status, success_status])
86
+ Client.run(:timeout => 5)
87
+ end
88
+ end
89
+
90
+ context "when not passed-in a timeout" do
91
+ it "does not wrap a timeout around the run" do
92
+ dont_allow(Timeout).timeout
93
+ mock_post_to_runner("*firefox")
94
+ mock_polling_returns([running_status, running_status, success_status])
95
+ Client.run
96
+ end
97
+ end
98
+
81
99
  def mock_post_to_runner(selenium_browser_start_command)
82
100
  mock(start_session_response = Object.new).body {"session_id=my_session_id"}
83
- mock(request).post("/runners", "selenium_browser_start_command=#{CGI.escape(selenium_browser_start_command)}&selenium_host=localhost&selenium_port=4444") do
101
+ mock(request).post(Resources::SeleniumSession.path, "selenium_browser_start_command=#{CGI.escape(selenium_browser_start_command)}&selenium_host=localhost&selenium_port=4444") do
84
102
  start_session_response
85
103
  end
86
104
  end
87
105
 
88
106
  def mock_polling_returns(session_statuses=[])
89
- mock(request).get("/sessions/my_session_id") do
107
+ mock(request).get(Resources::SeleniumSession.path(":session_id", :session_id => "my_session_id")) do
90
108
  stub(session_response = Object.new).body {session_statuses.shift}
91
109
  stub(session_response).code {"200"}
92
110
  session_response
@@ -94,15 +112,15 @@ module JsTestCore
94
112
  end
95
113
 
96
114
  def running_status
97
- "status=#{Resources::Session::RUNNING}"
115
+ "status=#{Resources::SeleniumSession::RUNNING}"
98
116
  end
99
117
 
100
118
  def success_status
101
- "status=#{Resources::Session::SUCCESSFUL_COMPLETION}"
119
+ "status=#{Resources::SeleniumSession::SUCCESSFUL_COMPLETION}"
102
120
  end
103
121
 
104
122
  def failure_status(reason)
105
- "status=#{Resources::Session::FAILURE_COMPLETION}&reason=#{reason}"
123
+ "status=#{Resources::SeleniumSession::FAILURE_COMPLETION}&reason=#{reason}"
106
124
  end
107
125
  end
108
126
 
@@ -112,7 +130,7 @@ module JsTestCore
112
130
  stub(Client).puts
113
131
  end
114
132
 
115
- describe "when passed in Hash contains :selenium_browser_start_command" do
133
+ context "when passed-in Hash contains :selenium_browser_start_command" do
116
134
  it "passes the spec_url as a post parameter" do
117
135
  selenium_browser_start_command = '*iexplore'
118
136
  mock(Client).run(:selenium_browser_start_command => selenium_browser_start_command)
@@ -120,7 +138,7 @@ module JsTestCore
120
138
  end
121
139
  end
122
140
 
123
- describe "when passed in Hash contains :spec_url" do
141
+ context "when passed-in Hash contains :spec_url" do
124
142
  it "passes the spec_url as a post parameter" do
125
143
  spec_url = 'http://foobar.com/foo'
126
144
  mock(Client).run(:spec_url => spec_url)
@@ -128,7 +146,7 @@ module JsTestCore
128
146
  end
129
147
  end
130
148
 
131
- describe "when passed in Hash contains :selenium_host" do
149
+ context "when passed-in Hash contains :selenium_host" do
132
150
  it "passes the selenium_host as a post parameter" do
133
151
  selenium_host = 'test-runner'
134
152
  mock(Client).run(:selenium_host => selenium_host)
@@ -136,13 +154,20 @@ module JsTestCore
136
154
  end
137
155
  end
138
156
 
139
- describe "when passed in Hash contains :selenium_port" do
157
+ context "when passed-in Hash contains :selenium_port" do
140
158
  it "passes the selenium_port as a post parameter" do
141
159
  selenium_port = "5000"
142
160
  mock(Client).run(:selenium_port => selenium_port)
143
161
  client = Client.run_argv(['--selenium_port', selenium_port])
144
162
  end
145
163
  end
164
+
165
+ context "when passed-in Hash contains :timeout" do
166
+ it "passes the timeout as a post parameter" do
167
+ mock(Client).run(:timeout => 5)
168
+ client = Client.run_argv(['--timeout', "5"])
169
+ end
170
+ end
146
171
  end
147
172
 
148
173
  describe '#parts_from_query' do
@@ -0,0 +1,44 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../unit_spec_helper")
2
+
3
+ module JsTestCore
4
+ describe Configuration do
5
+ attr_reader :result
6
+
7
+ before do
8
+ @result = ""
9
+ end
10
+
11
+ describe ".spec_root" do
12
+ it "returns the Dir " do
13
+ Configuration.spec_root_path.should == spec_root_path
14
+ end
15
+ end
16
+
17
+ describe ".spec_root_path" do
18
+ it "returns the absolute path of the specs root directory" do
19
+ Configuration.spec_root_path.should == spec_root_path
20
+ end
21
+ end
22
+
23
+ describe ".public_path" do
24
+ it "returns the expanded path of the public path" do
25
+ Configuration.public_path.should == public_path
26
+ end
27
+ end
28
+
29
+ describe ".core_path" do
30
+ it "returns the expanded path to the JsTestCore core directory" do
31
+ Configuration.core_path.should == core_path
32
+ end
33
+ end
34
+
35
+ describe "#root_url" do
36
+ it "returns the url of the site's root" do
37
+ server = Configuration.new
38
+ server.host = "localhost"
39
+ server.port = 9999
40
+ server.root_url.should == "http://localhost:9999"
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,85 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../unit_spec_helper")
2
+
3
+ module JsTestCore
4
+ module Models
5
+ describe SeleniumSession do
6
+ attr_reader :driver, :session_id, :selenium_session
7
+
8
+ before do
9
+ @driver = FakeSeleniumDriver.new
10
+ @selenium_session = SeleniumSession.new(:spec_url => "http://localhost:8080/specs")
11
+ stub(selenium_session).driver {driver}
12
+ driver.start
13
+ @session_id = driver.session_id
14
+ SeleniumSession.register(selenium_session)
15
+ end
16
+
17
+ describe ".find" do
18
+ context "when passed an id for which there is a corresponding selenium_session" do
19
+ it "returns the selenium_session" do
20
+ SeleniumSession.find(session_id).should == selenium_session
21
+ end
22
+ end
23
+
24
+ context "when passed an id for which there is no corresponding selenium_session" do
25
+ it "returns nil" do
26
+ invalid_id = "666666666666666"
27
+ SeleniumSession.find(invalid_id).should be_nil
28
+ end
29
+ end
30
+ end
31
+
32
+ describe "#running?" do
33
+ context "when the driver#session_started? is true" do
34
+ it "returns true" do
35
+ driver.session_started?.should be_true
36
+ selenium_session.should be_running
37
+ end
38
+ end
39
+
40
+ context "when the driver#session_started? is false" do
41
+ it "returns false" do
42
+ driver.stop
43
+ driver.session_started?.should be_false
44
+ selenium_session.should_not be_running
45
+ end
46
+ end
47
+ end
48
+
49
+ describe "#finalize" do
50
+ attr_reader :selenium_session
51
+
52
+ before do
53
+ mock.proxy(driver).stop
54
+ end
55
+
56
+ it "kills the browser and stores the #run_result" do
57
+ run_result = "The session run result"
58
+ selenium_session.finish(run_result)
59
+ selenium_session.run_result.should == run_result
60
+ end
61
+
62
+ it "sets #run_result" do
63
+ selenium_session.finish("the result")
64
+ selenium_session.run_result.should == "the result"
65
+ end
66
+
67
+ context "when passed an empty string" do
68
+ it "causes #successful? to be true" do
69
+ selenium_session.finish("")
70
+ selenium_session.should be_successful
71
+ selenium_session.should_not be_failed
72
+ end
73
+ end
74
+
75
+ context "when passed a non-empty string" do
76
+ it "causes #successful? to be false" do
77
+ selenium_session.finish("A bunch of error stuff")
78
+ selenium_session.should_not be_successful
79
+ selenium_session.should be_failed
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,60 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../unit_spec_helper")
2
+
3
+ module JsTestCore
4
+ module Resources
5
+ describe CoreFile do
6
+ describe "Files" do
7
+ describe "GET /core/JsTestCore.js" do
8
+ it "renders the JsTestCore.js file, which lives in the core framework directory" do
9
+ absolute_path = "#{core_path}/JsTestCore.js"
10
+
11
+ response = get(CoreFile.path("JsTestCore.js"))
12
+ response.should be_http(
13
+ 200,
14
+ {
15
+ "Content-Type" => "text/javascript",
16
+ "Last-Modified" => ::File.mtime(absolute_path).rfc822
17
+ },
18
+ ::File.read(absolute_path)
19
+ )
20
+ end
21
+ end
22
+ end
23
+
24
+ describe "Directories" do
25
+ macro "returns a page with the files in the root core directory" do |relative_path|
26
+ it "returns a page with the files in the root core directory" do
27
+ response = get(CoreFile.path(relative_path))
28
+ response.should be_http(
29
+ 200,
30
+ {},
31
+ ""
32
+ )
33
+ doc = Nokogiri::HTML(response.body)
34
+ links = doc.search("a").map {|script| script["href"]}
35
+ links.should include("/core/JsTestCore.js")
36
+ links.should include("/core/JsTestCore.css")
37
+ links.should include("/core/subdir")
38
+ end
39
+ end
40
+ describe "GET /core" do
41
+ send("returns a page with the files in the root core directory", "")
42
+ end
43
+ describe "GET /core/" do
44
+ send("returns a page with the files in the root core directory", "/")
45
+ end
46
+
47
+ describe "GET /core/subdir" do
48
+ it "returns a page with the files in the directory" do
49
+ response = get(CoreFile.path("subdir"))
50
+ response.should be_http(
51
+ 200,
52
+ {},
53
+ %r(<a href="/core/subdir/SubDirFile.js">SubDirFile.js</a>)
54
+ )
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -3,86 +3,77 @@ require File.expand_path("#{File.dirname(__FILE__)}/../../unit_spec_helper")
3
3
  module JsTestCore
4
4
  module Resources
5
5
  describe File do
6
- before do
7
- WebRoot.dispatch_specs
8
- stub_send_data
9
- stub(EventMachine).close_connection
10
- end
11
-
12
- describe "GET" do
6
+ describe "Files" do
13
7
  describe "GET /stylesheets/example.css" do
14
- it "returns a page with a of files in the directory" do
8
+ it "returns the example.css file content as a css file" do
15
9
  path = "#{public_path}/stylesheets/example.css"
16
- mock(connection).send_head(200, 'Content-Type' => "text/css", 'Content-Length' => ::File.size(path), 'Last-Modified' => ::File.mtime(path).rfc822)
17
- mock(connection).send_data(::File.read(path))
18
-
19
- connection.receive_data("GET /stylesheets/example.css HTTP/1.1\r\nHost: _\r\n\r\n")
10
+ response = get("/stylesheets/example.css")
11
+ response.should be_http(
12
+ 200,
13
+ {
14
+ 'Content-Length' => ::File.size(path).to_s,
15
+ 'Content-Type' => "text/css",
16
+ 'Last-Modified' => ::File.mtime(path).rfc822
17
+ },
18
+ ::File.read(path)
19
+ )
20
20
  end
21
21
  end
22
22
 
23
- describe "GET /implementations/foo.js" do
24
- it "returns a page with a of files in the directory" do
23
+ describe "GET /javascripts/foo.js" do
24
+ it "returns the foo.js file content as a javascript file" do
25
25
  path = "#{public_path}/javascripts/foo.js"
26
- mock(connection).send_head(200, 'Content-Type' => "text/javascript", 'Content-Length' => ::File.size(path), 'Last-Modified' => ::File.mtime(path).rfc822)
27
- mock(connection).send_data(::File.read(path))
28
-
29
- connection.receive_data("GET /implementations/foo.js HTTP/1.1\r\nHost: _\r\n\r\n")
26
+ response = get("/javascripts/foo.js")
27
+ response.should be_http(
28
+ 200,
29
+ {
30
+ 'Content-Length' => ::File.size(path).to_s,
31
+ 'Content-Type' => "text/javascript",
32
+ 'Last-Modified' => ::File.mtime(path).rfc822
33
+ },
34
+ ::File.read(path)
35
+ )
30
36
  end
31
37
  end
32
38
 
33
39
  describe "GET /javascripts/subdir/bar.js - Subdirectory" do
34
- it "returns a page with a of files in the directory" do
40
+ it "returns the subdir/bar.js file content as a javascript file" do
35
41
  path = "#{public_path}/javascripts/subdir/bar.js"
36
- mock(connection).send_head(200, 'Content-Type' => "text/javascript", 'Content-Length' => ::File.size(path), 'Last-Modified' => ::File.mtime(path).rfc822)
37
- mock(connection).send_data(::File.read(path))
38
-
39
- connection.receive_data("GET /javascripts/subdir/bar.js HTTP/1.1\r\nHost: _\r\n\r\n")
40
- end
41
- end
42
-
43
- describe "GET /implementations/large_file.js - Large files" do
44
- it "returns a page in 1024 byte chunks" do
45
- chunk_count = 0
46
- path = "#{public_path}/javascripts/large_file.js"
47
- mock(connection).send_head(200, 'Content-Type' => "text/javascript", 'Content-Length' => ::File.size(path), 'Last-Modified' => ::File.mtime(path).rfc822)
48
- ::File.open(path) do |file|
49
- while !file.eof?
50
- chunk_count += 1
51
- mock(connection).send_data(file.read(1024))
52
- end
53
- end
54
-
55
- chunk_count.should == (::File.size(path) / 1024.0).ceil.to_i
56
- connection.receive_data("GET /javascripts/large_file.js HTTP/1.1\r\nHost: _\r\n\r\n")
42
+ response = get("/javascripts/subdir/bar.js")
43
+ response.should be_http(
44
+ 200,
45
+ {
46
+ 'Content-Length' => ::File.size(path).to_s,
47
+ 'Content-Type' => "text/javascript",
48
+ 'Last-Modified' => ::File.mtime(path).rfc822
49
+ },
50
+ ::File.read(path)
51
+ )
57
52
  end
58
53
  end
59
54
  end
60
55
 
61
-
62
- describe "==" do
63
- attr_reader :file, :absolute_path, :relative_path
64
-
65
- before do
66
- @absolute_path = "#{implementation_root_path}/foo.js"
67
- @relative_path = "/implementations/foo.js"
68
- @file = Resources::File.new(
69
- :connection => connection,
70
- :absolute_path => absolute_path,
71
- :relative_path => relative_path
72
- )
73
- end
74
-
75
- it "returns true when passed a file with the same absolute and relative paths" do
76
- file.should == Resources::File.new(:absolute_path => absolute_path, :relative_path => relative_path)
77
- end
78
-
79
- it "returns false when passed a file with a different absolute or relative path" do
80
- file.should_not == Resources::File.new(:absolute_path => absolute_path, :relative_path => "bogus")
81
- file.should_not == Resources::File.new(:absolute_path => "bogus", :relative_path => relative_path)
56
+ describe "Directories" do
57
+ describe "GET /stylesheets - Top level directory" do
58
+ it "returns a page with a of files in the directory" do
59
+ response = get("/stylesheets")
60
+ response.should be_http(
61
+ 200,
62
+ {},
63
+ %r(<a href="/stylesheets/example.css">example.css</a>)
64
+ )
65
+ end
82
66
  end
83
67
 
84
- it "when passed a Dir, returns false because File is not a Dir" do
85
- file.should_not == Resources::Dir.new(:absolute_path => absolute_path, :relative_path => relative_path)
68
+ describe "GET /javascripts/subdir - Subdirectory" do
69
+ it "returns a page with a of files in the directory" do
70
+ response = get("/javascripts/subdir")
71
+ response.should be_http(
72
+ 200,
73
+ {},
74
+ %r(<a href="/javascripts/subdir/bar.js">bar.js</a>)
75
+ )
76
+ end
86
77
  end
87
78
  end
88
79
  end
@@ -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