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
@@ -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,137 +0,0 @@
1
- require File.expand_path("#{File.dirname(__FILE__)}/../unit_spec_helper")
2
-
3
- module JsTestCore
4
- describe Client do
5
- describe '.run' do
6
- describe 'when successful' do
7
- before do
8
- request = Object.new
9
- mock(request).post("/runners/firefox", "selenium_host=localhost&selenium_port=4444")
10
- response = Object.new
11
- mock(response).body {""}
12
- mock(Net::HTTP).start(DEFAULT_HOST, DEFAULT_PORT).yields(request) {response}
13
- stub(Client).puts
14
- end
15
-
16
- it "returns true" do
17
- Client.run.should be_true
18
- end
19
-
20
- it "prints 'SUCCESS'" do
21
- mock(Client).puts("SUCCESS")
22
- Client.run
23
- end
24
- end
25
-
26
- describe 'when unsuccessful' do
27
- before do
28
- request = Object.new
29
- mock(request).post("/runners/firefox", "selenium_host=localhost&selenium_port=4444")
30
- response = Object.new
31
- mock(response).body {"the failure message"}
32
- mock(Net::HTTP).start(DEFAULT_HOST, DEFAULT_PORT).yields(request) {response}
33
- stub(Client).puts
34
- end
35
-
36
- it "returns false" do
37
- Client.run.should be_false
38
- end
39
-
40
- it "prints 'FAILURE' and the error message(s)" do
41
- mock(Client).puts("FAILURE")
42
- mock(Client).puts("the failure message")
43
- Client.run
44
- end
45
- end
46
-
47
- describe "arguments" do
48
- attr_reader :request, :response
49
- before do
50
- @request = Object.new
51
- @response = Object.new
52
- mock(response).body {""}
53
- mock(Net::HTTP).start(DEFAULT_HOST, DEFAULT_PORT).yields(request) {response}
54
- stub(Client).puts
55
- end
56
-
57
- describe "when passed a custom spec_url" do
58
- it "passes the spec_url as a post parameter" do
59
- spec_url = 'http://foobar.com/foo'
60
- mock(request).post(
61
- "/runners/firefox",
62
- "selenium_host=localhost&selenium_port=4444&spec_url=#{CGI.escape(spec_url)}"
63
- )
64
- Client.run(:spec_url => spec_url)
65
- end
66
- end
67
-
68
- describe "when passed a custom selenium host" do
69
- it "passes the selenium_host as a post parameter" do
70
- selenium_host = 'test-runner'
71
- mock(request).post(
72
- "/runners/firefox",
73
- "selenium_host=test-runner&selenium_port=4444"
74
- )
75
- Client.run(:selenium_host => selenium_host)
76
- end
77
- end
78
-
79
- describe "when passed a custom selenium port" do
80
- it "passes the selenium_port as a post parameter" do
81
- selenium_port = 5000
82
- mock(request).post(
83
- "/runners/firefox",
84
- "selenium_host=localhost&selenium_port=5000"
85
- )
86
- Client.run(:selenium_port => selenium_port)
87
- end
88
- end
89
- end
90
-
91
- end
92
-
93
- describe ".run_argv" do
94
- attr_reader :request, :response
95
- before do
96
- @request = Object.new
97
- @response = Object.new
98
- mock(response).body {""}
99
- mock(Net::HTTP).start(DEFAULT_HOST, DEFAULT_PORT).yields(request) {response}
100
- stub(Client).puts
101
- end
102
-
103
- describe "when passed a custom spec_url" do
104
- it "passes the spec_url as a post parameter" do
105
- spec_url = 'http://foobar.com/foo'
106
- mock(request).post(
107
- "/runners/firefox",
108
- "selenium_host=localhost&selenium_port=4444&spec_url=#{CGI.escape(spec_url)}"
109
- )
110
- Client.run_argv(['--spec_url', spec_url])
111
- end
112
- end
113
-
114
- describe "when passed a custom selenium host" do
115
- it "passes the selenium_host as a post parameter" do
116
- selenium_host = 'test-runner'
117
- mock(request).post(
118
- "/runners/firefox",
119
- "selenium_host=test-runner&selenium_port=4444"
120
- )
121
- Client.run_argv(['--selenium_host', selenium_host])
122
- end
123
- end
124
-
125
- describe "when passed a custom selenium port" do
126
- it "passes the selenium_port as a post parameter" do
127
- selenium_port = 5000
128
- mock(request).post(
129
- "/runners/firefox",
130
- "selenium_host=localhost&selenium_port=5000"
131
- )
132
- Client.run_argv(['--selenium_port', selenium_port.to_s])
133
- end
134
- end
135
- end
136
- end
137
- 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,88 +0,0 @@
1
- require File.expand_path("#{File.dirname(__FILE__)}/../../unit_spec_helper")
2
-
3
- module JsTestCore
4
- module Resources
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)
45
- end
46
-
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
53
- end
54
-
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
68
- end
69
- end
70
- end
71
-
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)
80
- end
81
-
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)
84
- end
85
- end
86
- end
87
- end
88
- 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,161 +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 "#post" do
18
- attr_reader :firefox_profile_path
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
- end
25
-
26
- it "keeps the connection open" do
27
- stub(driver).start
28
- stub(driver).open
29
- stub(driver).session_id {suite_id}
30
- dont_allow(EventMachine).send_data
31
- dont_allow(EventMachine).close_connection
32
- runner.post(request, response)
33
-
34
- response.body.should be_empty
35
- end
36
-
37
- describe "when a selenium_host parameter is passed into the request" do
38
- before do
39
- request['selenium_host'] = "another-machine"
40
- stub(driver).start
41
- stub(driver).open
42
- stub(driver).session_id {suite_id}
43
- end
44
-
45
- it "starts the Selenium Driver with the passed in selenium_host" do
46
- mock(Selenium::SeleniumDriver).new('another-machine', 4444, '*firefox', 'http://0.0.0.0:8080') do
47
- driver
48
- end
49
- runner.post(request, response)
50
- end
51
- end
52
-
53
- describe "when a selenium_host parameter is not passed into the request" do
54
- before do
55
- request['selenium_host'].should be_nil
56
- stub(driver).start
57
- stub(driver).open
58
- stub(driver).session_id {suite_id}
59
- end
60
-
61
- it "starts the Selenium Driver from localhost" do
62
- mock(Selenium::SeleniumDriver).new('localhost', 4444, '*firefox', 'http://0.0.0.0:8080') do
63
- driver
64
- end
65
- runner.post(request, response)
66
- end
67
- end
68
-
69
- describe "when a selenium_port parameter is passed into the request" do
70
- before do
71
- request['selenium_port'] = "4000"
72
- stub(driver).start
73
- stub(driver).open
74
- stub(driver).session_id {suite_id}
75
- end
76
-
77
- it "starts the Selenium Driver with the passed in selenium_port" do
78
- mock(Selenium::SeleniumDriver).new('localhost', 4000, '*firefox', 'http://0.0.0.0:8080') do
79
- driver
80
- end
81
- runner.post(request, response)
82
- end
83
- end
84
-
85
- describe "when a selenium_port parameter is not passed into the request" do
86
- before do
87
- request['selenium_port'].should be_nil
88
- stub(driver).start
89
- stub(driver).open
90
- stub(driver).session_id {suite_id}
91
- end
92
-
93
- it "starts the Selenium Driver from localhost" do
94
- mock(Selenium::SeleniumDriver).new('localhost', 4444, '*firefox', 'http://0.0.0.0:8080') do
95
- driver
96
- end
97
- runner.post(request, response)
98
- end
99
- end
100
-
101
- describe "when a spec_url is passed into the request" do
102
- before do
103
- request['spec_url'] = "http://another-host:8080/specs/subdir"
104
- end
105
-
106
- it "runs Selenium with the passed in host and part to run the specified spec suite in Firefox" do
107
- mock(Selenium::SeleniumDriver).new('localhost', 4444, '*firefox', 'http://another-host:8080') do
108
- driver
109
- end
110
- mock(driver).start
111
- mock(driver).open("http://another-host:8080/specs/subdir")
112
- mock(driver).session_id {suite_id}
113
-
114
- runner.post(request, response)
115
- end
116
- end
117
-
118
- describe "when a spec_url is not passed into the request" do
119
- before do
120
- request['spec_url'].should be_nil
121
- mock(Selenium::SeleniumDriver).new('localhost', 4444, '*firefox', 'http://0.0.0.0:8080') do
122
- driver
123
- end
124
- end
125
-
126
- it "uses Selenium to run the entire spec suite in Firefox" do
127
- mock(driver).start
128
- mock(driver).open("http://0.0.0.0:8080/specs")
129
- mock(driver).session_id {suite_id}
130
-
131
- runner.post(request, response)
132
- end
133
- end
134
- end
135
-
136
- describe "#finalize" do
137
- before do
138
- @request = Rack::Request.new( Rack::MockRequest.env_for('/runners/firefox') )
139
- @response = Rack::Response.new
140
- @runner = Runners::FirefoxRunner.new
141
- stub(driver).start
142
- stub(driver).open
143
- stub(driver).session_id {suite_id}
144
- runner.post(request, response)
145
- end
146
-
147
- it "kills the browser, sends the response body, and close the connection" do
148
- mock(driver).stop
149
- data = ""
150
- stub(EventMachine).send_data do |signature, data, data_length|
151
- data << data
152
- end
153
- mock(connection).close_connection_after_writing
154
-
155
- runner.finalize("The text")
156
- data.should include("The text")
157
- end
158
- end
159
- end
160
- end
161
- end