screw-unit 0.3.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.
- data/CHANGES +11 -0
- data/README.markdown +354 -0
- data/Rakefile +40 -0
- data/bin/screw_unit +6 -0
- data/bin/screw_unit_server +10 -0
- data/core/EXAMPLE.html +68 -0
- data/core/LICENSE +22 -0
- data/core/README.markdown +307 -0
- data/core/example/models/cat.js +5 -0
- data/core/example/models/man.js +17 -0
- data/core/example/spec/matchers/have.js +8 -0
- data/core/example/spec/models/cat_spec.js +31 -0
- data/core/example/spec/models/man_spec.js +34 -0
- data/core/example/spec/spec_helper.js +5 -0
- data/core/example/spec/suite.html +25 -0
- data/core/lib/jquery-1.2.6.js +3549 -0
- data/core/lib/jquery.fn.js +29 -0
- data/core/lib/jquery.print.js +109 -0
- data/core/lib/screw.assets.js +36 -0
- data/core/lib/screw.behaviors.js +91 -0
- data/core/lib/screw.builder.js +80 -0
- data/core/lib/screw.css +90 -0
- data/core/lib/screw.events.js +44 -0
- data/core/lib/screw.matchers.js +145 -0
- data/core/lib/screw.server.js +21 -0
- data/core/spec/behaviors_spec.js +178 -0
- data/core/spec/matchers_spec.js +237 -0
- data/core/spec/print_spec.js +152 -0
- data/core/spec/spec_helper.js +0 -0
- data/core/spec/suite.html +18 -0
- data/init.rb +0 -0
- data/lib/screw_unit.rb +26 -0
- data/lib/screw_unit/resources.rb +2 -0
- data/lib/screw_unit/resources/spec.rb +38 -0
- data/spec/functional/functional_spec.rb +25 -0
- data/spec/functional/functional_spec_helper.rb +55 -0
- data/spec/functional_suite.rb +10 -0
- data/spec/spec_suite.rb +3 -0
- data/spec/unit/js_test_core/specs/spec_dir_spec.rb +39 -0
- data/spec/unit/js_test_core/specs/spec_file_spec.rb +35 -0
- data/spec/unit/unit_spec_helper.rb +120 -0
- data/spec/unit_suite.rb +10 -0
- data/vendor/js-test-core/CHANGES +15 -0
- data/vendor/js-test-core/README +12 -0
- data/vendor/js-test-core/Rakefile +72 -0
- data/vendor/js-test-core/lib/js_test_core.rb +38 -0
- data/vendor/js-test-core/lib/js_test_core/client.rb +114 -0
- data/vendor/js-test-core/lib/js_test_core/extensions.rb +3 -0
- data/vendor/js-test-core/lib/js_test_core/extensions/time.rb +6 -0
- data/vendor/js-test-core/lib/js_test_core/rack.rb +2 -0
- data/vendor/js-test-core/lib/js_test_core/rack/commonlogger.rb +5 -0
- data/vendor/js-test-core/lib/js_test_core/rails_server.rb +22 -0
- data/vendor/js-test-core/lib/js_test_core/resources.rb +10 -0
- data/vendor/js-test-core/lib/js_test_core/resources/dir.rb +67 -0
- data/vendor/js-test-core/lib/js_test_core/resources/file.rb +49 -0
- data/vendor/js-test-core/lib/js_test_core/resources/file_not_found.rb +11 -0
- data/vendor/js-test-core/lib/js_test_core/resources/runner.rb +105 -0
- data/vendor/js-test-core/lib/js_test_core/resources/specs/spec_dir.rb +46 -0
- data/vendor/js-test-core/lib/js_test_core/resources/specs/spec_file.rb +17 -0
- data/vendor/js-test-core/lib/js_test_core/resources/suite.rb +40 -0
- data/vendor/js-test-core/lib/js_test_core/resources/suite_finish.rb +17 -0
- data/vendor/js-test-core/lib/js_test_core/resources/web_root.rb +63 -0
- data/vendor/js-test-core/lib/js_test_core/selenium.rb +2 -0
- data/vendor/js-test-core/lib/js_test_core/selenium/selenium_driver.rb +5 -0
- data/vendor/js-test-core/lib/js_test_core/selenium_server_configuration.rb +48 -0
- data/vendor/js-test-core/lib/js_test_core/server.rb +50 -0
- data/vendor/js-test-core/lib/js_test_core/thin.rb +3 -0
- data/vendor/js-test-core/lib/js_test_core/thin/backends/js_test_core_server.rb +9 -0
- data/vendor/js-test-core/lib/js_test_core/thin/js_test_core_connection.rb +8 -0
- data/vendor/js-test-core/spec/example_core/JsTestCore.css +0 -0
- data/vendor/js-test-core/spec/example_core/JsTestCore.js +0 -0
- data/vendor/js-test-core/spec/example_public/favicon.ico +0 -0
- data/vendor/js-test-core/spec/example_public/javascripts/foo.js +3 -0
- data/vendor/js-test-core/spec/example_public/javascripts/large_file.js +59 -0
- data/vendor/js-test-core/spec/example_public/javascripts/subdir/bar.js +1 -0
- data/vendor/js-test-core/spec/example_public/robots.txt +0 -0
- data/vendor/js-test-core/spec/example_public/stylesheets/example.css +3 -0
- data/vendor/js-test-core/spec/example_specs/failing_spec.js +5 -0
- data/vendor/js-test-core/spec/example_specs/foo/failing_spec.js +6 -0
- data/vendor/js-test-core/spec/example_specs/foo/passing_spec.js +6 -0
- data/vendor/js-test-core/spec/spec_suite.rb +2 -0
- data/vendor/js-test-core/spec/specs/failing_spec.js +0 -0
- data/vendor/js-test-core/spec/unit/js_test_core/client_spec.rb +166 -0
- data/vendor/js-test-core/spec/unit/js_test_core/rails_server_spec.rb +45 -0
- data/vendor/js-test-core/spec/unit/js_test_core/resources/dir_spec.rb +52 -0
- data/vendor/js-test-core/spec/unit/js_test_core/resources/file_not_found_spec.rb +16 -0
- data/vendor/js-test-core/spec/unit/js_test_core/resources/file_spec.rb +128 -0
- data/vendor/js-test-core/spec/unit/js_test_core/resources/runners/runner_spec.rb +283 -0
- data/vendor/js-test-core/spec/unit/js_test_core/resources/specs/spec_dir_spec.rb +105 -0
- data/vendor/js-test-core/spec/unit/js_test_core/resources/specs/spec_file_spec.rb +42 -0
- data/vendor/js-test-core/spec/unit/js_test_core/resources/suite_finish_spec.rb +82 -0
- data/vendor/js-test-core/spec/unit/js_test_core/resources/suite_spec.rb +86 -0
- data/vendor/js-test-core/spec/unit/js_test_core/resources/web_root_spec.rb +32 -0
- data/vendor/js-test-core/spec/unit/js_test_core/selenium_server_configuration_spec.rb +49 -0
- data/vendor/js-test-core/spec/unit/js_test_core/server_spec.rb +117 -0
- data/vendor/js-test-core/spec/unit/thin/js_test_core_connection_spec.rb +6 -0
- data/vendor/js-test-core/spec/unit/unit_spec_helper.rb +134 -0
- data/vendor/js-test-core/spec/unit_suite.rb +10 -0
- data/vendor/js-test-core/vendor/thin-rest/CHANGES +2 -0
- data/vendor/js-test-core/vendor/thin-rest/README +0 -0
- data/vendor/js-test-core/vendor/thin-rest/lib/thin_rest.rb +9 -0
- data/vendor/js-test-core/vendor/thin-rest/lib/thin_rest/connection.rb +116 -0
- data/vendor/js-test-core/vendor/thin-rest/lib/thin_rest/extensions.rb +3 -0
- data/vendor/js-test-core/vendor/thin-rest/lib/thin_rest/extensions/object.rb +21 -0
- data/vendor/js-test-core/vendor/thin-rest/lib/thin_rest/resource.rb +104 -0
- data/vendor/js-test-core/vendor/thin-rest/lib/thin_rest/resource_invalid.rb +4 -0
- data/vendor/js-test-core/vendor/thin-rest/lib/thin_rest/routing_error.rb +5 -0
- data/vendor/js-test-core/vendor/thin-rest/spec/spec_suite.rb +5 -0
- data/vendor/js-test-core/vendor/thin-rest/spec/thin_rest/connection_spec.rb +207 -0
- data/vendor/js-test-core/vendor/thin-rest/spec/thin_rest/resource_spec.rb +127 -0
- data/vendor/js-test-core/vendor/thin-rest/spec/thin_rest_spec_helper.rb +124 -0
- metadata +210 -0
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../../../unit_spec_helper")
|
|
2
|
+
|
|
3
|
+
module JsTestCore
|
|
4
|
+
module Resources
|
|
5
|
+
describe Runner do
|
|
6
|
+
attr_reader :request, :driver, :suite_id, :selenium_browser_start_command, :body
|
|
7
|
+
|
|
8
|
+
def self.before_with_selenium_browser_start_command(selenium_browser_start_command="selenium browser start command")
|
|
9
|
+
before do
|
|
10
|
+
@driver = "Selenium Driver"
|
|
11
|
+
@suite_id = "DEADBEEF"
|
|
12
|
+
@selenium_browser_start_command = selenium_browser_start_command
|
|
13
|
+
@body = "selenium_browser_start_command=#{selenium_browser_start_command}"
|
|
14
|
+
stub(Selenium::SeleniumDriver).new('localhost', 4444, selenium_browser_start_command, 'http://0.0.0.0:8080') do
|
|
15
|
+
driver
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
after do
|
|
21
|
+
Runner.send(:instances).clear
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
describe ".find" do
|
|
25
|
+
attr_reader :runner
|
|
26
|
+
before_with_selenium_browser_start_command
|
|
27
|
+
before do
|
|
28
|
+
@runner = Runner.new(:connection => connection, :selenium_browser_start_command => selenium_browser_start_command)
|
|
29
|
+
stub(runner).driver {driver}
|
|
30
|
+
stub(driver).session_id {suite_id}
|
|
31
|
+
Runner.register(runner)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
context "when passed an id for which there is a corresponding Runner" do
|
|
35
|
+
it "returns the Runner" do
|
|
36
|
+
Runner.find(suite_id).should == runner
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
context "when passed an id for which there is no corresponding Runner" do
|
|
41
|
+
it "returns nil" do
|
|
42
|
+
invalid_id = "666666666666666"
|
|
43
|
+
Runner.find(invalid_id).should be_nil
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
describe ".finalize" do
|
|
49
|
+
attr_reader :runner
|
|
50
|
+
before_with_selenium_browser_start_command
|
|
51
|
+
describe "when there is a runner for the passed in suite_id" do
|
|
52
|
+
before do
|
|
53
|
+
@runner = Runner.new(:connection => connection, :selenium_browser_start_command => selenium_browser_start_command)
|
|
54
|
+
stub(runner).driver {driver}
|
|
55
|
+
stub(driver).session_id {"DEADBEEF"}
|
|
56
|
+
|
|
57
|
+
Runner.register(runner)
|
|
58
|
+
runner.suite_id.should == suite_id
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
it "finalizes the Runner that has the suite_id and keeps the Runner in memory" do
|
|
62
|
+
mock(driver).stop
|
|
63
|
+
mock.proxy(runner).finalize("Browser output")
|
|
64
|
+
Runner.find(suite_id).should == runner
|
|
65
|
+
Runner.finalize(suite_id, "Browser output")
|
|
66
|
+
Runner.find(suite_id).should == runner
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
describe "when there is not a runner for the passed in suite_id" do
|
|
71
|
+
it "does nothing" do
|
|
72
|
+
lambda do
|
|
73
|
+
Runner.finalize("6666666", "nothing happens")
|
|
74
|
+
end.should_not raise_error
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
describe "POST /runners" do
|
|
80
|
+
before_with_selenium_browser_start_command
|
|
81
|
+
before do
|
|
82
|
+
stub(Thread).start.yields
|
|
83
|
+
stub(connection).send_head
|
|
84
|
+
stub(connection).send_body
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
it "responds with a 200 and the suite_id" do
|
|
88
|
+
stub(driver).start
|
|
89
|
+
stub(driver).open
|
|
90
|
+
stub(driver).session_id {suite_id}
|
|
91
|
+
|
|
92
|
+
mock(connection).send_head
|
|
93
|
+
mock(connection).send_body("suite_id=#{suite_id}")
|
|
94
|
+
connection.receive_data("POST /runners HTTP/1.1\r\nHost: _\r\nContent-Length: #{body.length}\r\n\r\n#{body}")
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
describe "when a selenium_host parameter is passed into the request" do
|
|
98
|
+
before do
|
|
99
|
+
stub(driver).start
|
|
100
|
+
stub(driver).open
|
|
101
|
+
stub(driver).session_id {suite_id}
|
|
102
|
+
body << "&selenium_host=another-machine"
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
it "starts the Selenium Driver with the passed in selenium_host" do
|
|
106
|
+
mock(Selenium::SeleniumDriver).new('another-machine', 4444, selenium_browser_start_command, 'http://0.0.0.0:8080') do
|
|
107
|
+
driver
|
|
108
|
+
end
|
|
109
|
+
connection.receive_data("POST /runners HTTP/1.1\r\nHost: _\r\nContent-Length: #{body.length}\r\n\r\n#{body}")
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
describe "when a selenium_host parameter is not passed into the request" do
|
|
114
|
+
before do
|
|
115
|
+
stub(driver).start
|
|
116
|
+
stub(driver).open
|
|
117
|
+
stub(driver).session_id {suite_id}
|
|
118
|
+
body << "&selenium_host="
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
it "starts the Selenium Driver from localhost" do
|
|
122
|
+
mock(Selenium::SeleniumDriver).new('localhost', 4444, selenium_browser_start_command, 'http://0.0.0.0:8080') do
|
|
123
|
+
driver
|
|
124
|
+
end
|
|
125
|
+
connection.receive_data("POST /runners HTTP/1.1\r\nHost: _\r\nContent-Length: #{body.length}\r\n\r\n#{body}")
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
describe "when a selenium_port parameter is passed into the request" do
|
|
130
|
+
before do
|
|
131
|
+
stub(driver).start
|
|
132
|
+
stub(driver).open
|
|
133
|
+
stub(driver).session_id {suite_id}
|
|
134
|
+
body << "&selenium_port=4000"
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
it "starts the Selenium Driver with the passed in selenium_port" do
|
|
138
|
+
mock(Selenium::SeleniumDriver).new('localhost', 4000, selenium_browser_start_command, 'http://0.0.0.0:8080') do
|
|
139
|
+
driver
|
|
140
|
+
end
|
|
141
|
+
connection.receive_data("POST /runners HTTP/1.1\r\nHost: _\r\nContent-Length: #{body.length}\r\n\r\n#{body}")
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
describe "when a selenium_port parameter is not passed into the request" do
|
|
146
|
+
before do
|
|
147
|
+
stub(driver).start
|
|
148
|
+
stub(driver).open
|
|
149
|
+
stub(driver).session_id {suite_id}
|
|
150
|
+
body << "&selenium_port="
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
it "starts the Selenium Driver from localhost" do
|
|
154
|
+
mock(Selenium::SeleniumDriver).new('localhost', 4444, selenium_browser_start_command, 'http://0.0.0.0:8080') do
|
|
155
|
+
driver
|
|
156
|
+
end
|
|
157
|
+
connection.receive_data("POST /runners HTTP/1.1\r\nHost: _\r\nContent-Length: #{body.length}\r\n\r\n#{body}")
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
describe "when a spec_url is passed into the request" do
|
|
162
|
+
it "runs Selenium with the passed in host and part to run the specified spec suite in Firefox" do
|
|
163
|
+
mock(Selenium::SeleniumDriver).new('localhost', 4444, selenium_browser_start_command, 'http://another-host:8080') do
|
|
164
|
+
driver
|
|
165
|
+
end
|
|
166
|
+
mock(driver).start
|
|
167
|
+
mock(driver).open("http://another-host:8080/specs/subdir")
|
|
168
|
+
mock(driver).session_id {suite_id}.at_least(1)
|
|
169
|
+
|
|
170
|
+
body << "&spec_url=http://another-host:8080/specs/subdir"
|
|
171
|
+
connection.receive_data("POST /runners HTTP/1.1\r\nHost: _\r\nContent-Length: #{body.length}\r\n\r\n#{body}")
|
|
172
|
+
end
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
describe "when a spec_url is not passed into the request" do
|
|
176
|
+
before do
|
|
177
|
+
mock(Selenium::SeleniumDriver).new('localhost', 4444, selenium_browser_start_command, 'http://0.0.0.0:8080') do
|
|
178
|
+
driver
|
|
179
|
+
end
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
it "uses Selenium to run the entire spec suite in Firefox" do
|
|
183
|
+
mock(driver).start
|
|
184
|
+
mock(driver).open("http://0.0.0.0:8080/specs")
|
|
185
|
+
mock(driver).session_id {suite_id}.at_least(1)
|
|
186
|
+
|
|
187
|
+
body << "&spec_url="
|
|
188
|
+
connection.receive_data("POST /runners HTTP/1.1\r\nHost: _\r\nContent-Length: #{body.length}\r\n\r\n#{body}")
|
|
189
|
+
end
|
|
190
|
+
end
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
describe "POST /runners/firefox" do
|
|
194
|
+
before_with_selenium_browser_start_command "*firefox"
|
|
195
|
+
|
|
196
|
+
it "creates a Runner whose #driver started with '*firefox'" do
|
|
197
|
+
stub(Thread).start.yields
|
|
198
|
+
stub(connection).send_head
|
|
199
|
+
stub(connection).send_body
|
|
200
|
+
|
|
201
|
+
stub(driver).start
|
|
202
|
+
stub(driver).open
|
|
203
|
+
stub(driver).session_id {suite_id}
|
|
204
|
+
|
|
205
|
+
mock(connection).send_head
|
|
206
|
+
mock(connection).send_body("suite_id=#{suite_id}")
|
|
207
|
+
|
|
208
|
+
Runner.find(suite_id).should be_nil
|
|
209
|
+
connection.receive_data("POST /runners/firefox HTTP/1.1\r\nHost: _\r\n\r\n")
|
|
210
|
+
runner = Runner.find(suite_id)
|
|
211
|
+
runner.class.should == Runner
|
|
212
|
+
runner.driver.should == driver
|
|
213
|
+
end
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
describe "POST /runners/iexplore" do
|
|
217
|
+
before_with_selenium_browser_start_command "*iexplore"
|
|
218
|
+
|
|
219
|
+
it "creates a Runner whose #driver started with '*iexplore'" do
|
|
220
|
+
stub(Thread).start.yields
|
|
221
|
+
stub(connection).send_head
|
|
222
|
+
stub(connection).send_body
|
|
223
|
+
|
|
224
|
+
stub(driver).start
|
|
225
|
+
stub(driver).open
|
|
226
|
+
stub(driver).session_id {suite_id}
|
|
227
|
+
|
|
228
|
+
mock(connection).send_head
|
|
229
|
+
mock(connection).send_body("suite_id=#{suite_id}")
|
|
230
|
+
|
|
231
|
+
Runner.find(suite_id).should be_nil
|
|
232
|
+
connection.receive_data("POST /runners/iexplore HTTP/1.1\r\nHost: _\r\n\r\n")
|
|
233
|
+
runner = Runner.find(suite_id)
|
|
234
|
+
runner.class.should == Runner
|
|
235
|
+
runner.driver.should == driver
|
|
236
|
+
end
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
describe "#finalize" do
|
|
240
|
+
attr_reader :runner
|
|
241
|
+
before_with_selenium_browser_start_command
|
|
242
|
+
before do
|
|
243
|
+
stub(driver).start
|
|
244
|
+
stub(driver).open
|
|
245
|
+
stub(driver).session_id {suite_id}
|
|
246
|
+
|
|
247
|
+
create_runner_connection = create_connection
|
|
248
|
+
stub(create_runner_connection).send_head
|
|
249
|
+
stub(create_runner_connection).send_body
|
|
250
|
+
create_runner_connection.receive_data("POST /runners HTTP/1.1\r\nHost: _\r\nContent-Length: #{body.length}\r\n\r\n#{body}")
|
|
251
|
+
@runner = Resources::Runner.find(suite_id)
|
|
252
|
+
mock(driver).stop
|
|
253
|
+
end
|
|
254
|
+
|
|
255
|
+
it "kills the browser and stores the #suite_run_result" do
|
|
256
|
+
suite_run_result = "The suite run result"
|
|
257
|
+
runner.finalize(suite_run_result)
|
|
258
|
+
runner.suite_run_result.should == suite_run_result
|
|
259
|
+
end
|
|
260
|
+
|
|
261
|
+
it "causes #running? to be false" do
|
|
262
|
+
runner.finalize("")
|
|
263
|
+
end
|
|
264
|
+
|
|
265
|
+
context "when passed an empty string" do
|
|
266
|
+
it "causes #successful? to be true" do
|
|
267
|
+
runner.finalize("")
|
|
268
|
+
runner.should be_successful
|
|
269
|
+
runner.should_not be_failed
|
|
270
|
+
end
|
|
271
|
+
end
|
|
272
|
+
|
|
273
|
+
context "when passed a non-empty string" do
|
|
274
|
+
it "causes #successful? to be false" do
|
|
275
|
+
runner.finalize("A bunch of error stuff")
|
|
276
|
+
runner.should_not be_successful
|
|
277
|
+
runner.should be_failed
|
|
278
|
+
end
|
|
279
|
+
end
|
|
280
|
+
end
|
|
281
|
+
end
|
|
282
|
+
end
|
|
283
|
+
end
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../../../unit_spec_helper")
|
|
2
|
+
|
|
3
|
+
module JsTestCore
|
|
4
|
+
module Resources
|
|
5
|
+
module Specs
|
|
6
|
+
describe SpecDir do
|
|
7
|
+
attr_reader :dir, :absolute_path, :relative_path
|
|
8
|
+
before do
|
|
9
|
+
@absolute_path = spec_root_path
|
|
10
|
+
@relative_path = "/specs"
|
|
11
|
+
@dir = Resources::Specs::SpecDir.new(:connection => connection, :absolute_path => absolute_path, :relative_path => relative_path)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
describe "#locate" do
|
|
15
|
+
context "when passed the name with an extension" do
|
|
16
|
+
context "when file exists" do
|
|
17
|
+
it "returns a Resources::File representing it" do
|
|
18
|
+
file = dir.locate("failing_spec.js")
|
|
19
|
+
file.relative_path.should == "/specs/failing_spec.js"
|
|
20
|
+
file.absolute_path.should == "#{spec_root_path}/failing_spec.js"
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
context "when file does not exist" do
|
|
25
|
+
it "raises error" do
|
|
26
|
+
lambda { dir.locate("nonexistent.js") }.should raise_error
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
context "when passed a name without an extension" do
|
|
32
|
+
context "when name corresponds to a subdirectory" do
|
|
33
|
+
it "returns a DirectoryRunner for the directory" do
|
|
34
|
+
subdir = dir.locate("foo")
|
|
35
|
+
subdir.should == spec_dir("/foo")
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
context "when name corresponds to a .js file" do
|
|
40
|
+
it "returns a SpecFile for the .js file" do
|
|
41
|
+
spec_file_name = "failing_spec"
|
|
42
|
+
subdir = dir.locate(spec_file_name)
|
|
43
|
+
subdir.should == JsTestCore::Resources::Specs::SpecFile.new(
|
|
44
|
+
:connection => connection,
|
|
45
|
+
:absolute_path => "#{spec_root_path}/#{spec_file_name}.js",
|
|
46
|
+
:relative_path => "/specs/#{spec_file_name}.js"
|
|
47
|
+
)
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
context "when name does not correspond to a .js file or directory" do
|
|
52
|
+
it "raises an error" do
|
|
53
|
+
lambda do
|
|
54
|
+
dir.locate("nonexistent")
|
|
55
|
+
end.should raise_error
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
describe "#get" do
|
|
62
|
+
attr_reader :request, :response
|
|
63
|
+
before do
|
|
64
|
+
@request = Rack::Request.new( Rack::MockRequest.env_for('/core') )
|
|
65
|
+
@response = Rack::Response.new
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
it "raises NotImplementedError" do
|
|
69
|
+
lambda do
|
|
70
|
+
dir.get
|
|
71
|
+
end.should raise_error(NotImplementedError)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
it "can be overridden from a Module without needing to redefine the #get method" do
|
|
75
|
+
spec_dir_class = Resources::Specs::SpecDir.clone
|
|
76
|
+
mod = Module.new do
|
|
77
|
+
def get
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
spec_dir_class.class_eval do
|
|
81
|
+
include mod
|
|
82
|
+
end
|
|
83
|
+
@dir = spec_dir_class.new(:connection => connection, :absolute_path => absolute_path, :relative_path => relative_path)
|
|
84
|
+
|
|
85
|
+
lambda do
|
|
86
|
+
dir.get
|
|
87
|
+
end.should_not raise_error
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
describe "GET /" do
|
|
92
|
+
context "when WebRoot.dispatch_specs has been invoked" do
|
|
93
|
+
it "redirects to /specs" do
|
|
94
|
+
WebRoot.dispatch_specs
|
|
95
|
+
mock(connection).send_head(301, :Location => '/specs')
|
|
96
|
+
mock(connection).send_body("<script type='text/javascript'>window.location.href='/specs';</script>")
|
|
97
|
+
|
|
98
|
+
connection.receive_data("GET / HTTP/1.1\r\nHost: _\r\n\r\n")
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../../../unit_spec_helper")
|
|
2
|
+
|
|
3
|
+
module JsTestCore
|
|
4
|
+
module Resources
|
|
5
|
+
module Specs
|
|
6
|
+
describe SpecFile do
|
|
7
|
+
attr_reader :file, :absolute_path, :relative_path, :request, :response
|
|
8
|
+
before do
|
|
9
|
+
@absolute_path = "#{spec_root_path}/failing_spec.js"
|
|
10
|
+
@relative_path = "/specs/failing_spec.js"
|
|
11
|
+
@file = Resources::Specs::SpecFile.new(:connection => connection, :absolute_path => absolute_path, :relative_path => relative_path)
|
|
12
|
+
@request = Rack::Request.new( Rack::MockRequest.env_for(relative_path) )
|
|
13
|
+
@response = Rack::Response.new
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
describe "#get" do
|
|
17
|
+
it "raises NotImplementedError" do
|
|
18
|
+
lambda do
|
|
19
|
+
file.get
|
|
20
|
+
end.should raise_error(NotImplementedError)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it "can be overridden from a Module without needing to redefine the #get method" do
|
|
24
|
+
spec_file_class = Resources::Specs::SpecFile.clone
|
|
25
|
+
mod = Module.new do
|
|
26
|
+
def get
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
spec_file_class.class_eval do
|
|
30
|
+
include mod
|
|
31
|
+
end
|
|
32
|
+
@file = spec_file_class.new(:connection => connection, :absolute_path => absolute_path, :relative_path => relative_path)
|
|
33
|
+
|
|
34
|
+
lambda do
|
|
35
|
+
file.get
|
|
36
|
+
end.should_not raise_error
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../../unit_spec_helper")
|
|
2
|
+
|
|
3
|
+
module JsTestCore
|
|
4
|
+
module Resources
|
|
5
|
+
describe SuiteFinish do
|
|
6
|
+
attr_reader :stdout
|
|
7
|
+
before do
|
|
8
|
+
@stdout = StringIO.new
|
|
9
|
+
SuiteFinish.const_set(:STDOUT, stdout)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
after do
|
|
13
|
+
SuiteFinish.__send__(:remove_const, :STDOUT)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
describe "POST /suites/:suite_id/finish" do
|
|
17
|
+
context "when :suite_id == 'user'" do
|
|
18
|
+
it "writes the body of the request to stdout" do
|
|
19
|
+
stub(connection).send_head
|
|
20
|
+
stub(connection).send_body
|
|
21
|
+
|
|
22
|
+
text = "The text in the POST body"
|
|
23
|
+
body = "text=#{text}"
|
|
24
|
+
connection.receive_data("POST /suites/user/finish HTTP/1.1\r\nHost: _\r\nContent-Length: #{body.length}\r\n\r\n#{body}")
|
|
25
|
+
stdout.string.should == "#{text}\n"
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "sends an empty body" do
|
|
29
|
+
text = "The text in the POST body"
|
|
30
|
+
body = "text=#{text}"
|
|
31
|
+
|
|
32
|
+
mock(connection).send_head
|
|
33
|
+
mock(connection).send_body("")
|
|
34
|
+
connection.receive_data("POST /suites/user/finish HTTP/1.1\r\nHost: _\r\nContent-Length: #{body.length}\r\n\r\n#{body}")
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
context "when :suite_id != 'user'" do
|
|
39
|
+
attr_reader :suite_id, :driver
|
|
40
|
+
before do
|
|
41
|
+
@suite_id = "DEADBEEF"
|
|
42
|
+
@driver = "Selenium Driver"
|
|
43
|
+
stub(Selenium::SeleniumDriver).new('localhost', 4444, '*firefox', 'http://0.0.0.0:8080') do
|
|
44
|
+
driver
|
|
45
|
+
end
|
|
46
|
+
stub(driver).start
|
|
47
|
+
stub(driver).open
|
|
48
|
+
stub(driver).session_id {suite_id}
|
|
49
|
+
stub(Thread).start.yields
|
|
50
|
+
|
|
51
|
+
firefox_connection = Thin::JsTestCoreConnection.new(Guid.new)
|
|
52
|
+
stub(firefox_connection).send_head
|
|
53
|
+
stub(firefox_connection).send_body
|
|
54
|
+
stub(firefox_connection).close_connection
|
|
55
|
+
firefox_connection.receive_data("POST /runners/firefox HTTP/1.1\r\nHost: _\r\n\r\n")
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it "calls Runner.finalize" do
|
|
59
|
+
text = "The text in the POST body"
|
|
60
|
+
body = "text=#{text}"
|
|
61
|
+
stub(connection).send_head
|
|
62
|
+
stub(connection).send_body
|
|
63
|
+
mock.proxy(Runner).finalize(suite_id.to_s, text)
|
|
64
|
+
mock(driver).stop
|
|
65
|
+
stub(connection).close_connection
|
|
66
|
+
|
|
67
|
+
connection.receive_data("POST /suites/#{suite_id}/finish HTTP/1.1\r\nHost: _\r\nContent-Length: #{body.length}\r\n\r\n#{body}")
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
it "responds with a blank body" do
|
|
71
|
+
stub(driver).stop
|
|
72
|
+
stub(connection).close_connection
|
|
73
|
+
|
|
74
|
+
mock(connection).send_head
|
|
75
|
+
mock(connection).send_body("")
|
|
76
|
+
connection.receive_data("POST /suites/#{suite_id}/finish HTTP/1.1\r\nHost: _\r\nContent-Length: 0\r\n\r\n")
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|