js_test_core 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. data/CHANGES +11 -0
  2. data/Rakefile +1 -1
  3. data/lib/js_test_core.rb +10 -2
  4. data/lib/js_test_core/client.rb +85 -18
  5. data/lib/js_test_core/extensions.rb +3 -0
  6. data/lib/js_test_core/extensions/time.rb +6 -0
  7. data/lib/js_test_core/resources.rb +4 -4
  8. data/lib/js_test_core/resources/dir.rb +22 -7
  9. data/lib/js_test_core/resources/file.rb +24 -16
  10. data/lib/js_test_core/resources/file_not_found.rb +11 -0
  11. data/lib/js_test_core/resources/runner.rb +107 -0
  12. data/lib/js_test_core/resources/session.rb +44 -0
  13. data/lib/js_test_core/resources/session_finish.rb +17 -0
  14. data/lib/js_test_core/resources/specs/spec_dir.rb +10 -14
  15. data/lib/js_test_core/resources/specs/spec_file.rb +1 -1
  16. data/lib/js_test_core/resources/web_root.rb +51 -39
  17. data/lib/js_test_core/selenium_server_configuration.rb +48 -0
  18. data/lib/js_test_core/server.rb +3 -64
  19. data/lib/js_test_core/thin/js_test_core_connection.rb +4 -38
  20. data/spec/unit/js_test_core/client_spec.rb +167 -0
  21. data/spec/unit/{js_spec → js_test_core}/rails_server_spec.rb +0 -0
  22. data/spec/unit/js_test_core/resources/dir_spec.rb +52 -0
  23. data/spec/unit/js_test_core/resources/file_not_found_spec.rb +16 -0
  24. data/spec/unit/js_test_core/resources/file_spec.rb +90 -0
  25. data/spec/unit/js_test_core/resources/runners/runner_spec.rb +303 -0
  26. data/spec/unit/js_test_core/resources/session_finish_spec.rb +79 -0
  27. data/spec/unit/js_test_core/resources/session_spec.rb +82 -0
  28. data/spec/unit/js_test_core/resources/specs/spec_dir_spec.rb +105 -0
  29. data/spec/unit/{js_spec → js_test_core}/resources/specs/spec_file_spec.rb +5 -5
  30. data/spec/unit/js_test_core/resources/web_root_spec.rb +32 -0
  31. data/spec/unit/js_test_core/selenium_server_configuration_spec.rb +49 -0
  32. data/spec/unit/{js_spec → js_test_core}/server_spec.rb +18 -32
  33. data/spec/unit/thin/js_test_core_connection_spec.rb +0 -86
  34. data/spec/unit/unit_spec_helper.rb +58 -22
  35. metadata +39 -33
  36. data/lib/js_test_core/resources/runners.rb +0 -15
  37. data/lib/js_test_core/resources/runners/firefox_runner.rb +0 -73
  38. data/lib/js_test_core/resources/suite.rb +0 -24
  39. data/lib/js_test_core/resources/suite_finish.rb +0 -19
  40. data/spec/unit/js_spec/client_spec.rb +0 -137
  41. data/spec/unit/js_spec/resources/dir_spec.rb +0 -42
  42. data/spec/unit/js_spec/resources/file_spec.rb +0 -88
  43. data/spec/unit/js_spec/resources/runner_spec.rb +0 -24
  44. data/spec/unit/js_spec/resources/runners/firefox_runner_spec.rb +0 -161
  45. data/spec/unit/js_spec/resources/specs/spec_dir_spec.rb +0 -79
  46. data/spec/unit/js_spec/resources/suite_finish_spec.rb +0 -94
  47. data/spec/unit/js_spec/resources/suite_spec.rb +0 -44
  48. data/spec/unit/js_spec/resources/web_root_spec.rb +0 -67
@@ -2,91 +2,5 @@ require File.expand_path("#{File.dirname(__FILE__)}/../unit_spec_helper")
2
2
 
3
3
  module Thin
4
4
  describe JsTestCoreConnection do
5
- describe "#process" do
6
- attr_reader :connection, :result
7
- before do
8
- @connection = JsTestCoreConnection.new('signature')
9
- stub(connection).socket_address {'0.0.0.0'}
10
-
11
- @result = ""
12
- stub(EventMachine).send_data do |signature, data, data_length|
13
- result << data
14
- end
15
- end
16
-
17
- describe "and the call is successful" do
18
- describe "and the body is not empty" do
19
- before do
20
- mock(app = Object.new).call(is_a(Hash)) do
21
- [200, {}, 'The Body']
22
- end
23
- connection.app = app
24
- end
25
-
26
- it "sends the response to the socket and closes the connection" do
27
- mock(connection).close_connection_after_writing
28
- connection.receive_data "GET /specs HTTP/1.1\r\nHost: _\r\n\r\n"
29
- result.should include("The Body")
30
- end
31
- end
32
-
33
- describe "and the body is empty" do
34
- describe "and the Content-Length header is 0" do
35
- before do
36
- mock(app = Object.new).call(is_a(Hash)) do
37
- [200, {"Content-Length" => '0'}, []]
38
- end
39
- connection.app = app
40
- end
41
-
42
- it "sends the response to the socket and closes the connection" do
43
- mock(connection).close_connection_after_writing
44
- connection.receive_data "GET /specs HTTP/1.1\r\nHost: _\r\n\r\n"
45
- end
46
- end
47
-
48
- describe "and the Content-Length header is > 0" do
49
- before do
50
- mock(app = Object.new).call(is_a(Hash)) do
51
- [200, {"Content-Length" => '55'}, []]
52
- end
53
- connection.app = app
54
- end
55
-
56
- it "keeps the connection open" do
57
- dont_allow(connection).close_connection_after_writing
58
- connection.receive_data "GET /specs HTTP/1.1\r\nHost: _\r\n\r\n"
59
- end
60
- end
61
-
62
- describe "and the Content-Length header is not passed in" do
63
- before do
64
- mock(app = Object.new).call(is_a(Hash)) do
65
- [200, {}, []]
66
- end
67
- connection.app = app
68
- end
69
-
70
- it "keeps the connection open" do
71
- dont_allow(connection).close_connection_after_writing
72
- connection.receive_data "GET /specs HTTP/1.1\r\nHost: _\r\n\r\n"
73
- end
74
- end
75
- end
76
- end
77
-
78
- describe "and the call raises an error" do
79
- it "logs the error and closes the connection" do
80
- mock(app = Object.new).call(is_a(Hash)) do
81
- raise "An Error"
82
- end
83
- connection.app = app
84
- mock(connection).log(anything).at_least(1)
85
- mock(connection).close_connection
86
-
87
- connection.receive_data "GET /specs HTTP/1.1\r\nHost: _\r\n\r\n"
88
- end
89
- end
90
- end
91
5
  end
92
6
  end
@@ -2,7 +2,7 @@ require "rubygems"
2
2
  require "spec"
3
3
 
4
4
  dir = File.dirname(__FILE__)
5
- $LOAD_PATH.unshift "#{dir}/../../lib"
5
+ $LOAD_PATH.unshift File.expand_path("#{dir}/../../lib")
6
6
  require "js_test_core"
7
7
  require "hpricot"
8
8
  require "guid"
@@ -22,7 +22,13 @@ module Spec
22
22
  end
23
23
  end
24
24
 
25
- class Spec::Example::ExampleGroup
25
+ class JsTestCoreTestDir < JsTestCore::Resources::Dir
26
+ def get
27
+
28
+ end
29
+ end
30
+
31
+ class Spec::ExampleGroup
26
32
  class << self
27
33
  def thin_logging
28
34
  @thin_logging = true if @thin_logging.nil?
@@ -31,15 +37,7 @@ class Spec::Example::ExampleGroup
31
37
 
32
38
  attr_writer :thin_logging
33
39
  end
34
- end
35
-
36
- class JsTestCoreTestDir < JsTestCore::Resources::Dir
37
- def get(request, response)
38
-
39
- end
40
- end
41
-
42
- module Spec::Example::ExampleMethods
40
+
43
41
  attr_reader :core_path, :spec_root_path, :implementation_root_path, :public_path, :server, :connection
44
42
  before(:all) do
45
43
  dir = File.dirname(__FILE__)
@@ -48,6 +46,7 @@ module Spec::Example::ExampleMethods
48
46
  @spec_root_path = File.expand_path("#{dir}/../example_specs")
49
47
  @implementation_root_path = File.expand_path("#{dir}/../example_public/javascripts")
50
48
  @public_path = File.expand_path("#{dir}/../example_public")
49
+ stub(Thread).start.yields
51
50
  end
52
51
 
53
52
  before(:each) do
@@ -61,7 +60,7 @@ module Spec::Example::ExampleMethods
61
60
  stub(EventMachine).send_data do
62
61
  raise "Calls to EventMachine.send_data must be mocked or stubbed"
63
62
  end
64
- @connection = Thin::JsTestCoreConnection.new(Guid.new)
63
+ @connection = create_connection
65
64
  stub(EventMachine).send_data {raise "EventMachine.send_data must be handled"}
66
65
  stub(EventMachine).close_connection {raise "EventMachine.close_connection must be handled"}
67
66
  @server = JsTestCore::Server.instance
@@ -75,6 +74,10 @@ module Spec::Example::ExampleMethods
75
74
  Thin::Logging.debug = false
76
75
  end
77
76
 
77
+ def create_connection(guid=Guid.new)
78
+ Thin::JsTestCoreConnection.new(Guid.new)
79
+ end
80
+
78
81
  def get(url, params={})
79
82
  request(:get, url, params)
80
83
  end
@@ -95,20 +98,18 @@ module Spec::Example::ExampleMethods
95
98
  Rack::MockRequest.env_for(url, params.merge({:method => method.to_s.upcase, 'js_test_core.connection' => connection}))
96
99
  end
97
100
 
98
- def create_request(method, url, params={})
99
- env = env_for(method, url, params)
100
- server.call(env)[2]
101
+ def create_request(method, path, params={})
102
+ body = params.map do |key, value|
103
+ "#{URI.escape(key)}=#{URI.escape(value)}"
104
+ end.join("&")
105
+ connection.receive_data "#{method.to_s.upcase} #{path} HTTP/1.1\r\nHost: _\r\nContent-Length: #{body.length}\r\n\r\n#{body}"
106
+ connection.response
101
107
  end
102
108
  alias_method :request, :create_request
103
109
 
104
- def spec_file(relative_path)
105
- absolute_path = spec_root_path + relative_path
106
- JsTestCore::Resources::File.new(absolute_path, "/specs#{relative_path}")
107
- end
108
-
109
110
  def spec_dir(relative_path="")
110
111
  absolute_path = spec_root_path + relative_path
111
- JsTestCore::Resources::Specs::SpecDir.new(absolute_path, "/specs#{relative_path}")
112
+ JsTestCore::Resources::Specs::SpecDir.new(:connection => connection, :absolute_path => absolute_path, :relative_path => "/specs#{relative_path}")
112
113
  end
113
114
 
114
115
  def contain_spec_file_with_correct_paths(path_relative_to_spec_root)
@@ -119,7 +120,42 @@ module Spec::Example::ExampleMethods
119
120
  file = globbed_files.find do |file|
120
121
  file.absolute_path == expected_absolute_path
121
122
  end
122
- file && file.relative_path == expected_relative_path
123
+ raise "Did not find file with absolute path of #{expected_absolute_path.inspect}" unless file
124
+ file.relative_path == expected_relative_path
123
125
  end
124
126
  end
127
+
128
+ def stub_send_data
129
+ stub(EventMachine).send_data do |signature, data, data_length|
130
+ data_length
131
+ end
132
+ end
133
+ end
134
+
135
+ class FakeSeleniumDriver
136
+ SESSION_ID = "DEADBEEF"
137
+ attr_reader :session_id
138
+
139
+ def initialize
140
+ @session_id = nil
141
+ end
142
+
143
+ def start
144
+ @session_id = SESSION_ID
145
+ end
146
+
147
+ def stop
148
+ @session_id = nil
149
+ end
150
+
151
+ def open(url)
152
+ end
153
+
154
+ def create_cookie(key_value, options="")
155
+
156
+ end
157
+
158
+ def session_started?
159
+ !!@session_id
160
+ end
125
161
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: js_test_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Takita
@@ -9,11 +9,12 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-05-07 00:00:00 -07:00
12
+ date: 2009-01-27 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: Selenium
17
+ type: :runtime
17
18
  version_requirement:
18
19
  version_requirements: !ruby/object:Gem::Requirement
19
20
  requirements:
@@ -23,6 +24,7 @@ dependencies:
23
24
  version:
24
25
  - !ruby/object:Gem::Dependency
25
26
  name: thin
27
+ type: :runtime
26
28
  version_requirement:
27
29
  version_requirements: !ruby/object:Gem::Requirement
28
30
  requirements:
@@ -40,45 +42,49 @@ extra_rdoc_files:
40
42
  - README
41
43
  - CHANGES
42
44
  files:
45
+ - README
43
46
  - Rakefile
44
47
  - CHANGES
45
- - README
46
- - lib/js_test_core/rack.rb
47
- - lib/js_test_core/thin/backends/js_test_core_server.rb
48
- - lib/js_test_core/thin/js_test_core_connection.rb
48
+ - lib/js_test_core.rb
49
49
  - lib/js_test_core/rack/commonlogger.rb
50
- - lib/js_test_core/selenium/selenium_driver.rb
50
+ - lib/js_test_core/server.rb
51
+ - lib/js_test_core/client.rb
52
+ - lib/js_test_core/resources.rb
53
+ - lib/js_test_core/rails_server.rb
54
+ - lib/js_test_core/thin.rb
55
+ - lib/js_test_core/extensions/time.rb
56
+ - lib/js_test_core/rack.rb
51
57
  - lib/js_test_core/selenium.rb
58
+ - lib/js_test_core/thin/js_test_core_connection.rb
59
+ - lib/js_test_core/thin/backends/js_test_core_server.rb
60
+ - lib/js_test_core/resources/file.rb
61
+ - lib/js_test_core/resources/session_finish.rb
62
+ - lib/js_test_core/resources/runner.rb
63
+ - lib/js_test_core/resources/file_not_found.rb
64
+ - lib/js_test_core/resources/session.rb
52
65
  - lib/js_test_core/resources/dir.rb
53
- - lib/js_test_core/resources/runners/firefox_runner.rb
54
- - lib/js_test_core/resources/suite_finish.rb
55
66
  - lib/js_test_core/resources/web_root.rb
56
- - lib/js_test_core/resources/file.rb
57
- - lib/js_test_core/resources/suite.rb
58
- - lib/js_test_core/resources/runners.rb
59
- - lib/js_test_core/resources/specs/spec_file.rb
60
67
  - lib/js_test_core/resources/specs/spec_dir.rb
61
- - lib/js_test_core/rails_server.rb
62
- - lib/js_test_core/resources.rb
63
- - lib/js_test_core/thin.rb
64
- - lib/js_test_core/server.rb
65
- - lib/js_test_core/client.rb
66
- - lib/js_test_core.rb
68
+ - lib/js_test_core/resources/specs/spec_file.rb
69
+ - lib/js_test_core/extensions.rb
70
+ - lib/js_test_core/selenium/selenium_driver.rb
71
+ - lib/js_test_core/selenium_server_configuration.rb
67
72
  - spec/spec_suite.rb
68
- - spec/unit/thin/js_test_core_connection_spec.rb
69
- - spec/unit/js_spec/resources/file_spec.rb
70
- - spec/unit/js_spec/resources/suite_spec.rb
71
- - spec/unit/js_spec/resources/dir_spec.rb
72
- - spec/unit/js_spec/resources/suite_finish_spec.rb
73
- - spec/unit/js_spec/resources/web_root_spec.rb
74
- - spec/unit/js_spec/resources/runners/firefox_runner_spec.rb
75
- - spec/unit/js_spec/resources/runner_spec.rb
76
- - spec/unit/js_spec/resources/specs/spec_dir_spec.rb
77
- - spec/unit/js_spec/resources/specs/spec_file_spec.rb
78
- - spec/unit/js_spec/server_spec.rb
79
- - spec/unit/js_spec/client_spec.rb
80
- - spec/unit/js_spec/rails_server_spec.rb
81
73
  - spec/unit/unit_spec_helper.rb
74
+ - spec/unit/thin/js_test_core_connection_spec.rb
75
+ - spec/unit/js_test_core/selenium_server_configuration_spec.rb
76
+ - spec/unit/js_test_core/resources/web_root_spec.rb
77
+ - spec/unit/js_test_core/resources/runners/runner_spec.rb
78
+ - spec/unit/js_test_core/resources/session_spec.rb
79
+ - spec/unit/js_test_core/resources/file_not_found_spec.rb
80
+ - spec/unit/js_test_core/resources/file_spec.rb
81
+ - spec/unit/js_test_core/resources/dir_spec.rb
82
+ - spec/unit/js_test_core/resources/session_finish_spec.rb
83
+ - spec/unit/js_test_core/resources/specs/spec_file_spec.rb
84
+ - spec/unit/js_test_core/resources/specs/spec_dir_spec.rb
85
+ - spec/unit/js_test_core/server_spec.rb
86
+ - spec/unit/js_test_core/rails_server_spec.rb
87
+ - spec/unit/js_test_core/client_spec.rb
82
88
  - spec/unit_suite.rb
83
89
  has_rdoc: true
84
90
  homepage: http://pivotallabs.com
@@ -105,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
105
111
  requirements: []
106
112
 
107
113
  rubyforge_project: pivotalrb
108
- rubygems_version: 1.1.0
114
+ rubygems_version: 1.3.1
109
115
  signing_key:
110
116
  specification_version: 2
111
117
  summary: The JsTestCore library is the core javascript test server library used by several JS Test server libraries.
@@ -1,15 +0,0 @@
1
- dir = File.dirname(__FILE__)
2
-
3
- module JsTestCore
4
- module Resources
5
- class Runners
6
- def locate(name)
7
- if name == 'firefox'
8
- FirefoxRunner.new
9
- else
10
- raise "Invalid path #{name}"
11
- end
12
- end
13
- end
14
- end
15
- end
@@ -1,73 +0,0 @@
1
- module JsTestCore
2
- module Resources
3
- class Runners
4
- class FirefoxRunner
5
- class << self
6
- def resume(suite_id, text)
7
- runner = instances.delete(suite_id)
8
- runner.finalize(text)
9
- end
10
-
11
- def register_instance(runner)
12
- instances[runner.suite_id] = runner
13
- end
14
-
15
- protected
16
- def instances
17
- @instances ||= {}
18
- end
19
- end
20
-
21
- include FileUtils
22
- attr_reader :profile_dir, :connection, :driver, :response
23
-
24
- def initialize
25
- profile_base = "#{::Dir.tmpdir}/js_test_core/firefox"
26
- mkdir_p profile_base
27
- @profile_dir = "#{profile_base}/#{Time.now.to_i}"
28
- @connection = Server.connection
29
- end
30
-
31
- def post(request, response)
32
- @response = response
33
-
34
- spec_url = (request && request['spec_url']) ? request['spec_url'] : spec_suite_url
35
- parsed_spec_url = URI.parse(spec_url)
36
- selenium_port = (request['selenium_port'] || 4444).to_i
37
- @driver = Selenium::SeleniumDriver.new(
38
- request['selenium_host'] || 'localhost',
39
- selenium_port,
40
- '*firefox',
41
- "#{parsed_spec_url.scheme}://#{parsed_spec_url.host}:#{parsed_spec_url.port}"
42
- )
43
- begin
44
- driver.start
45
- rescue Errno::ECONNREFUSED => e
46
- raise Errno::ECONNREFUSED, "Cannot connect to Selenium Server on port #{selenium_port}. To start the selenium server, run `selenium`."
47
- end
48
- Thread.start do
49
- driver.open(spec_url)
50
- end
51
- response.status = 200
52
- FirefoxRunner.register_instance self
53
- end
54
-
55
- def finalize(text)
56
- driver.stop
57
- response.body = text
58
- connection.send_body(response)
59
- end
60
-
61
- def suite_id
62
- driver.session_id
63
- end
64
-
65
- protected
66
-
67
- def spec_suite_url
68
- "#{Server.root_url}/specs"
69
- end
70
- end
71
- end
72
- end
73
- 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