btakita-screw-unit-server 0.3.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (141) hide show
  1. data/CHANGES +44 -1
  2. data/README.markdown +17 -5
  3. data/Rakefile +28 -55
  4. data/VERSION.yml +5 -0
  5. data/bin/screw_unit_server +8 -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 +12 -17
  25. data/spec/functional/functional_spec.rb +15 -4
  26. data/spec/functional/functional_spec_helper.rb +22 -35
  27. data/spec/functional/functional_spec_server_starter.rb +68 -0
  28. data/spec/spec_suite.rb +0 -1
  29. data/standalone.ru +3 -0
  30. data/vendor/js-test-core/CHANGES +22 -0
  31. data/vendor/js-test-core/README +4 -10
  32. data/vendor/js-test-core/Rakefile +2 -1
  33. data/vendor/js-test-core/{spec/example_core/JsTestCore.css → bin/js-test-client} +0 -0
  34. data/vendor/js-test-core/bin/js-test-server +6 -0
  35. data/vendor/js-test-core/lib/js_test_core.rb +27 -19
  36. data/vendor/js-test-core/lib/js_test_core/app.rb +11 -0
  37. data/vendor/js-test-core/lib/js_test_core/client.rb +125 -36
  38. data/vendor/js-test-core/lib/js_test_core/configuration.rb +65 -0
  39. data/vendor/js-test-core/lib/js_test_core/representations.rb +13 -0
  40. data/vendor/js-test-core/lib/js_test_core/representations/dir.html.rb +25 -0
  41. data/vendor/js-test-core/lib/js_test_core/representations/frameworks.rb +3 -0
  42. data/vendor/js-test-core/lib/js_test_core/representations/not_found.html.rb +16 -0
  43. data/vendor/js-test-core/lib/js_test_core/representations/page.html.rb +41 -0
  44. data/vendor/js-test-core/lib/js_test_core/representations/suite.html.rb +57 -0
  45. data/vendor/js-test-core/lib/js_test_core/representations/suites.rb +3 -0
  46. data/vendor/js-test-core/lib/js_test_core/representations/suites/screw_unit.html.rb +81 -0
  47. data/vendor/js-test-core/lib/js_test_core/resources.rb +12 -8
  48. data/vendor/js-test-core/lib/js_test_core/resources/core_file.rb +19 -0
  49. data/vendor/js-test-core/lib/js_test_core/resources/file.rb +43 -13
  50. data/vendor/js-test-core/lib/js_test_core/resources/implementations_deprecation.rb +12 -0
  51. data/vendor/js-test-core/lib/js_test_core/resources/not_found.rb +28 -0
  52. data/vendor/js-test-core/lib/js_test_core/resources/resource.rb +16 -0
  53. data/vendor/js-test-core/lib/js_test_core/resources/spec_file.rb +51 -0
  54. data/vendor/js-test-core/lib/js_test_core/resources/web_root.rb +7 -54
  55. data/vendor/js-test-core/lib/js_test_core/server.rb +65 -92
  56. data/vendor/js-test-core/public/js_test_server.js +541 -0
  57. data/vendor/js-test-core/spec/{example_core/JsTestCore.js → example_framework/JsTestCore.css} +0 -0
  58. data/vendor/js-test-core/spec/{example_public/favicon.ico → example_framework/JsTestCore.js} +0 -0
  59. data/vendor/js-test-core/spec/{example_public/robots.txt → example_framework/subdir/SubDirFile.js} +0 -0
  60. data/vendor/js-test-core/spec/example_root/favicon.ico +0 -0
  61. data/vendor/js-test-core/spec/{example_public → example_root}/javascripts/foo.js +1 -1
  62. data/vendor/js-test-core/spec/example_root/javascripts/large_file.js +59 -0
  63. data/vendor/js-test-core/spec/example_root/javascripts/subdir/bar.js +1 -0
  64. data/vendor/js-test-core/spec/example_root/robots.txt +0 -0
  65. data/vendor/js-test-core/spec/{example_public → example_root}/stylesheets/example.css +0 -0
  66. data/vendor/js-test-core/spec/example_spec/custom_dir_and_suite/passing_spec.js +8 -0
  67. data/vendor/js-test-core/spec/example_spec/custom_suite.html +8 -0
  68. data/vendor/js-test-core/spec/example_spec/failing_spec.js +7 -0
  69. data/vendor/js-test-core/spec/example_spec/foo/failing_spec.js +8 -0
  70. data/vendor/js-test-core/spec/example_spec/foo/passing_spec.js +8 -0
  71. data/vendor/js-test-core/spec/example_spec/passing_spec.js +8 -0
  72. data/vendor/js-test-core/spec/functional/functional_spec.rb +25 -0
  73. data/vendor/js-test-core/spec/functional/functional_spec_helper.rb +42 -0
  74. data/vendor/js-test-core/spec/functional/functional_spec_server_starter.rb +77 -0
  75. data/vendor/js-test-core/spec/functional_suite.rb +10 -0
  76. data/vendor/js-test-core/spec/spec_helpers/be_http.rb +32 -0
  77. data/vendor/js-test-core/spec/spec_helpers/example_group.rb +36 -0
  78. data/vendor/js-test-core/spec/spec_helpers/fake_selenium_driver.rb +16 -0
  79. data/vendor/js-test-core/spec/spec_helpers/show_test_exceptions.rb +22 -0
  80. data/vendor/js-test-core/spec/spec_suite.rb +2 -1
  81. data/vendor/js-test-core/spec/unit/js_test_core/client_spec.rb +153 -94
  82. data/vendor/js-test-core/spec/unit/js_test_core/configuration_spec.rb +50 -0
  83. data/vendor/js-test-core/spec/unit/js_test_core/resources/core_file_spec.rb +60 -0
  84. data/vendor/js-test-core/spec/unit/js_test_core/resources/file_spec.rb +61 -68
  85. data/vendor/js-test-core/spec/unit/js_test_core/resources/implementations_deprecation_spec.rb +18 -0
  86. data/vendor/js-test-core/spec/unit/js_test_core/resources/not_found_spec.rb +51 -0
  87. data/vendor/js-test-core/spec/unit/js_test_core/resources/spec_file_spec.rb +149 -0
  88. data/vendor/js-test-core/spec/unit/js_test_core/resources/web_root_spec.rb +14 -89
  89. data/vendor/js-test-core/spec/unit/js_test_core/server_spec.rb +41 -106
  90. data/vendor/js-test-core/spec/unit/unit_spec_helper.rb +19 -114
  91. data/vendor/js-test-core/standalone.ru +1 -0
  92. data/vendor/js-test-core/vendor/lucky-luciano/README.markdown +77 -0
  93. data/vendor/js-test-core/vendor/lucky-luciano/lib/lucky_luciano.rb +5 -0
  94. data/vendor/js-test-core/vendor/lucky-luciano/lib/lucky_luciano/resource.rb +142 -0
  95. data/vendor/js-test-core/vendor/lucky-luciano/lib/lucky_luciano/resource/path.rb +24 -0
  96. data/vendor/js-test-core/vendor/lucky-luciano/lib/lucky_luciano/rspec.rb +4 -0
  97. data/vendor/js-test-core/vendor/lucky-luciano/lib/lucky_luciano/rspec/be_http.rb +32 -0
  98. data/vendor/js-test-core/vendor/lucky-luciano/spec/lucky_luciano/resource_spec.rb +276 -0
  99. data/vendor/js-test-core/vendor/lucky-luciano/spec/spec_helper.rb +48 -0
  100. data/vendor/js-test-core/vendor/lucky-luciano/spec/spec_suite.rb +4 -0
  101. data/vendor/js-test-core/vendor/lucky-luciano/syntax_ideas.txt +34 -0
  102. metadata +145 -130
  103. data/core/TODO +0 -2
  104. data/core/lib/jquery-1.2.3.js +0 -3408
  105. data/core/lib/screw.assets.js +0 -36
  106. data/core/lib/screw.server.js +0 -21
  107. data/lib/screw_unit/resources.rb +0 -2
  108. data/lib/screw_unit/resources/spec.rb +0 -37
  109. data/spec/unit/js_test_core/specs/spec_dir_spec.rb +0 -43
  110. data/spec/unit/js_test_core/specs/spec_file_spec.rb +0 -43
  111. data/spec/unit/unit_spec_helper.rb +0 -120
  112. data/spec/unit_suite.rb +0 -10
  113. data/vendor/js-test-core/lib/js_test_core/rack.rb +0 -2
  114. data/vendor/js-test-core/lib/js_test_core/rack/commonlogger.rb +0 -5
  115. data/vendor/js-test-core/lib/js_test_core/rails_server.rb +0 -22
  116. data/vendor/js-test-core/lib/js_test_core/resources/dir.rb +0 -52
  117. data/vendor/js-test-core/lib/js_test_core/resources/file_not_found.rb +0 -15
  118. data/vendor/js-test-core/lib/js_test_core/resources/runners.rb +0 -15
  119. data/vendor/js-test-core/lib/js_test_core/resources/runners/firefox_runner.rb +0 -75
  120. data/vendor/js-test-core/lib/js_test_core/resources/specs/spec_dir.rb +0 -50
  121. data/vendor/js-test-core/lib/js_test_core/resources/specs/spec_file.rb +0 -17
  122. data/vendor/js-test-core/lib/js_test_core/resources/suite.rb +0 -24
  123. data/vendor/js-test-core/lib/js_test_core/resources/suite_finish.rb +0 -19
  124. data/vendor/js-test-core/lib/js_test_core/selenium.rb +0 -2
  125. data/vendor/js-test-core/lib/js_test_core/selenium/selenium_driver.rb +0 -5
  126. data/vendor/js-test-core/lib/js_test_core/thin.rb +0 -3
  127. data/vendor/js-test-core/lib/js_test_core/thin/backends/js_test_core_server.rb +0 -9
  128. data/vendor/js-test-core/lib/js_test_core/thin/js_test_core_connection.rb +0 -42
  129. data/vendor/js-test-core/spec/example_specs/failing_spec.js +0 -5
  130. data/vendor/js-test-core/spec/example_specs/foo/failing_spec.js +0 -6
  131. data/vendor/js-test-core/spec/example_specs/foo/passing_spec.js +0 -6
  132. data/vendor/js-test-core/spec/unit/js_test_core/rails_server_spec.rb +0 -45
  133. data/vendor/js-test-core/spec/unit/js_test_core/resources/dir_spec.rb +0 -42
  134. data/vendor/js-test-core/spec/unit/js_test_core/resources/file_not_found_spec.rb +0 -26
  135. data/vendor/js-test-core/spec/unit/js_test_core/resources/runner_spec.rb +0 -24
  136. data/vendor/js-test-core/spec/unit/js_test_core/resources/runners/firefox_runner_spec.rb +0 -197
  137. data/vendor/js-test-core/spec/unit/js_test_core/resources/specs/spec_dir_spec.rb +0 -79
  138. data/vendor/js-test-core/spec/unit/js_test_core/resources/specs/spec_file_spec.rb +0 -42
  139. data/vendor/js-test-core/spec/unit/js_test_core/resources/suite_finish_spec.rb +0 -94
  140. data/vendor/js-test-core/spec/unit/js_test_core/resources/suite_spec.rb +0 -44
  141. data/vendor/js-test-core/spec/unit/thin/js_test_core_connection_spec.rb +0 -92
@@ -1,75 +0,0 @@
1
- module JsTestCore
2
- module Resources
3
- class Runners
4
- class FirefoxRunner
5
- class << self
6
- def resume(suite_id, text)
7
- if instances[suite_id]
8
- runner = instances.delete(suite_id)
9
- runner.finalize(text)
10
- end
11
- end
12
-
13
- def register_instance(runner)
14
- instances[runner.suite_id] = runner
15
- end
16
-
17
- protected
18
- def instances
19
- @instances ||= {}
20
- end
21
- end
22
-
23
- include FileUtils
24
- attr_reader :profile_dir, :connection, :driver, :response
25
-
26
- def initialize
27
- profile_base = "#{::Dir.tmpdir}/js_test_core/firefox"
28
- mkdir_p profile_base
29
- @profile_dir = "#{profile_base}/#{Time.now.to_i}"
30
- @connection = Server.connection
31
- end
32
-
33
- def post(request, response)
34
- @response = response
35
-
36
- spec_url = (request && request['spec_url']) ? request['spec_url'] : spec_suite_url
37
- parsed_spec_url = URI.parse(spec_url)
38
- selenium_port = (request['selenium_port'] || 4444).to_i
39
- @driver = Selenium::SeleniumDriver.new(
40
- request['selenium_host'] || 'localhost',
41
- selenium_port,
42
- '*firefox',
43
- "#{parsed_spec_url.scheme}://#{parsed_spec_url.host}:#{parsed_spec_url.port}"
44
- )
45
- begin
46
- driver.start
47
- rescue Errno::ECONNREFUSED => e
48
- raise Errno::ECONNREFUSED, "Cannot connect to Selenium Server on port #{selenium_port}. To start the selenium server, run `selenium`."
49
- end
50
- Thread.start do
51
- driver.open(spec_url)
52
- end
53
- response.status = 200
54
- FirefoxRunner.register_instance self
55
- end
56
-
57
- def finalize(text)
58
- driver.stop
59
- response.body = text
60
- connection.send_body(response)
61
- end
62
-
63
- def suite_id
64
- driver.session_id
65
- end
66
-
67
- protected
68
-
69
- def spec_suite_url
70
- "#{Server.root_url}/specs"
71
- end
72
- end
73
- end
74
- end
75
- end
@@ -1,50 +0,0 @@
1
- module JsTestCore
2
- module Resources
3
- module Specs
4
- class SpecDirSuperclass < ::JsTestCore::Resources::Dir
5
- def get(request, response)
6
- raise NotImplementedError, "#{self.class}#get needs to be implemented"
7
- end
8
- end
9
-
10
- class SpecDir < SpecDirSuperclass
11
- def spec_files
12
- glob("/**/*_spec.js")
13
- end
14
-
15
- def locate(name)
16
- if file = file(name)
17
- file
18
- elsif subdir = subdir(name)
19
- subdir
20
- elsif spec_file = spec_file(name)
21
- spec_file
22
- else
23
- base_path = "#{relative_path}/#{name}"
24
- raise "No file or directory found at #{base_path} or spec found at #{base_path}.js."
25
- end
26
- end
27
-
28
- protected
29
-
30
- def subdir(name)
31
- absolute_dir_path, relative_dir_path = determine_child_paths(name)
32
- if ::File.directory?(absolute_dir_path)
33
- SpecDir.new(absolute_dir_path, relative_dir_path)
34
- else
35
- nil
36
- end
37
- end
38
-
39
- def spec_file(name)
40
- absolute_file_path, relative_file_path = determine_child_paths("#{name}.js")
41
- if ::File.exists?(absolute_file_path) && !::File.directory?(absolute_file_path)
42
- SpecFile.new(absolute_file_path, relative_file_path)
43
- else
44
- nil
45
- end
46
- end
47
- end
48
- end
49
- end
50
- end
@@ -1,17 +0,0 @@
1
- module JsTestCore
2
- module Resources
3
- module Specs
4
- class SpecFileSuperclass < ::JsTestCore::Resources::File
5
- def get(request, response)
6
- raise NotImplementedError, "#{self.class}#get needs to be implemented"
7
- end
8
- end
9
-
10
- class SpecFile < SpecFileSuperclass
11
- def spec_files
12
- [self]
13
- end
14
- end
15
- end
16
- end
17
- end
@@ -1,24 +0,0 @@
1
- module JsTestCore
2
- module Resources
3
- class Suite
4
- class << self
5
- def locate(id)
6
- new id
7
- end
8
- end
9
-
10
- attr_reader :id
11
- def initialize(id)
12
- @id = id
13
- end
14
-
15
- def locate(name)
16
- if name == 'finish'
17
- SuiteFinish.new self
18
- else
19
- raise ArgumentError, "Invalid path: #{name}"
20
- end
21
- end
22
- end
23
- end
24
- end
@@ -1,19 +0,0 @@
1
- module JsTestCore
2
- module Resources
3
- class SuiteFinish
4
- attr_reader :suite
5
- def initialize(suite)
6
- @suite = suite
7
- end
8
-
9
- def post(request, response)
10
- if suite.id == 'user'
11
- STDOUT.puts request['text']
12
- else
13
- Runners::FirefoxRunner.resume(suite.id, request['text'])
14
- end
15
- response.headers['Content-Length'] = "0"
16
- end
17
- end
18
- end
19
- end
@@ -1,2 +0,0 @@
1
- dir = File.dirname(__FILE__)
2
- require "#{dir}/selenium/selenium_driver"
@@ -1,5 +0,0 @@
1
- module Selenium
2
- class SeleniumDriver
3
- attr_reader :session_id
4
- end
5
- end
@@ -1,3 +0,0 @@
1
- dir = File.dirname(__FILE__)
2
- require "#{dir}/thin/js_test_core_connection"
3
- require "#{dir}/thin/backends/js_test_core_server"
@@ -1,9 +0,0 @@
1
- module Thin
2
- module Backends
3
- class JsTestCoreServer < TcpServer
4
- def connect
5
- @signature = EventMachine.start_server(@host, @port, JsTestCoreConnection, &method(:initialize_connection))
6
- end
7
- end
8
- end
9
- end
@@ -1,42 +0,0 @@
1
- module Thin
2
- class JsTestCoreConnection < Connection
3
- def process
4
- # Add client info to the request env
5
- @request.remote_address = remote_address
6
-
7
- env = @request.env
8
- env['js_test_core.connection'] = self
9
- @response.status, @response.headers, @response.body = @app.call(env)
10
- send_data @response.head
11
- if !@response.body.empty? || @response.headers.to_s.include?("Content-Length: 0")
12
- send_body @response.body
13
- end
14
- rescue Exception => e
15
- handle_error e
16
- end
17
-
18
- def send_body(rack_response)
19
- rack_response.each do |chunk|
20
- send_data chunk
21
- end
22
- # If no more request on that same connection, we close it.
23
- close_connection_after_writing unless persistent?
24
- rescue Exception => e
25
- handle_error e
26
- ensure
27
- @request.close rescue nil
28
- @response.close rescue nil
29
-
30
- # Prepare the connection for another request if the client
31
- # supports HTTP pipelining (persistent connection).
32
- post_init if persistent?
33
- end
34
-
35
- def handle_error(error)
36
- log "!! Unexpected error while processing request: #{error.message}"
37
- log error.backtrace
38
- log_error
39
- close_connection rescue nil
40
- end
41
- end
42
- end
@@ -1,5 +0,0 @@
1
- describe("A failing spec", {
2
- 'fails': function() {
3
- value_of(true).should_be(false);
4
- }
5
- })
@@ -1,6 +0,0 @@
1
- require("/implementations/foo");
2
- describe("A failing spec in foo", {
3
- 'fails': function() {
4
- value_of(Foo.value).should_be(false);
5
- }
6
- })
@@ -1,6 +0,0 @@
1
- require("/implementations/foo");
2
- describe("A passing spec", {
3
- 'passes': function() {
4
- value_of(Foo.value).should_be(true);
5
- }
6
- })
@@ -1,45 +0,0 @@
1
- require File.expand_path("#{File.dirname(__FILE__)}/../unit_spec_helper")
2
-
3
- module JsTestCore
4
- describe RailsServer do
5
- it "subclasses Server" do
6
- RailsServer.superclass.should == Server
7
- end
8
-
9
- describe ".run" do
10
- attr_reader :rails_root
11
- before do
12
- @rails_root = "/rails/root"
13
- Server.instance = nil
14
- end
15
-
16
- it "initializes the RailsServer and runs the Thin Handler and sets Server.instance to the RailsServer instance" do
17
- host = DEFAULT_HOST
18
- port = DEFAULT_PORT
19
- server_instance = nil
20
- mock.proxy(RailsServer).new(
21
- rails_root,
22
- host,
23
- port
24
- ) do |new_instance|
25
- server_instance = new_instance
26
- end
27
-
28
- mock(EventMachine).run.yields
29
- mock(EventMachine).start_server(host, port, ::Thin::JsTestCoreConnection)
30
- RailsServer.run(rails_root)
31
- Server.instance.should == server_instance
32
- end
33
- end
34
-
35
- describe "#initialize" do
36
- it "sets the server paths based on the passed in rails root" do
37
- rails_root = "/rails/root"
38
- server = RailsServer.new(rails_root)
39
- server.spec_root_path.should == "#{rails_root}/spec/javascripts"
40
- server.implementation_root_path.should == "#{rails_root}/public/javascripts"
41
- server.public_path.should == "#{rails_root}/public"
42
- end
43
- end
44
- end
45
- end
@@ -1,42 +0,0 @@
1
- require File.expand_path("#{File.dirname(__FILE__)}/../../unit_spec_helper")
2
-
3
- module JsTestCore
4
- module Resources
5
- describe Dir do
6
- attr_reader :dir, :absolute_path, :relative_path
7
-
8
- describe "#locate" do
9
- before do
10
- @absolute_path = core_path
11
- @relative_path = "/core"
12
- @dir = Resources::Dir.new(absolute_path, relative_path)
13
- end
14
-
15
- describe "when passed a name of a real file" do
16
- it "returns a Resources::File representing it" do
17
- file = dir.locate("JsTestCore.css")
18
- file.relative_path.should == "/core/JsTestCore.css"
19
- file.absolute_path.should == "#{core_path}/JsTestCore.css"
20
- end
21
- end
22
- end
23
-
24
- describe "#glob" do
25
- before do
26
- @absolute_path = spec_root_path
27
- @relative_path = "/specs"
28
- @dir = Resources::Dir.new(absolute_path, relative_path)
29
- end
30
-
31
- it "returns an array of matching Files under this directory with the correct relative paths" do
32
- globbed_files = dir.glob("/**/*_spec.js")
33
-
34
- globbed_files.size.should == 3
35
- globbed_files.should contain_spec_file_with_correct_paths("/failing_spec.js")
36
- globbed_files.should contain_spec_file_with_correct_paths("/foo/failing_spec.js")
37
- globbed_files.should contain_spec_file_with_correct_paths("/foo/passing_spec.js")
38
- end
39
- end
40
- end
41
- end
42
- end
@@ -1,26 +0,0 @@
1
- require File.expand_path("#{File.dirname(__FILE__)}/../../unit_spec_helper")
2
-
3
- module JsTestCore
4
- module Resources
5
- describe FileNotFound do
6
- attr_reader :request, :response, :file_not_found
7
-
8
- before do
9
- WebRoot.dispatch_specs
10
- stub(EventMachine).send_data
11
- stub(EventMachine).close_connection
12
- @request = create_request('get', '/invalid')
13
- @response = Rack::Response.new
14
- @file_not_found = FileNotFound.new('invalid')
15
- end
16
-
17
- describe "#get" do
18
- it "returns a 404 response code with an error message" do
19
- file_not_found.get(request, response)
20
- response.status.should == 404
21
- response.body.should include("Path invalid not found. You may want to try the /specs directory.")
22
- end
23
- end
24
- end
25
- end
26
- end
@@ -1,24 +0,0 @@
1
- require File.expand_path("#{File.dirname(__FILE__)}/../../unit_spec_helper")
2
-
3
- module JsTestCore
4
- module Resources
5
- describe Runners do
6
- attr_reader :runner
7
- before do
8
- @runner = Runners.new
9
- end
10
-
11
- describe "#locate" do
12
- it "when passed 'firefox', returns a Firefox1Runner" do
13
- runner.locate('firefox').is_a?(Runners::FirefoxRunner).should be_true
14
- end
15
-
16
- it "when not passed 'firefox', raises an error" do
17
- lambda do
18
- runner.locate('invalid')
19
- end.should raise_error
20
- end
21
- end
22
- end
23
- end
24
- end
@@ -1,197 +0,0 @@
1
- require File.expand_path("#{File.dirname(__FILE__)}/../../../unit_spec_helper")
2
-
3
- module JsTestCore
4
- module Resources
5
- describe Runners::FirefoxRunner do
6
- attr_reader :runner, :request, :response, :driver, :suite_id
7
-
8
- before do
9
- Thread.current[:connection] = connection
10
- @driver = "Selenium Driver"
11
- @suite_id = 12345
12
- stub(Selenium::SeleniumDriver).new('localhost', 4444, '*firefox', 'http://0.0.0.0:8080') do
13
- driver
14
- end
15
- end
16
-
17
- describe ".resume" do
18
- describe "when there is a runner for the passed in suite_id" do
19
- before do
20
- @request = Rack::Request.new( Rack::MockRequest.env_for('/runners/firefox') )
21
- @response = Rack::Response.new
22
- @runner = Runners::FirefoxRunner.new
23
- stub(Thread).start.yields
24
-
25
- stub(driver).start
26
- stub(driver).open
27
- stub(driver).session_id {suite_id}
28
- stub(driver).stop
29
- stub(EventMachine).send_data
30
- stub(EventMachine).close_connection
31
-
32
- runner.post(request, response)
33
- runner.suite_id.should == suite_id
34
- end
35
-
36
- it "removes and finalizes the instance that has the suite_id" do
37
- mock.proxy(runner).finalize("Browser output")
38
- Runners::FirefoxRunner.send(:instances)[suite_id].should == runner
39
- Runners::FirefoxRunner.resume(suite_id, "Browser output")
40
- Runners::FirefoxRunner.send(:instances)[suite_id].should be_nil
41
- end
42
- end
43
-
44
- describe "when there is not a runner for the passed in suite_id" do
45
- it "does nothing" do
46
- lambda do
47
- Runners::FirefoxRunner.resume("invalid", "nothing happens")
48
- end.should_not raise_error
49
- end
50
- end
51
- end
52
-
53
- describe "#post" do
54
- attr_reader :firefox_profile_path
55
- before do
56
- @request = Rack::Request.new( Rack::MockRequest.env_for('/runners/firefox') )
57
- @response = Rack::Response.new
58
- @runner = Runners::FirefoxRunner.new
59
- stub(Thread).start.yields
60
- end
61
-
62
- it "keeps the connection open" do
63
- stub(driver).start
64
- stub(driver).open
65
- stub(driver).session_id {suite_id}
66
- dont_allow(EventMachine).send_data
67
- dont_allow(EventMachine).close_connection
68
- runner.post(request, response)
69
-
70
- response.body.should be_empty
71
- end
72
-
73
- describe "when a selenium_host parameter is passed into the request" do
74
- before do
75
- request['selenium_host'] = "another-machine"
76
- stub(driver).start
77
- stub(driver).open
78
- stub(driver).session_id {suite_id}
79
- end
80
-
81
- it "starts the Selenium Driver with the passed in selenium_host" do
82
- mock(Selenium::SeleniumDriver).new('another-machine', 4444, '*firefox', 'http://0.0.0.0:8080') do
83
- driver
84
- end
85
- runner.post(request, response)
86
- end
87
- end
88
-
89
- describe "when a selenium_host parameter is not passed into the request" do
90
- before do
91
- request['selenium_host'].should be_nil
92
- stub(driver).start
93
- stub(driver).open
94
- stub(driver).session_id {suite_id}
95
- end
96
-
97
- it "starts the Selenium Driver from localhost" do
98
- mock(Selenium::SeleniumDriver).new('localhost', 4444, '*firefox', 'http://0.0.0.0:8080') do
99
- driver
100
- end
101
- runner.post(request, response)
102
- end
103
- end
104
-
105
- describe "when a selenium_port parameter is passed into the request" do
106
- before do
107
- request['selenium_port'] = "4000"
108
- stub(driver).start
109
- stub(driver).open
110
- stub(driver).session_id {suite_id}
111
- end
112
-
113
- it "starts the Selenium Driver with the passed in selenium_port" do
114
- mock(Selenium::SeleniumDriver).new('localhost', 4000, '*firefox', 'http://0.0.0.0:8080') do
115
- driver
116
- end
117
- runner.post(request, response)
118
- end
119
- end
120
-
121
- describe "when a selenium_port parameter is not passed into the request" do
122
- before do
123
- request['selenium_port'].should be_nil
124
- stub(driver).start
125
- stub(driver).open
126
- stub(driver).session_id {suite_id}
127
- end
128
-
129
- it "starts the Selenium Driver from localhost" do
130
- mock(Selenium::SeleniumDriver).new('localhost', 4444, '*firefox', 'http://0.0.0.0:8080') do
131
- driver
132
- end
133
- runner.post(request, response)
134
- end
135
- end
136
-
137
- describe "when a spec_url is passed into the request" do
138
- before do
139
- request['spec_url'] = "http://another-host:8080/specs/subdir"
140
- end
141
-
142
- it "runs Selenium with the passed in host and part to run the specified spec suite in Firefox" do
143
- mock(Selenium::SeleniumDriver).new('localhost', 4444, '*firefox', 'http://another-host:8080') do
144
- driver
145
- end
146
- mock(driver).start
147
- mock(driver).open("http://another-host:8080/specs/subdir")
148
- mock(driver).session_id {suite_id}
149
-
150
- runner.post(request, response)
151
- end
152
- end
153
-
154
- describe "when a spec_url is not passed into the request" do
155
- before do
156
- request['spec_url'].should be_nil
157
- mock(Selenium::SeleniumDriver).new('localhost', 4444, '*firefox', 'http://0.0.0.0:8080') do
158
- driver
159
- end
160
- end
161
-
162
- it "uses Selenium to run the entire spec suite in Firefox" do
163
- mock(driver).start
164
- mock(driver).open("http://0.0.0.0:8080/specs")
165
- mock(driver).session_id {suite_id}
166
-
167
- runner.post(request, response)
168
- end
169
- end
170
- end
171
-
172
- describe "#finalize" do
173
- before do
174
- @request = Rack::Request.new( Rack::MockRequest.env_for('/runners/firefox') )
175
- @response = Rack::Response.new
176
- @runner = Runners::FirefoxRunner.new
177
- stub(driver).start
178
- stub(driver).open
179
- stub(driver).session_id {suite_id}
180
- runner.post(request, response)
181
- end
182
-
183
- it "kills the browser, sends the response body, and close the connection" do
184
- mock(driver).stop
185
- data = ""
186
- stub(EventMachine).send_data do |signature, data, data_length|
187
- data << data
188
- end
189
- mock(connection).close_connection_after_writing
190
-
191
- runner.finalize("The text")
192
- data.should include("The text")
193
- end
194
- end
195
- end
196
- end
197
- end