js_spec 0.3.2 → 0.3.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 (27) hide show
  1. data/CHANGES +3 -0
  2. data/Rakefile +1 -1
  3. data/core/JSSpecExtensions.js +5 -11
  4. data/spec/integration/integration_spec_helper.rb +1 -1
  5. data/spec/spec_suite.rb +0 -1
  6. data/spec/unit/js_test_core/resources/spec_dir_spec.rb +6 -6
  7. data/spec/unit/js_test_core/resources/spec_file_spec.rb +4 -4
  8. data/spec/unit/unit_spec_helper.rb +1 -3
  9. data/vendor/js-test-core/CHANGES +4 -0
  10. data/vendor/js-test-core/lib/js_test_core/client.rb +19 -16
  11. data/vendor/js-test-core/lib/js_test_core/resources.rb +2 -2
  12. data/vendor/js-test-core/lib/js_test_core/resources/runner.rb +17 -15
  13. data/vendor/js-test-core/lib/js_test_core/resources/{suite.rb → session.rb} +8 -4
  14. data/vendor/js-test-core/lib/js_test_core/resources/{suite_finish.rb → session_finish.rb} +5 -5
  15. data/vendor/js-test-core/lib/js_test_core/resources/web_root.rb +6 -3
  16. data/vendor/js-test-core/spec/unit/js_test_core/client_spec.rb +22 -21
  17. data/vendor/js-test-core/spec/unit/js_test_core/resources/runners/runner_spec.rb +83 -63
  18. data/vendor/js-test-core/spec/unit/js_test_core/resources/{suite_finish_spec.rb → session_finish_spec.rb} +15 -18
  19. data/vendor/js-test-core/spec/unit/js_test_core/resources/session_spec.rb +82 -0
  20. data/vendor/js-test-core/spec/unit/js_test_core/resources/specs/spec_dir_spec.rb +3 -3
  21. data/vendor/js-test-core/spec/unit/unit_spec_helper.rb +37 -10
  22. data/vendor/js-test-core/vendor/thin-rest/lib/thin_rest/resource.rb +4 -0
  23. metadata +84 -87
  24. data/spec/functional/functional_spec_helper.rb +0 -18
  25. data/spec/functional/server_spec.rb +0 -5
  26. data/spec/functional_suite.rb +0 -10
  27. data/vendor/js-test-core/spec/unit/js_test_core/resources/suite_spec.rb +0 -86
@@ -3,12 +3,12 @@ require File.expand_path("#{File.dirname(__FILE__)}/../../../unit_spec_helper")
3
3
  module JsTestCore
4
4
  module Resources
5
5
  describe Runner do
6
- attr_reader :request, :driver, :suite_id, :selenium_browser_start_command, :body
6
+ attr_reader :request, :driver, :session_id, :selenium_browser_start_command, :body
7
7
 
8
8
  def self.before_with_selenium_browser_start_command(selenium_browser_start_command="selenium browser start command")
9
9
  before do
10
- @driver = "Selenium Driver"
11
- @suite_id = "DEADBEEF"
10
+ @driver = FakeSeleniumDriver.new
11
+ @session_id = FakeSeleniumDriver::SESSION_ID
12
12
  @selenium_browser_start_command = selenium_browser_start_command
13
13
  @body = "selenium_browser_start_command=#{selenium_browser_start_command}"
14
14
  stub(Selenium::SeleniumDriver).new('localhost', 4444, selenium_browser_start_command, 'http://0.0.0.0:8080') do
@@ -27,13 +27,13 @@ module JsTestCore
27
27
  before do
28
28
  @runner = Runner.new(:connection => connection, :selenium_browser_start_command => selenium_browser_start_command)
29
29
  stub(runner).driver {driver}
30
- stub(driver).session_id {suite_id}
30
+ stub(driver).session_id {session_id}
31
31
  Runner.register(runner)
32
32
  end
33
33
 
34
34
  context "when passed an id for which there is a corresponding Runner" do
35
35
  it "returns the Runner" do
36
- Runner.find(suite_id).should == runner
36
+ Runner.find(session_id).should == runner
37
37
  end
38
38
  end
39
39
 
@@ -48,26 +48,26 @@ module JsTestCore
48
48
  describe ".finalize" do
49
49
  attr_reader :runner
50
50
  before_with_selenium_browser_start_command
51
- describe "when there is a runner for the passed in suite_id" do
51
+ describe "when there is a runner for the passed in session_id" do
52
52
  before do
53
53
  @runner = Runner.new(:connection => connection, :selenium_browser_start_command => selenium_browser_start_command)
54
54
  stub(runner).driver {driver}
55
55
  stub(driver).session_id {"DEADBEEF"}
56
56
 
57
57
  Runner.register(runner)
58
- runner.suite_id.should == suite_id
58
+ runner.session_id.should == session_id
59
59
  end
60
60
 
61
- it "finalizes the Runner that has the suite_id and keeps the Runner in memory" do
62
- mock(driver).stop
61
+ it "finalizes the Runner that has the session_id and keeps the Runner in memory" do
62
+ mock.proxy(driver).stop
63
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
64
+ Runner.find(session_id).should == runner
65
+ Runner.finalize(session_id, "Browser output")
66
+ Runner.find(session_id).should == runner
67
67
  end
68
68
  end
69
69
 
70
- describe "when there is not a runner for the passed in suite_id" do
70
+ describe "when there is not a runner for the passed in session_id" do
71
71
  it "does nothing" do
72
72
  lambda do
73
73
  Runner.finalize("6666666", "nothing happens")
@@ -84,21 +84,27 @@ module JsTestCore
84
84
  stub(connection).send_body
85
85
  end
86
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
-
87
+ it "responds with a 200 and the session_id" do
92
88
  mock(connection).send_head
93
- mock(connection).send_body("suite_id=#{suite_id}")
89
+ mock(connection).send_body("session_id=#{session_id}")
90
+ connection.receive_data("POST /runners HTTP/1.1\r\nHost: _\r\nContent-Length: #{body.length}\r\n\r\n#{body}")
91
+ end
92
+
93
+ it "starts the Selenium Driver, creates a SessionID cookie, and opens the spec page" do
94
+ mock(driver).start
95
+ stub(driver).session_id {session_id}
96
+ mock(driver).create_cookie("session_id=#{session_id}")
97
+ mock(driver).open("/")
98
+ mock(driver).open("/specs")
99
+
100
+ mock(Selenium::SeleniumDriver).new('localhost', 4444, selenium_browser_start_command, 'http://0.0.0.0:8080') do
101
+ driver
102
+ end
94
103
  connection.receive_data("POST /runners HTTP/1.1\r\nHost: _\r\nContent-Length: #{body.length}\r\n\r\n#{body}")
95
104
  end
96
105
 
97
106
  describe "when a selenium_host parameter is passed into the request" do
98
107
  before do
99
- stub(driver).start
100
- stub(driver).open
101
- stub(driver).session_id {suite_id}
102
108
  body << "&selenium_host=another-machine"
103
109
  end
104
110
 
@@ -112,9 +118,6 @@ module JsTestCore
112
118
 
113
119
  describe "when a selenium_host parameter is not passed into the request" do
114
120
  before do
115
- stub(driver).start
116
- stub(driver).open
117
- stub(driver).session_id {suite_id}
118
121
  body << "&selenium_host="
119
122
  end
120
123
 
@@ -128,9 +131,6 @@ module JsTestCore
128
131
 
129
132
  describe "when a selenium_port parameter is passed into the request" do
130
133
  before do
131
- stub(driver).start
132
- stub(driver).open
133
- stub(driver).session_id {suite_id}
134
134
  body << "&selenium_port=4000"
135
135
  end
136
136
 
@@ -144,9 +144,6 @@ module JsTestCore
144
144
 
145
145
  describe "when a selenium_port parameter is not passed into the request" do
146
146
  before do
147
- stub(driver).start
148
- stub(driver).open
149
- stub(driver).session_id {suite_id}
150
147
  body << "&selenium_port="
151
148
  end
152
149
 
@@ -159,13 +156,15 @@ module JsTestCore
159
156
  end
160
157
 
161
158
  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
159
+ it "runs Selenium with the passed in host and part to run the specified spec session in Firefox" do
163
160
  mock(Selenium::SeleniumDriver).new('localhost', 4444, selenium_browser_start_command, 'http://another-host:8080') do
164
161
  driver
165
162
  end
166
163
  mock(driver).start
167
- mock(driver).open("http://another-host:8080/specs/subdir")
168
- mock(driver).session_id {suite_id}.at_least(1)
164
+ stub(driver).create_cookie
165
+ mock(driver).open("/")
166
+ mock(driver).open("/specs/subdir")
167
+ mock(driver).session_id {session_id}.at_least(1)
169
168
 
170
169
  body << "&spec_url=http://another-host:8080/specs/subdir"
171
170
  connection.receive_data("POST /runners HTTP/1.1\r\nHost: _\r\nContent-Length: #{body.length}\r\n\r\n#{body}")
@@ -179,10 +178,12 @@ module JsTestCore
179
178
  end
180
179
  end
181
180
 
182
- it "uses Selenium to run the entire spec suite in Firefox" do
181
+ it "uses Selenium to run the entire spec session in Firefox" do
183
182
  mock(driver).start
184
- mock(driver).open("http://0.0.0.0:8080/specs")
185
- mock(driver).session_id {suite_id}.at_least(1)
183
+ stub(driver).create_cookie
184
+ mock(driver).open("/")
185
+ mock(driver).open("/specs")
186
+ mock(driver).session_id {session_id}.at_least(1)
186
187
 
187
188
  body << "&spec_url="
188
189
  connection.receive_data("POST /runners HTTP/1.1\r\nHost: _\r\nContent-Length: #{body.length}\r\n\r\n#{body}")
@@ -198,16 +199,12 @@ module JsTestCore
198
199
  stub(connection).send_head
199
200
  stub(connection).send_body
200
201
 
201
- stub(driver).start
202
- stub(driver).open
203
- stub(driver).session_id {suite_id}
204
-
205
202
  mock(connection).send_head
206
- mock(connection).send_body("suite_id=#{suite_id}")
203
+ mock(connection).send_body("session_id=#{session_id}")
207
204
 
208
- Runner.find(suite_id).should be_nil
205
+ Runner.find(session_id).should be_nil
209
206
  connection.receive_data("POST /runners/firefox HTTP/1.1\r\nHost: _\r\n\r\n")
210
- runner = Runner.find(suite_id)
207
+ runner = Runner.find(session_id)
211
208
  runner.class.should == Runner
212
209
  runner.driver.should == driver
213
210
  end
@@ -221,45 +218,68 @@ module JsTestCore
221
218
  stub(connection).send_head
222
219
  stub(connection).send_body
223
220
 
224
- stub(driver).start
225
- stub(driver).open
226
- stub(driver).session_id {suite_id}
227
-
228
221
  mock(connection).send_head
229
- mock(connection).send_body("suite_id=#{suite_id}")
222
+ mock(connection).send_body("session_id=#{session_id}")
230
223
 
231
- Runner.find(suite_id).should be_nil
224
+ Runner.find(session_id).should be_nil
232
225
  connection.receive_data("POST /runners/iexplore HTTP/1.1\r\nHost: _\r\n\r\n")
233
- runner = Runner.find(suite_id)
226
+ runner = Runner.find(session_id)
234
227
  runner.class.should == Runner
235
228
  runner.driver.should == driver
236
229
  end
237
230
  end
238
231
 
232
+ describe "#running?" do
233
+ before_with_selenium_browser_start_command
234
+ context "when the driver#session_started? is true" do
235
+ it "returns true" do
236
+ create_runner_connection = create_connection
237
+ stub(create_runner_connection).send_head
238
+ stub(create_runner_connection).send_body
239
+ create_runner_connection.receive_data("POST /runners HTTP/1.1\r\nHost: _\r\nContent-Length: #{body.length}\r\n\r\n#{body}")
240
+
241
+ runner = Resources::Runner.find(session_id)
242
+ runner.driver.session_started?.should be_true
243
+ runner.should be_running
244
+ end
245
+ end
246
+
247
+ context "when the driver#session_started? is false" do
248
+ it "returns false" do
249
+ create_runner_connection = create_connection
250
+ stub(create_runner_connection).send_head
251
+ stub(create_runner_connection).send_body
252
+ create_runner_connection.receive_data("POST /runners HTTP/1.1\r\nHost: _\r\nContent-Length: #{body.length}\r\n\r\n#{body}")
253
+
254
+ runner = Resources::Runner.find(session_id)
255
+ runner.driver.stop
256
+ runner.driver.session_started?.should be_false
257
+ runner.should_not be_running
258
+ end
259
+ end
260
+ end
261
+
239
262
  describe "#finalize" do
240
263
  attr_reader :runner
241
264
  before_with_selenium_browser_start_command
242
265
  before do
243
- stub(driver).start
244
- stub(driver).open
245
- stub(driver).session_id {suite_id}
246
-
247
266
  create_runner_connection = create_connection
248
267
  stub(create_runner_connection).send_head
249
268
  stub(create_runner_connection).send_body
250
269
  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
270
+ @runner = Resources::Runner.find(session_id)
271
+ mock.proxy(driver).stop
253
272
  end
254
273
 
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
274
+ it "kills the browser and stores the #session_run_result" do
275
+ session_run_result = "The session run result"
276
+ runner.finalize(session_run_result)
277
+ runner.session_run_result.should == session_run_result
259
278
  end
260
279
 
261
- it "causes #running? to be false" do
262
- runner.finalize("")
280
+ it "sets #session_run_result" do
281
+ runner.finalize("the result")
282
+ runner.session_run_result.should == "the result"
263
283
  end
264
284
 
265
285
  context "when passed an empty string" do
@@ -2,26 +2,27 @@ require File.expand_path("#{File.dirname(__FILE__)}/../../unit_spec_helper")
2
2
 
3
3
  module JsTestCore
4
4
  module Resources
5
- describe SuiteFinish do
5
+ describe SessionFinish do
6
6
  attr_reader :stdout
7
7
  before do
8
8
  @stdout = StringIO.new
9
- SuiteFinish.const_set(:STDOUT, stdout)
9
+ SessionFinish.const_set(:STDOUT, stdout)
10
10
  end
11
11
 
12
12
  after do
13
- SuiteFinish.__send__(:remove_const, :STDOUT)
13
+ SessionFinish.__send__(:remove_const, :STDOUT)
14
14
  end
15
15
 
16
- describe "POST /suites/:suite_id/finish" do
17
- context "when :suite_id == 'user'" do
16
+
17
+ describe "POST /session/finish" do
18
+ context "when session_id cookie is not set" do
18
19
  it "writes the body of the request to stdout" do
19
20
  stub(connection).send_head
20
21
  stub(connection).send_body
21
22
 
22
23
  text = "The text in the POST body"
23
24
  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
+ connection.receive_data("POST /session/finish HTTP/1.1\r\nHost: _\r\nContent-Length: #{body.length}\r\n\r\n#{body}")
25
26
  stdout.string.should == "#{text}\n"
26
27
  end
27
28
 
@@ -31,22 +32,18 @@ module JsTestCore
31
32
 
32
33
  mock(connection).send_head
33
34
  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
+ connection.receive_data("POST /session/finish HTTP/1.1\r\nHost: _\r\nContent-Length: #{body.length}\r\n\r\n#{body}")
35
36
  end
36
37
  end
37
38
 
38
- context "when :suite_id != 'user'" do
39
- attr_reader :suite_id, :driver
39
+ context "when session_id cookie is set'" do
40
+ attr_reader :session_id, :driver
40
41
  before do
41
- @suite_id = "DEADBEEF"
42
- @driver = "Selenium Driver"
42
+ @session_id = FakeSeleniumDriver::SESSION_ID
43
+ @driver = FakeSeleniumDriver.new
43
44
  stub(Selenium::SeleniumDriver).new('localhost', 4444, '*firefox', 'http://0.0.0.0:8080') do
44
45
  driver
45
46
  end
46
- stub(driver).start
47
- stub(driver).open
48
- stub(driver).session_id {suite_id}
49
- stub(Thread).start.yields
50
47
 
51
48
  firefox_connection = Thin::JsTestCoreConnection.new(Guid.new)
52
49
  stub(firefox_connection).send_head
@@ -60,11 +57,11 @@ module JsTestCore
60
57
  body = "text=#{text}"
61
58
  stub(connection).send_head
62
59
  stub(connection).send_body
63
- mock.proxy(Runner).finalize(suite_id.to_s, text)
60
+ mock.proxy(Runner).finalize(session_id.to_s, text)
64
61
  mock(driver).stop
65
62
  stub(connection).close_connection
66
63
 
67
- connection.receive_data("POST /suites/#{suite_id}/finish HTTP/1.1\r\nHost: _\r\nContent-Length: #{body.length}\r\n\r\n#{body}")
64
+ connection.receive_data("POST /session/finish HTTP/1.1\r\nCookie: session_id=#{session_id}\r\nHost: _\r\nContent-Length: #{body.length}\r\n\r\n#{body}")
68
65
  end
69
66
 
70
67
  it "responds with a blank body" do
@@ -73,7 +70,7 @@ module JsTestCore
73
70
 
74
71
  mock(connection).send_head
75
72
  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")
73
+ connection.receive_data("POST /session/finish HTTP/1.1\r\nCookie: session_id=#{session_id}\r\nHost: _\r\nContent-Length: 0\r\n\r\n")
77
74
  end
78
75
  end
79
76
  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 Session do
6
+ describe "GET /sessions/:session_id" do
7
+ attr_reader :driver, :session_id
8
+
9
+ context "when there is no Runner with the :session_id" do
10
+ it "responds with a 404" do
11
+ session_id = "invalid_session_id"
12
+ Runner.find(session_id).should be_nil
13
+
14
+ mock(connection).send_head(404)
15
+ mock(connection).send_body("")
16
+
17
+ connection.receive_data("GET /sessions/#{session_id} HTTP/1.1\r\nHost: _\r\n\r\n")
18
+ end
19
+ end
20
+
21
+ context "when there is a Runner with the :session_id" do
22
+ attr_reader :session_runner
23
+ before do
24
+ @driver = FakeSeleniumDriver.new
25
+ @session_id = FakeSeleniumDriver::SESSION_ID
26
+ stub(Selenium::SeleniumDriver).new('localhost', 4444, '*firefox', 'http://0.0.0.0:8080') do
27
+ driver
28
+ end
29
+
30
+ connection_that_starts_firefox = create_connection
31
+ stub(connection_that_starts_firefox).send_head
32
+ stub(connection_that_starts_firefox).send_body
33
+ connection_that_starts_firefox.receive_data("POST /runners/firefox HTTP/1.1\r\nHost: _\r\nContent-Length: 0\r\n\r\n")
34
+ @session_runner = Runner.find(session_id)
35
+ session_runner.should be_running
36
+ end
37
+
38
+ context "when a Runner with the :session_id is running" do
39
+ it "responds with a 200 and status=running" do
40
+ mock(connection).send_head
41
+ mock(connection).send_body("status=#{Resources::Session::RUNNING}")
42
+
43
+ connection.receive_data("GET /sessions/#{session_id} HTTP/1.1\r\nHost: _\r\n\r\n")
44
+ end
45
+ end
46
+
47
+ context "when a Runner with the :session_id has completed" do
48
+ context "when the session has a status of 'success'" do
49
+ before do
50
+ session_runner.finalize("")
51
+ session_runner.should be_successful
52
+ end
53
+
54
+ it "responds with a 200 and status=success" do
55
+ mock(connection).send_head
56
+ mock(connection).send_body("status=#{Resources::Session::SUCCESSFUL_COMPLETION}")
57
+
58
+ connection.receive_data("GET /sessions/#{session_id} HTTP/1.1\r\nHost: _\r\n\r\n")
59
+ end
60
+ end
61
+
62
+ context "when the session has a status of 'failure'" do
63
+ attr_reader :reason
64
+ before do
65
+ @reason = "Failure stuff"
66
+ session_runner.finalize(reason)
67
+ session_runner.should be_failed
68
+ end
69
+
70
+ it "responds with a 200 and status=failure and reason" do
71
+ mock(connection).send_head
72
+ mock(connection).send_body("status=#{Resources::Session::FAILURE_COMPLETION}&reason=#{reason}")
73
+
74
+ connection.receive_data("GET /sessions/#{session_id} HTTP/1.1\r\nHost: _\r\n\r\n")
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
@@ -90,10 +90,10 @@ module JsTestCore
90
90
 
91
91
  describe "GET /" do
92
92
  context "when WebRoot.dispatch_specs has been invoked" do
93
- it "redirects to /specs" do
93
+ it "renders a home page" do
94
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>")
95
+ mock(connection).send_head(200, :Location => '/specs')
96
+ mock(connection).send_body(is_a(String))
97
97
 
98
98
  connection.receive_data("GET / HTTP/1.1\r\nHost: _\r\n\r\n")
99
99
  end