screw-unit-server 0.3.0 → 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 (124) hide show
  1. data/CHANGES +23 -1
  2. data/README.markdown +10 -3
  3. data/Rakefile +27 -55
  4. data/VERSION.yml +4 -0
  5. data/bin/screw_unit_server +14 -4
  6. data/core/CHANGES +10 -0
  7. data/core/EXAMPLE.html +4 -4
  8. data/core/README.markdown +7 -7
  9. data/core/example/models/man.js +2 -2
  10. data/core/example/spec/suite.html +1 -1
  11. data/core/lib/jquery-1.3.2.js +4376 -0
  12. data/core/lib/jquery.fn.js +2 -1
  13. data/core/lib/jquery.print.js +13 -12
  14. data/core/lib/screw.behaviors.js +11 -9
  15. data/core/lib/screw.builder.js +26 -11
  16. data/core/lib/screw.css +2 -2
  17. data/core/lib/screw.events.js +11 -4
  18. data/core/lib/screw.matchers.js +192 -13
  19. data/core/spec/behaviors_spec.js +11 -1
  20. data/core/spec/matchers_spec.js +288 -9
  21. data/core/spec/print_spec.js +47 -8
  22. data/core/spec/suite.html +2 -1
  23. data/core/spec/with_screw_context_spec.js +9 -0
  24. data/lib/screw_unit.rb +13 -16
  25. data/lib/screw_unit/representations.rb +2 -0
  26. data/lib/screw_unit/representations/spec.html.rb +117 -0
  27. data/spec/functional/functional_spec.rb +14 -3
  28. data/spec/functional/functional_spec_helper.rb +22 -34
  29. data/spec/functional/functional_spec_server_starter.rb +68 -0
  30. data/spec/unit/js_test_core/specs/spec_file_spec.rb +45 -20
  31. data/spec/unit/unit_spec_helper.rb +24 -93
  32. data/vendor/js-test-core/CHANGES +19 -0
  33. data/vendor/js-test-core/Rakefile +2 -1
  34. data/vendor/js-test-core/lib/js_test_core.rb +26 -10
  35. data/vendor/js-test-core/lib/js_test_core/app.rb +12 -0
  36. data/vendor/js-test-core/lib/js_test_core/client.rb +97 -18
  37. data/vendor/js-test-core/lib/js_test_core/configuration.rb +35 -0
  38. data/vendor/js-test-core/lib/js_test_core/extensions.rb +3 -0
  39. data/vendor/js-test-core/lib/js_test_core/extensions/selenium/client/driver.rb +7 -0
  40. data/vendor/js-test-core/lib/js_test_core/extensions/time.rb +6 -0
  41. data/vendor/js-test-core/lib/js_test_core/models.rb +8 -0
  42. data/vendor/js-test-core/lib/js_test_core/models/selenium_session.rb +80 -0
  43. data/vendor/js-test-core/lib/js_test_core/representations.rb +11 -0
  44. data/vendor/js-test-core/lib/js_test_core/representations/dir.html.rb +24 -0
  45. data/vendor/js-test-core/lib/js_test_core/representations/not_found.html.rb +15 -0
  46. data/vendor/js-test-core/lib/js_test_core/representations/page.html.rb +41 -0
  47. data/vendor/js-test-core/lib/js_test_core/representations/spec.html.rb +24 -0
  48. data/vendor/js-test-core/lib/js_test_core/resources.rb +13 -8
  49. data/vendor/js-test-core/lib/js_test_core/resources/core_file.rb +19 -0
  50. data/vendor/js-test-core/lib/js_test_core/resources/file.rb +44 -14
  51. data/vendor/js-test-core/lib/js_test_core/resources/implementations_deprecation.rb +12 -0
  52. data/vendor/js-test-core/lib/js_test_core/resources/not_found.rb +35 -0
  53. data/vendor/js-test-core/lib/js_test_core/resources/resource.rb +16 -0
  54. data/vendor/js-test-core/lib/js_test_core/resources/selenium_session.rb +104 -0
  55. data/vendor/js-test-core/lib/js_test_core/resources/spec_file.rb +63 -0
  56. data/vendor/js-test-core/lib/js_test_core/resources/web_root.rb +5 -56
  57. data/vendor/js-test-core/lib/js_test_core/selenium_server_configuration.rb +48 -0
  58. data/vendor/js-test-core/spec/example_core/subdir/SubDirFile.js +0 -0
  59. data/vendor/js-test-core/spec/example_public/javascripts/large_file.js +59 -0
  60. data/vendor/js-test-core/spec/example_public/javascripts/subdir/bar.js +1 -0
  61. data/vendor/js-test-core/spec/example_specs/custom_dir_and_suite/passing_spec.js +6 -0
  62. data/vendor/js-test-core/spec/example_specs/custom_suite.html +8 -0
  63. data/vendor/js-test-core/spec/example_specs/foo/failing_spec.js +1 -1
  64. data/vendor/js-test-core/spec/example_specs/foo/passing_spec.js +1 -1
  65. data/vendor/js-test-core/spec/spec_helpers/be_http.rb +32 -0
  66. data/vendor/js-test-core/spec/spec_helpers/example_group.rb +36 -0
  67. data/vendor/js-test-core/spec/spec_helpers/fake_selenium_driver.rb +27 -0
  68. data/vendor/js-test-core/spec/spec_helpers/show_test_exceptions.rb +22 -0
  69. data/vendor/js-test-core/spec/unit/js_test_core/client_spec.rb +140 -85
  70. data/vendor/js-test-core/spec/unit/js_test_core/configuration_spec.rb +44 -0
  71. data/vendor/js-test-core/spec/unit/js_test_core/models/selenium_session_spec.rb +85 -0
  72. data/vendor/js-test-core/spec/unit/js_test_core/resources/core_file_spec.rb +60 -0
  73. data/vendor/js-test-core/spec/unit/js_test_core/resources/file_spec.rb +61 -68
  74. data/vendor/js-test-core/spec/unit/js_test_core/resources/implementations_deprecation_spec.rb +18 -0
  75. data/vendor/js-test-core/spec/unit/js_test_core/resources/not_found_spec.rb +51 -0
  76. data/vendor/js-test-core/spec/unit/js_test_core/resources/selenium_session_spec.rb +362 -0
  77. data/vendor/js-test-core/spec/unit/js_test_core/resources/spec_file_spec.rb +120 -0
  78. data/vendor/js-test-core/spec/unit/js_test_core/resources/web_root_spec.rb +14 -89
  79. data/vendor/js-test-core/spec/unit/js_test_core/selenium_server_configuration_spec.rb +49 -0
  80. data/vendor/js-test-core/spec/unit/unit_spec_helper.rb +16 -113
  81. data/vendor/js-test-core/vendor/lucky-luciano/README.markdown +7 -0
  82. data/vendor/js-test-core/vendor/lucky-luciano/lib/lucky_luciano.rb +4 -0
  83. data/vendor/js-test-core/vendor/lucky-luciano/lib/lucky_luciano/resource.rb +135 -0
  84. data/vendor/js-test-core/vendor/lucky-luciano/lib/lucky_luciano/rspec.rb +4 -0
  85. data/vendor/js-test-core/vendor/lucky-luciano/lib/lucky_luciano/rspec/be_http.rb +32 -0
  86. data/vendor/js-test-core/vendor/lucky-luciano/spec/lucky_luciano/resource_spec.rb +231 -0
  87. data/vendor/js-test-core/vendor/lucky-luciano/spec/spec_helper.rb +48 -0
  88. data/vendor/js-test-core/vendor/lucky-luciano/spec/spec_suite.rb +4 -0
  89. metadata +143 -129
  90. data/core/TODO +0 -2
  91. data/core/lib/jquery-1.2.3.js +0 -3408
  92. data/core/lib/screw.assets.js +0 -36
  93. data/core/lib/screw.server.js +0 -21
  94. data/lib/screw_unit/resources.rb +0 -2
  95. data/lib/screw_unit/resources/spec.rb +0 -37
  96. data/spec/unit/js_test_core/specs/spec_dir_spec.rb +0 -43
  97. data/vendor/js-test-core/lib/js_test_core/rack.rb +0 -2
  98. data/vendor/js-test-core/lib/js_test_core/rack/commonlogger.rb +0 -5
  99. data/vendor/js-test-core/lib/js_test_core/rails_server.rb +0 -22
  100. data/vendor/js-test-core/lib/js_test_core/resources/dir.rb +0 -52
  101. data/vendor/js-test-core/lib/js_test_core/resources/file_not_found.rb +0 -15
  102. data/vendor/js-test-core/lib/js_test_core/resources/runners.rb +0 -15
  103. data/vendor/js-test-core/lib/js_test_core/resources/runners/firefox_runner.rb +0 -75
  104. data/vendor/js-test-core/lib/js_test_core/resources/specs/spec_dir.rb +0 -50
  105. data/vendor/js-test-core/lib/js_test_core/resources/specs/spec_file.rb +0 -17
  106. data/vendor/js-test-core/lib/js_test_core/resources/suite.rb +0 -24
  107. data/vendor/js-test-core/lib/js_test_core/resources/suite_finish.rb +0 -19
  108. data/vendor/js-test-core/lib/js_test_core/selenium.rb +0 -2
  109. data/vendor/js-test-core/lib/js_test_core/selenium/selenium_driver.rb +0 -5
  110. data/vendor/js-test-core/lib/js_test_core/server.rb +0 -111
  111. data/vendor/js-test-core/lib/js_test_core/thin.rb +0 -3
  112. data/vendor/js-test-core/lib/js_test_core/thin/backends/js_test_core_server.rb +0 -9
  113. data/vendor/js-test-core/lib/js_test_core/thin/js_test_core_connection.rb +0 -42
  114. data/vendor/js-test-core/spec/unit/js_test_core/rails_server_spec.rb +0 -45
  115. data/vendor/js-test-core/spec/unit/js_test_core/resources/dir_spec.rb +0 -42
  116. data/vendor/js-test-core/spec/unit/js_test_core/resources/file_not_found_spec.rb +0 -26
  117. data/vendor/js-test-core/spec/unit/js_test_core/resources/runner_spec.rb +0 -24
  118. data/vendor/js-test-core/spec/unit/js_test_core/resources/runners/firefox_runner_spec.rb +0 -197
  119. data/vendor/js-test-core/spec/unit/js_test_core/resources/specs/spec_dir_spec.rb +0 -79
  120. data/vendor/js-test-core/spec/unit/js_test_core/resources/specs/spec_file_spec.rb +0 -42
  121. data/vendor/js-test-core/spec/unit/js_test_core/resources/suite_finish_spec.rb +0 -94
  122. data/vendor/js-test-core/spec/unit/js_test_core/resources/suite_spec.rb +0 -44
  123. data/vendor/js-test-core/spec/unit/js_test_core/server_spec.rb +0 -131
  124. data/vendor/js-test-core/spec/unit/thin/js_test_core_connection_spec.rb +0 -92
@@ -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,84 +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
- attr_reader :request, :file
7
-
8
- before do
9
- WebRoot.dispatch_specs
10
- stub(EventMachine).send_data
11
- stub(EventMachine).close_connection
12
- @file = Resources::File.new(absolute_path, relative_path)
13
- @request = create_request('get', relative_path)
14
- end
15
-
16
- def absolute_path
17
- "#{spec_root_path}/failing_spec.js"
18
- end
19
-
20
- def relative_path
21
- "/specs/failing_spec.js"
22
- end
23
-
24
- describe "#absolute_path" do
25
- it "returns the absolute path passed into the initializer" do
26
- file.absolute_path.should == absolute_path
27
- end
28
- end
29
-
30
- describe "#relative_path" do
31
- it "returns the relative path passed into the initializer" do
32
- file.relative_path.should == relative_path
33
- end
34
- end
35
-
36
- describe "#get" do
37
- attr_reader :response
38
- before do
39
- @response = Rack::Response.new
40
- end
41
-
42
- it "returns the contents of the file" do
43
- file.get(request, response)
44
- response.body.should == ::File.read(absolute_path)
6
+ describe "Files" do
7
+ describe "GET /stylesheets/example.css" do
8
+ it "returns the example.css file content as a css file" do
9
+ path = "#{public_path}/stylesheets/example.css"
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
+ end
45
21
  end
46
22
 
47
- describe "when File has an extension" do
48
- describe '.js' do
49
- it "sets Content-Type to text/javascript" do
50
- file.get(request,response)
51
- response.content_type.should == "text/javascript"
52
- end
23
+ describe "GET /javascripts/foo.js" do
24
+ it "returns the foo.js file content as a javascript file" do
25
+ path = "#{public_path}/javascripts/foo.js"
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
+ )
53
36
  end
37
+ end
54
38
 
55
- describe '.css' do
56
- it "sets Content-Type to text/css" do
57
- file.get(request, response)
58
- response.content_type.should == "text/css"
59
- end
60
-
61
- def absolute_path
62
- "#{core_path}/JsTestCore.css"
63
- end
64
-
65
- def relative_path
66
- "/core/JsTestCore.css"
67
- end
39
+ describe "GET /javascripts/subdir/bar.js - Subdirectory" do
40
+ it "returns the subdir/bar.js file content as a javascript file" do
41
+ path = "#{public_path}/javascripts/subdir/bar.js"
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
+ )
68
52
  end
69
53
  end
70
54
  end
71
55
 
72
- describe "==" do
73
- it "returns true when passed a file with the same absolute and relative paths" do
74
- file.should == Resources::File.new(absolute_path, relative_path)
75
- end
76
-
77
- it "returns false when passed a file with a different absolute or relative path" do
78
- file.should_not == Resources::File.new(absolute_path, "bogus")
79
- file.should_not == Resources::File.new("bogus", 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
80
66
  end
81
67
 
82
- it "when passed a Dir, returns false because File is not a Dir" do
83
- file.should_not == Resources::Dir.new(absolute_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
84
77
  end
85
78
  end
86
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
@@ -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